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
e481489a
Unverified
Commit
e481489a
authored
Nov 18, 2022
by
Jiarui Fang
Committed by
GitHub
Nov 18, 2022
Browse files
[Gemini] MemtracerWrapper unittests (#1981)
parent
52bd1066
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
colossalai/gemini/ophooks/mem_trace_hook.py
colossalai/gemini/ophooks/mem_trace_hook.py
+5
-0
tests/test_gemini/test_mem_tracer.py
tests/test_gemini/test_mem_tracer.py
+42
-0
No files found.
colossalai/gemini/ophooks/mem_trace_hook.py
View file @
e481489a
...
@@ -36,6 +36,11 @@ class MemTracerOpHook(BaseOpHook):
...
@@ -36,6 +36,11 @@ class MemTracerOpHook(BaseOpHook):
p
.
grad
=
p
.
grad
.
to
(
dev
)
p
.
grad
=
p
.
grad
.
to
(
dev
)
comm_volume
+=
p
.
grad
.
numel
()
*
p
.
grad
.
element_size
()
comm_volume
+=
p
.
grad
.
numel
()
*
p
.
grad
.
element_size
()
for
buf
in
module
.
buffers
():
if
buf
.
device
.
type
!=
dev
:
buf
.
data
=
buf
.
data
.
to
(
dev
)
comm_volume
+=
buf
.
data
.
numel
()
*
buf
.
data
.
element_size
()
if
dev
==
'cuda'
:
if
dev
==
'cuda'
:
self
.
_cur_model_data_vol
=
comm_volume
self
.
_cur_model_data_vol
=
comm_volume
...
...
tests/test_gemini/test_mem_tracer.py
0 → 100644
View file @
e481489a
import
torch
import
torch.nn
as
nn
import
colossalai
from
colossalai.gemini.memory_tracer
import
MemtracerWrapper
from
tests.components_to_test.registry
import
non_distributed_component_funcs
def
run_fwd_bwd
(
model
,
data
,
label
,
criterion
,
enable_autocast
=
False
):
with
torch
.
cuda
.
amp
.
autocast
(
enabled
=
enable_autocast
):
if
criterion
:
y
=
model
(
data
)
loss
=
criterion
(
y
,
label
)
else
:
loss
=
model
(
data
,
label
)
loss
=
loss
.
float
()
model
.
backward
(
loss
)
def
test_tracer
():
# reset the manager, in case that there exists memory information left
test_models
=
[
'repeated_computed_layers'
,
'resnet18'
,
'no_leaf_module'
]
for
model_name
in
test_models
:
get_components_func
=
non_distributed_component_funcs
.
get_callable
(
model_name
)
model_builder
,
train_dataloader
,
_
,
_
,
criterion
=
get_components_func
()
# init model on cpu
model
=
MemtracerWrapper
(
model_builder
())
for
i
,
(
data
,
label
)
in
enumerate
(
train_dataloader
):
if
i
>
1
:
break
data
=
data
.
cuda
()
label
=
label
.
cuda
()
run_fwd_bwd
(
model
,
data
,
label
,
criterion
,
False
)
# model._ophook_list[0].print_non_model_data()
if
__name__
==
'__main__'
:
test_tracer
()
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