Skip to content

Export testcase #105

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

Merged
merged 4 commits into from
Feb 26, 2019
Merged

Export testcase #105

merged 4 commits into from
Feb 26, 2019

Conversation

ir5
Copy link
Contributor

@ir5 ir5 commented Feb 25, 2019

I ported the implementation of test case export in chainer_compiler https://github.com/pfnet-research/chainer-compiler/blob/master/scripts/onnx_chainer_util.py.
Some functionalities such as outputting gradients and replacing ID are omitted.

Question?:

  • Should I run the inference with chainer.config.train=True? This might be incompatible with the export function.
  • Can I assume that the number of the outputs of model is always one?



def makedirs(d):
if not os.path.exists(d):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use exist_ok=True and remove if?


chainer.config.train = True
model.cleargrads()
result = model(*args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] Wouldn't it be better to call export from this function?

I think current export_testcase does not output model.onnx file. I think almost all users who call export_testcase will need to call export as well. If a user calls both export and export_testcase, model(*args) will run twice, which is sub-optimal.

Maybe it's worth considering to add a function like export_impl which returns outputs in addition to model and this function uses it instead of running the model by this line.

out_dir (str): The directory name used for saving the input and output.
"""
makedirs(out_dir)
onnx_extra_inputs = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 28-30 are only for chainer-compiler and we shouldn't need them.

@ir5
Copy link
Contributor Author

ir5 commented Feb 25, 2019

I changed the interface of the code so that the function saves the model file "model.onnx" as well.
This function calls forward computation twice, which actually can be reduced to once. But this inefficiency seems relatively small in many situation, so I may want to keep current naive implementation.

@shinh shinh requested a review from disktnk February 25, 2019 08:52
@shinh
Copy link
Member

shinh commented Feb 25, 2019

Yeah, I agree it's OK to run the model twice. I think we should eventually support at least list/tuple outputs, but this PR is a great start.

I'd like to defer to tanaka-san.

Copy link
Member

@disktnk disktnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost looks nice to me

"""
os.makedirs(out_dir, exist_ok=True)
export(model, args,
filename='%s/model.onnx' % out_dir,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use os.path.join function to make file path. L31 is same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for check. Fixed.

@disktnk
Copy link
Member

disktnk commented Feb 25, 2019

I think we should eventually support at least list/tuple outputs, but this PR is a great start.

I agree, I also have my mind to the code assumed only one result, but I think dealing with multiple outputs will be supported when needed.

@disktnk disktnk self-requested a review February 26, 2019 00:43
Copy link
Member

@disktnk disktnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@disktnk disktnk merged commit 5740947 into chainer:master Feb 26, 2019
@disktnk disktnk added this to the 1.3.3 milestone Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants