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
448248b2
Unverified
Commit
448248b2
authored
Nov 10, 2022
by
Super Daniel
Committed by
GitHub
Nov 10, 2022
Browse files
[fx] metainfo_trace as an API. (#1873)
* [fx] metainfo_trace as an API. * [fx] add return.
parent
6d559ea6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
4 deletions
+39
-4
colossalai/fx/__init__.py
colossalai/fx/__init__.py
+1
-1
colossalai/fx/passes/__init__.py
colossalai/fx/passes/__init__.py
+2
-2
colossalai/fx/passes/meta_info_prop.py
colossalai/fx/passes/meta_info_prop.py
+36
-1
No files found.
colossalai/fx/__init__.py
View file @
448248b2
from
._compatibility
import
compatibility
,
is_compatible_with_meta
from
._compatibility
import
compatibility
,
is_compatible_with_meta
from
.graph_module
import
ColoGraphModule
from
.graph_module
import
ColoGraphModule
from
.passes
import
MetaInfoProp
from
.passes
import
MetaInfoProp
,
metainfo_trace
from
.tracer
import
ColoTracer
,
meta_trace
,
symbolic_trace
from
.tracer
import
ColoTracer
,
meta_trace
,
symbolic_trace
colossalai/fx/passes/__init__.py
View file @
448248b2
from
.adding_split_node_pass
import
balanced_split_pass
,
split_with_split_nodes_pass
from
.adding_split_node_pass
import
balanced_split_pass
,
split_with_split_nodes_pass
from
.shard_1d_pass
import
column_shard_linear_pass
,
row_shard_linear_pass
from
.meta_info_prop
import
MetaInfoProp
from
.concrete_info_prop
import
ConcreteInfoProp
from
.concrete_info_prop
import
ConcreteInfoProp
from
.meta_info_prop
import
MetaInfoProp
,
metainfo_trace
from
.shard_1d_pass
import
column_shard_linear_pass
,
row_shard_linear_pass
colossalai/fx/passes/meta_info_prop.py
View file @
448248b2
...
@@ -6,7 +6,7 @@ import torch.fx
...
@@ -6,7 +6,7 @@ import torch.fx
from
torch.fx.node
import
Argument
,
Node
,
Target
from
torch.fx.node
import
Argument
,
Node
,
Target
from
torch.utils._pytree
import
tree_map
from
torch.utils._pytree
import
tree_map
from
colossalai.fx._compatibility
import
compatibility
from
colossalai.fx._compatibility
import
compatibility
,
is_compatible_with_meta
from
colossalai.fx.profiler
import
(
from
colossalai.fx.profiler
import
(
GraphInfo
,
GraphInfo
,
activation_size
,
activation_size
,
...
@@ -315,3 +315,38 @@ class MetaInfoProp(torch.fx.Interpreter):
...
@@ -315,3 +315,38 @@ class MetaInfoProp(torch.fx.Interpreter):
]
]
return
tabulate
(
node_summaries
,
headers
=
headers
,
stralign
=
'right'
)
return
tabulate
(
node_summaries
,
headers
=
headers
,
stralign
=
'right'
)
def
metainfo_trace
(
gm
:
torch
.
fx
.
GraphModule
,
*
args
,
verbose
:
bool
=
False
,
unit
:
str
=
"MB"
,
**
kwargs
)
->
None
:
"""
MetaInfo tracing API
Given a ``GraphModule`` and a sample input, this API will trace the MetaInfo of a single training cycle,
and annotate them on ``gm.graph``.
Uses:
>>> model = ...
>>> gm = symbolic_trace(model)
>>> args = ... # sample input to the ``GraphModule``
>>> metainfo_trace(gm, *args)
Args:
gm (torch.fx.GraphModule): The ``GraphModule`` to be annotated with MetaInfo.
verbose (bool, optional): Whether to show ``MetaInfoProp.summary()`. Defaults to False.
unit (str, optional): The unit of memory. Defaults to "MB".
Returns:
torch.fx.GraphModule: The ``GraphModule`` annotated with MetaInfo.
"""
device
=
torch
.
device
(
'cuda'
)
if
torch
.
cuda
.
is_available
()
else
torch
.
device
(
'cpu'
)
interp
=
MetaInfoProp
(
gm
.
to
(
device
))
if
is_compatible_with_meta
():
from
colossalai.fx.profiler
import
MetaTensor
args
=
tree_map
(
lambda
x
:
MetaTensor
(
x
,
fake_device
=
device
),
args
)
kwargs
=
tree_map
(
lambda
x
:
MetaTensor
(
x
,
fake_device
=
device
),
kwargs
)
interp
.
propagate
(
*
args
,
**
kwargs
)
if
verbose
:
interp
.
summary
(
unit
)
gm
.
to
(
'cpu'
)
del
interp
return
gm
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