FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BitNet/gpu/stats.py at main · XsquirrelC/BitNet · GitHub
XsquirrelC
BitNet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
BitNet
/
gpu
/
stats.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
57 lines (48 loc) · 1.47 KB
Breadcrumbs
BitNet
/
gpu
/
stats.py
Copy path
File metadata and controls
executable file
·
57 lines (48 loc) · 1.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
#
# This source code is licensed under the BSD license found in the
# LICENSE file in the root directory of this source tree.
import
time
from
dataclasses
import
dataclass
from
typing
import
Optional
@
dataclass
class
PhaseStats
:
name
:
str
tokens
:
int
time
:
float
def
show
(
self
)
->
str
:
tps
=
self
.
tokens
/
self
.
time
return
(
f"[
{
self
.
name
}
] "
f"generated tokens:
{
self
.
tokens
}
"
f" - total time:
{
self
.
time
:.3f
}
s"
f" -
{
tps
:.1f
}
tokens per second"
)
class
Stats
:
"""
Generation stats, split by phases.
"""
def
__init__
(
self
):
self
.
phases
=
[]
self
.
current
=
None
def
end_phase
(
self
,
tokens
:
int
,
now
:
Optional
[
float
]
=
None
):
"""Terminate the current phase."""
if
self
.
current
is
None
:
return
if
now
is
None
:
now
=
time
.
time
()
cname
,
ctokens
,
ctime
=
self
.
current
stats
=
PhaseStats
(
name
=
cname
,
tokens
=
tokens
-
ctokens
,
time
=
now
-
ctime
,
)
self
.
phases
.
append
(
stats
)
def
phase
(
self
,
name
:
str
,
tokens
:
int
=
0
):
"""
Start a new phase, and terminate the current one,
if one is ongoing.
"""
now
=
time
.
time
()
self
.
end_phase
(
tokens
,
now
)
self
.
current
=
(
name
,
tokens
,
now
)
Back
|
FazBrowse Home
|
New Git URL