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
f8aeecef
"git@developer.sourcefind.cn:OpenDAS/colossalai.git" did not exist on "b5dbb4617260875ea2835b01232acb8da5dcd2ca"
Commit
f8aeecef
authored
Nov 03, 2022
by
oahzxl
Browse files
add meta
parent
820ea4d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
chunk_codegen.py
chunk_codegen.py
+3
-0
chunk_codegen_run.py
chunk_codegen_run.py
+9
-4
No files found.
chunk_codegen.py
View file @
f8aeecef
...
@@ -366,6 +366,9 @@ def emit_code_with_chunk(body, ckpt_func, nodes, emit_node_func, delete_unused_v
...
@@ -366,6 +366,9 @@ def emit_code_with_chunk(body, ckpt_func, nodes, emit_node_func, delete_unused_v
if
CODEGEN_AVAILABLE
:
if
CODEGEN_AVAILABLE
:
class
ChunkCodeGen
(
CodeGen
):
class
ChunkCodeGen
(
CodeGen
):
def
__init__
(
self
,
meta_graph
):
super
().
__init__
()
self
.
meta_node
=
list
(
meta_graph
.
graph
.
nodes
)
def
_gen_python_code
(
self
,
nodes
,
root_module
:
str
,
namespace
:
_Namespace
)
->
PythonCode
:
def
_gen_python_code
(
self
,
nodes
,
root_module
:
str
,
namespace
:
_Namespace
)
->
PythonCode
:
free_vars
:
List
[
str
]
=
[]
free_vars
:
List
[
str
]
=
[]
...
...
chunk_codegen_run.py
View file @
f8aeecef
...
@@ -9,6 +9,8 @@ import colossalai
...
@@ -9,6 +9,8 @@ import colossalai
from
colossalai.utils
import
free_port
from
colossalai.utils
import
free_port
from
colossalai.core
import
global_context
as
gpc
from
colossalai.core
import
global_context
as
gpc
from
colossalai.fx.graph_module
import
ColoGraphModule
from
colossalai.fx.graph_module
import
ColoGraphModule
from
colossalai.fx.passes.meta_info_prop
import
MetaInfoProp
,
TensorMetadata
from
colossalai.fx.profiler
import
MetaTensor
from
evoformer.evoformer
import
evoformer_base
from
evoformer.evoformer
import
evoformer_base
from
chunk_codegen
import
ChunkCodeGen
from
chunk_codegen
import
ChunkCodeGen
with_codegen
=
True
with_codegen
=
True
...
@@ -56,9 +58,10 @@ def _run_offload_codegen(rank):
...
@@ -56,9 +58,10 @@ def _run_offload_codegen(rank):
# trace the module and replace codegen
# trace the module and replace codegen
tracer
=
ColoTracer
(
trace_act_ckpt
=
True
)
tracer
=
ColoTracer
(
trace_act_ckpt
=
True
)
graph
=
tracer
.
trace
(
model
)
graph
=
tracer
.
trace
(
model
)
# codegen = ChunkCodeGen()
gm_prop
=
torch
.
fx
.
GraphModule
(
model
,
graph
)
# graph.set_codegen(codegen)
interp
=
MetaInfoProp
(
gm_prop
)
interp
.
propagate
(
MetaTensor
(
node
,
fake_device
=
'cuda:0'
),
MetaTensor
(
pair
,
fake_device
=
'cuda:0'
))
# annotate the chunk part
# annotate the chunk part
# for node in graph.nodes:
# for node in graph.nodes:
# if node.name == "linear0":
# if node.name == "linear0":
...
@@ -66,7 +69,9 @@ def _run_offload_codegen(rank):
...
@@ -66,7 +69,9 @@ def _run_offload_codegen(rank):
# if node.name == "linear1":
# if node.name == "linear1":
# setattr(node, "activation_offload", [0, True, False])
# setattr(node, "activation_offload", [0, True, False])
gm
=
ColoGraphModule
(
copy
.
deepcopy
(
model
),
graph
)
codegen
=
ChunkCodeGen
(
gm_prop
)
# graph.set_codegen(codegen)
gm
=
ColoGraphModule
(
model
,
graph
)
gm
.
recompile
()
gm
.
recompile
()
# assert we have all the components
# assert we have all the components
...
...
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