-
Notifications
You must be signed in to change notification settings - Fork 24
Support temporary implicit input #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
onnx_chainer/export.py
Outdated
@@ -103,11 +103,28 @@ def rename_variable_name( | |||
context.set_name(variables, new_name, pinned=True) | |||
|
|||
|
|||
class InputCacheHook(chainer.FunctionHook): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about RetainInputHook
? "cache" sounds like we have the real copy of the inputs
onnx_chainer/export.py
Outdated
@@ -103,11 +103,28 @@ def rename_variable_name( | |||
context.set_name(variables, new_name, pinned=True) | |||
|
|||
|
|||
class InputCacheHook(chainer.FunctionHook): | |||
"""cache raw inputs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""cache raw inputs | |
"""Retain raw inputs |
onnx_chainer/export.py
Outdated
|
||
def forward_postprocess(self, fn, in_data): | ||
# in_data is ndarray, not variable | ||
self.func_inputs[id(fn)] = in_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will increase memory consumption. I think what we need to keep here is in_data
which is not wrapped by chainer.Variable
in inputs
of FunctionNode.forward
. However, it seems to be impossible to check this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly! I tried LinkHook
instead.
Codecov Report
@@ Coverage Diff @@
## master #202 +/- ##
==========================================
+ Coverage 89.69% 89.88% +0.18%
==========================================
Files 24 24
Lines 1417 1473 +56
==========================================
+ Hits 1271 1324 +53
- Misses 146 149 +3
Continue to review full report at Codecov.
|
f8f6014
to
0a2d8ab
Compare
/test |
Successfully created a job for commit 0a2d8ab: |
Sorry if I'm confused, but this does not work for the following case?
|
…r into fix/implicit-weakref
Good catch. If inputs are ndarray type, function node converts them to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
onnx_chainer/export.py
Outdated
if referenced_var is None: | ||
# This variable is created within function node and weakref | ||
# is lost. Make temporary variable and retain it. | ||
if isinstance(inputs[i], chainer.Variable): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temp_var = chainer.as_variable(inputs[i])
?
/test |
Successfully created a job for commit 8148f6e: |
fixes #201
Then, second value's reference is lost when convert to graph, so converter cannot set the value into ONNX graph .
To keep such a value reference, exporter retains input values in forwarding using
LinkHook
and patchedapply
. By introducingLinkHook
, the hook function only retains temporary values to reduce memory usage, but the target model is required to useforward
function, not__call__
function.export_implicit_inputs_public
option, because converter cannot distinguish the temporary value is covered by converter or not. For example,beta
of batch-normalization is sometimesNone
but followed by converter.