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
c57e0898
Commit
c57e0898
authored
Mar 09, 2022
by
HELSON
Committed by
Frank Lee
Mar 11, 2022
Browse files
[profile] added example for ProfilerContext (#349)
parent
532ae79c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
9 deletions
+19
-9
colossalai/utils/profiler/prof_utils.py
colossalai/utils/profiler/prof_utils.py
+19
-9
No files found.
colossalai/utils/profiler/prof_utils.py
View file @
c57e0898
...
...
@@ -35,15 +35,25 @@ class ProfilerContext(object):
"""
Profiler context manager
Usage:
from colossalai.utils.profiler import CommProf, ProfilerContext
from torch.utils.tensorboard import SummaryWriter
cc_prof = CommProf()
with ProfilerContext([cc_prof]) as prof:
train()
writer = SummaryWriter('tb/path')
prof.to_tensorboard(writer)
prof.to_file('./prof_logs/')
prof.show()
```python
world_size = 4
inputs = torch.randn(10, 10, dtype=torch.float32, device=get_current_device())
outputs = torch.empty(world_size, 10, 10, dtype=torch.float32, device=get_current_device())
outputs_list = list(torch.chunk(outputs, chunks=world_size, dim=0))
cc_prof = CommProfiler()
with ProfilerContext([cc_prof]) as prof:
op = dist.all_reduce(inputs, async_op=True)
dist.all_gather(outputs_list, inputs)
op.wait()
dist.reduce_scatter(inputs, outputs_list)
dist.broadcast(inputs, 0)
dist.reduce(inputs, 0)
prof.show()
```
"""
def
__init__
(
self
,
profilers
:
List
[
BaseProfiler
]
=
None
,
enable
:
bool
=
True
):
...
...
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