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
c4c02424
Unverified
Commit
c4c02424
authored
Mar 22, 2022
by
ver217
Committed by
GitHub
Mar 22, 2022
Browse files
[zero] sharded model manages ophooks individually (#492)
parent
c9023d40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
colossalai/zero/sharded_model/sharded_model_v2.py
colossalai/zero/sharded_model/sharded_model_v2.py
+6
-2
No files found.
colossalai/zero/sharded_model/sharded_model_v2.py
View file @
c4c02424
...
...
@@ -89,8 +89,8 @@ class ShardedModelV2(nn.Module):
self
.
_iter_cnter
=
0
# Register hooks
register_ophooks_recursively
(
self
.
module
,
[
ZeroHook
(
self
.
shard_strategy
,
self
.
_memstats_collector
,
self
.
process_group
)]
)
self
.
_ophook_list
=
[
ZeroHook
(
self
.
shard_strategy
,
self
.
_memstats_collector
,
self
.
process_group
)]
register_ophooks_recursively
(
self
.
module
,
self
.
_ophook_list
)
self
.
param_hook_mgr
=
BaseParamHookMgr
(
list
(
self
.
module
.
parameters
()))
self
.
param_hook_mgr
.
register_backward_hooks
(
self
.
_grad_post_backward_hook
)
...
...
@@ -134,10 +134,14 @@ class ShardedModelV2(nn.Module):
def
backward
(
self
,
loss
):
loss
.
backward
()
self
.
_post_backward_operations
()
for
ophook
in
self
.
_ophook_list
:
ophook
.
post_iter
()
def
backward_by_grad
(
self
,
tensor
,
grad
):
torch
.
autograd
.
backward
(
tensors
=
tensor
,
grad_tensors
=
grad
)
self
.
_post_backward_operations
()
for
ophook
in
self
.
_ophook_list
:
ophook
.
post_iter
()
@
torch
.
no_grad
()
def
_post_backward_operations
(
self
)
->
None
:
...
...
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