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
74b81395
Commit
74b81395
authored
Jan 09, 2023
by
oahzxl
Browse files
update codegen test
parent
18a51c87
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
18 deletions
+24
-18
tests/test_autochunk/test_autochunk_codegen.py
tests/test_autochunk/test_autochunk_codegen.py
+24
-18
No files found.
tests/test_autochunk/test_autochunk_codegen.py
View file @
74b81395
...
...
@@ -15,16 +15,19 @@ from tests.test_autochunk.evoformer.evoformer import evoformer_base
def
_test_fwd
(
model
:
torch
.
nn
.
Module
,
gm
:
ColoGraphModule
,
node
,
pair
):
torch
.
cuda
.
reset_peak_memory_stats
()
now_mem
=
torch
.
cuda
.
memory_allocated
()
/
1024
**
2
with
torch
.
no_grad
():
gm
(
node
.
clone
(),
pair
.
clone
())
new_now_mem
=
torch
.
cuda
.
memory_allocated
()
/
1024
**
2
new_max_mem
=
torch
.
cuda
.
max_memory_allocated
()
/
1024
**
2
print
(
"autochunk now mem:%.2f max mem:%.2f"
%
(
new_now_mem
-
now_mem
,
new_max_mem
-
now_mem
)
)
# for memory test
# torch.cuda.reset_peak_memory_stats()
# now_mem = torch.cuda.memory_allocated() / 1024**2
# with torch.no_grad():
# node1 = node.clone()
# pair1 = pair.clone()
# gm(node1, pair1)
# new_now_mem = torch.cuda.memory_allocated() / 1024**2
# new_max_mem = torch.cuda.max_memory_allocated() / 1024**2
# print(
# "autochunk now mem:%.2f max mem:%.2f"
# % (new_now_mem - now_mem, new_max_mem - now_mem)
# )
# test forward
with
torch
.
no_grad
():
...
...
@@ -43,7 +46,7 @@ def _test_fwd(model: torch.nn.Module, gm: ColoGraphModule, node, pair):
)
def
_
run_offload
_codegen
(
rank
):
def
_
test_autochunk
_codegen
(
rank
):
# launch colossalai to make sure we could execute colossalai.utils.checkpoint currectly
colossalai
.
launch
(
config
=
{},
...
...
@@ -56,8 +59,10 @@ def _run_offload_codegen(rank):
# build model and input
model
=
evoformer_base
().
cuda
()
node
=
torch
.
randn
(
1
,
100
,
300
,
256
).
cuda
()
pair
=
torch
.
randn
(
1
,
300
,
300
,
128
).
cuda
()
msa_len
=
32
pair_len
=
64
node
=
torch
.
randn
(
1
,
msa_len
,
pair_len
,
256
).
cuda
()
pair
=
torch
.
randn
(
1
,
pair_len
,
pair_len
,
128
).
cuda
()
# trace the module and replace codegen
graph
=
ColoTracer
().
trace
(
...
...
@@ -85,17 +90,18 @@ def _run_offload_codegen(rank):
gm
=
ColoGraphModule
(
model
,
graph
)
gm
.
recompile
()
# assert we have all the components
# code = graph.python_code("self").src
# assert we have inserted chunk
code
=
graph
.
python_code
(
"self"
).
src
assert
"chunk_size"
in
code
# print(code)
_test_fwd
(
model
,
gm
,
node
,
pair
)
gpc
.
destroy
()
def
test_autochunk
():
mp
.
spawn
(
_
run_offload
_codegen
,
nprocs
=
1
)
def
test_autochunk
_codegen
():
mp
.
spawn
(
_
test_autochunk
_codegen
,
nprocs
=
1
)
if
__name__
==
"__main__"
:
_
run_offload
_codegen
(
0
)
_
test_autochunk
_codegen
(
0
)
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