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
7f2d2b2b
Unverified
Commit
7f2d2b2b
authored
Jun 10, 2022
by
Frank Lee
Committed by
GitHub
Jun 10, 2022
Browse files
[engine] fixed empty op hook check (#1096)
* [engine] fixed empty op hook check * polish code
parent
14e5b11d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
colossalai/engine/_base_engine.py
colossalai/engine/_base_engine.py
+4
-1
colossalai/engine/ophooks/utils.py
colossalai/engine/ophooks/utils.py
+5
-5
No files found.
colossalai/engine/_base_engine.py
View file @
7f2d2b2b
...
...
@@ -92,7 +92,10 @@ class Engine:
self
.
_schedule
=
NonPipelineSchedule
()
if
self
.
uses_pipeline
:
self
.
_schedule
.
pre_processing
(
self
)
register_ophooks_recursively
(
self
.
_model
,
self
.
_ophook_list
)
#register hook if any
if
len
(
self
.
_ophook_list
)
>
0
:
register_ophooks_recursively
(
self
.
_model
,
self
.
_ophook_list
)
@
property
def
ophooks
(
self
):
...
...
colossalai/engine/ophooks/utils.py
View file @
7f2d2b2b
...
...
@@ -85,11 +85,15 @@ class PostBackwardFunction(torch.autograd.Function):
def
register_ophooks_recursively
(
module
:
torch
.
nn
.
Module
,
ophook_list
:
List
[
BaseOpHook
]
=
None
,
ophook_list
:
List
[
BaseOpHook
],
name
:
str
=
""
,
filter_fn
:
Optional
[
Callable
]
=
None
):
r
"""Recursilvely register pre/post hooks for all submodules in the module in FWD and BWD."""
assert
isinstance
(
module
,
torch
.
nn
.
Module
)
assert
isinstance
(
ophook_list
,
(
list
,
tuple
))
assert
len
(
ophook_list
)
>
0
,
'expected at least 1 hook in the argument ophook_list but found 0'
for
hook
in
ophook_list
:
assert
(
isinstance
(
hook
,
BaseOpHook
))
# Add hooks for submodules
for
child_name
,
child
in
module
.
named_children
():
...
...
@@ -103,10 +107,6 @@ def register_ophooks_recursively(module: torch.nn.Module,
if
filter_fn
is
not
None
and
filter_fn
(
module
):
return
if
ophook_list
is
not
None
:
for
hook
in
ophook_list
:
assert
(
isinstance
(
hook
,
BaseOpHook
))
def
_pre_forward_module_hook
(
submodule
,
*
args
):
for
hook
in
ophook_list
:
assert
isinstance
(
submodule
,
torch
.
nn
.
Module
)
...
...
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