-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[WIP] Serde Module for Import/Export of models between Onnx and Mxnet #9892
Conversation
import onnx | ||
|
||
def export_model(sym, params): | ||
pass |
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.
?
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.
Will delete this module for now.
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.
Is this the determined API for exporting MXNet models to onnx format? Have you considered whether we can borrow the interface of this function in Pytorch?
https://github.com/pytorch/pytorch/blob/master/torch/onnx/__init__.py#L43
python/mxnet/contrib/__init__.py
Outdated
@@ -28,3 +28,4 @@ | |||
from . import tensorboard | |||
|
|||
from . import text | |||
from . import serde |
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.
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.
Will change the module name from serde to onnx.
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.
+1
Serde can come in later as a facade on top of onnx and coreml
# and then return the output. | ||
|
||
class MXNetBackend(Backend): | ||
"""MXNet backend for ONNX""" |
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.
what's 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.
This class is used by the onnx backend test framework here - https://github.com/anirudhacharya/incubator-mxnet/blob/serde/python/mxnet/contrib/serde/_import/tests/onnx_backend_test.py
For testing the import functionality, we intend to use ONNX's backend test framework as described here - https://github.com/onnx/onnx/blob/master/docs/OnnxBackendTest.md
This is done to ensure that tests will be shared across different frameworks and that our module will be sync with onnx's standards and definition for various operators. This class will be used by the test framework to run operators on mxnet backend.
from __future__ import absolute_import as _abs | ||
from ....base import string_types | ||
|
||
class Renamer(object): |
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.
This class looks unnecessary
from onnx_mxnet import backend as mxnet_backend | ||
|
||
# This is a pytest magic variable to load extra plugins | ||
pytest_plugins = 'onnx.backend.test.report' |
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.
tests should be put in tests/python/unittests
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.
will change it.
slice_op = symbol.slice_axis(slice_op, axis=axis, begin=begin[i], end=end[i]) | ||
return slice_op | ||
|
||
def _fix_squeeze(self, inputs, new_attr): |
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.
why not do this in attribute converter?
|
||
def run_node(self, node, device='CPU'): # pylint: disable=unused-argument | ||
"""Construct symbol from individual node. | ||
Mainly using this function for unittests""" |
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.
test utility should be put into test code
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.
Will refactor this code along with Renamer and Attribute Converter class.
* temporary fix to update the verionsioning of 1.1.0 that is skipped during build process * updated build_doc.sh * testing new updates of build_doc.sh * fixed comments and syntax * removed test data and comments
* changed url references from dmlc to apache/incubator-mxnet * refactored build all docs * Created dockerfile and modified scripts to support it. * add license header * used license header tool this time * updated scripts to take arguments for flexible use
* TVM bridge support. Support wrap TVM compiled function as a NDArray function. * Testcases and CI to include TVM as dependency * address review comments * Add more comments, change to constexpr * change to log warn * update comment on the type code
* Update website version dropdown on master * Update
* opt register only once * lint pass * opt register only once lint pass * add test_optimizer.cpp * fix warning * typo
* add infer_type for regression ops * trigger CI
* Accelerate the calculation of F1 * cache the mid results * trigger CI
…ork (a trial solution to issue#9866) (apache#9867) * Enable the reporting of cross-entropy or nll loss value during training * Set the default value of loss as a '' to avoid a Python runtime issue when loss argument is not set * Applying the Xavier with "uniform" type to initialize weight when network is VGG
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.
Looks good!
Still needs some work...
python/mxnet/contrib/__init__.py
Outdated
@@ -28,3 +28,4 @@ | |||
from . import tensorboard | |||
|
|||
from . import text | |||
from . import serde |
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.
+1
Serde can come in later as a facade on top of onnx and coreml
import onnx | ||
from .import_onnx import GraphProto | ||
|
||
def import_model(model_file): |
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.
Propose to rename to import_onnx_model
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.
It will be used as follows -
sym, params = mxnet.contrib.onnx._import.import_model("super_resolution.onnx")
So onnx is already present in the package path.
Adding onnx in the method call could be redundant. It will get used like this
sym, params = mxnet.contrib.onnx._import.import_onnx_model("super_resolution.onnx")
I am not sure if we would want that.
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.
Is import_model
a user level API? If so, why is it registered under a hidden module _import
?
@@ -0,0 +1,131 @@ | |||
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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.
2018
@@ -0,0 +1,26 @@ | |||
# coding: utf-8 |
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.
Please add copyright headers
# coding: utf-8 | ||
# pylint: disable=too-many-locals,invalid-name | ||
"""backend wrapper for onnx test infrastructure""" | ||
from collections import namedtuple |
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.
nit: newline
@@ -0,0 +1,70 @@ | |||
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
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.
2018, repeats in more files, please update.
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 will update all the license and copyright statements.
@@ -28,7 +28,7 @@ | |||
else: | |||
from setuptools import setup | |||
from setuptools.extension import Extension | |||
kwargs = {'install_requires': ['numpy<=1.13.3,>=1.8.2', 'requests==2.18.4', 'graphviz==0.8.1'], 'zip_safe': False} | |||
kwargs = {'install_requires': ['numpy<=1.13.3,>=1.8.2', 'requests==2.18.4', 'graphviz==0.8.1', 'onnx>=1.0.1'], 'zip_safe': False} |
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.
Let's make ONNX a runtime dependency, in the future we can update it to be an install time dependency.
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.
will do.
- Change package name to onnx. - remove Renamer class - Add apache license to files. - refactor test files to unittests folder. - remove export folder. Signed-off-by: Acharya <[email protected]>
will raise another PR. closing this PR |
Description
ImportExport module based on this design doc - https://cwiki.apache.org/confluence/display/MXNET/Proposal%3A+ImportExport+module.
This PR is a work in progress, we are just sending out this skeleton code to get views on the api specification, general code structure, and any additional dependencies it may pull into the project. As this module is also being discussed currently in the dev list, it is open to change in the design and specification of the project.
Changes
Comments
@spidydev @Roshrini @lupesko @szha