Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
1712da28
Unverified
Commit
1712da28
authored
Feb 13, 2023
by
Shawn-Kong
Committed by
GitHub
Feb 14, 2023
Browse files
[NFC] polish colossalai/gemini/gemini_context.py code style (#2690)
parent
40c916b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
48 deletions
+48
-48
colossalai/gemini/gemini_context.py
colossalai/gemini/gemini_context.py
+48
-48
No files found.
colossalai/gemini/gemini_context.py
View file @
1712da28
from
enum
import
EnumMeta
from
enum
import
EnumMeta
class
GeminiMemoryManager
(
object
):
class
GeminiMemoryManager
(
object
):
def
__init__
(
self
,
states_cls
:
EnumMeta
):
def
__init__
(
self
,
states_cls
:
EnumMeta
):
super
().
__init__
()
super
().
__init__
()
self
.
states_cls
=
states_cls
self
.
states_cls
=
states_cls
self
.
_cnter
=
0
# the counter of instances
self
.
_cnter
=
0
# the counter of instances
self
.
total_mem
=
dict
()
self
.
total_mem
=
dict
()
self
.
state_mem
=
dict
()
self
.
state_mem
=
dict
()
self
.
state_mem
[
'cpu'
]
=
dict
()
self
.
state_mem
[
'cpu'
]
=
dict
()
self
.
state_mem
[
'cuda'
]
=
dict
()
self
.
state_mem
[
'cuda'
]
=
dict
()
self
.
reset
()
self
.
reset
()
@
property
@
property
def
total_number
(
self
):
def
total_number
(
self
):
return
self
.
_cnter
return
self
.
_cnter
def
reset
(
self
):
def
reset
(
self
):
self
.
_cnter
=
0
# the counter of instances
self
.
_cnter
=
0
# the counter of instances
self
.
total_mem
[
'cpu'
]
=
0
# memory occupation of instances in cpu
self
.
total_mem
[
'cpu'
]
=
0
# memory occupation of instances in cpu
self
.
total_mem
[
'cuda'
]
=
0
# memory of occupation of instances in cuda
self
.
total_mem
[
'cuda'
]
=
0
# memory of occupation of instances in cuda
# memory conditions for all states
# memory conditions for all states
for
state
in
self
.
states_cls
:
for
state
in
self
.
states_cls
:
self
.
state_mem
[
'cpu'
][
state
]
=
0
self
.
state_mem
[
'cpu'
][
state
]
=
0
self
.
state_mem
[
'cuda'
][
state
]
=
0
self
.
state_mem
[
'cuda'
][
state
]
=
0
def
register_new_instance
(
self
):
def
register_new_instance
(
self
):
self
.
_cnter
+=
1
self
.
_cnter
+=
1
def
delete_instance
(
self
):
def
delete_instance
(
self
):
self
.
_cnter
-=
1
self
.
_cnter
-=
1
def
print_info
(
self
):
def
print_info
(
self
):
print
(
f
"Total number:
{
self
.
total_number
}
"
,
print
(
f
"Total number:
{
self
.
total_number
}
"
,
f
"Total CPU memory occupation:
{
self
.
total_mem
[
'cpu'
]
}
"
,
f
"Total CPU memory occupation:
{
self
.
total_mem
[
'cpu'
]
}
"
,
f
"Total CUDA memory occupation:
{
self
.
total_mem
[
'cuda'
]
}
\n
"
,
f
"Total CUDA memory occupation:
{
self
.
total_mem
[
'cuda'
]
}
\n
"
,
sep
=
'
\n
'
)
sep
=
'
\n
'
)
for
state
in
self
.
states_cls
:
for
state
in
self
.
states_cls
:
print
(
f
"
{
state
}
: CPU memory occupation:
{
self
.
state_mem
[
'cpu'
][
state
]
}
"
,
print
(
f
"
{
state
}
: CPU memory occupation:
{
self
.
state_mem
[
'cpu'
][
state
]
}
"
,
f
"
{
state
}
: CUDA memory occupation:
{
self
.
state_mem
[
'cuda'
][
state
]
}
\n
"
,
f
"
{
state
}
: CUDA memory occupation:
{
self
.
state_mem
[
'cuda'
][
state
]
}
\n
"
,
sep
=
'
\n
'
)
sep
=
'
\n
'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment