Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[WIP] Serde Module for Import/Export of models between Onnx and Mxnet #9892

Closed
wants to merge 15 commits into from

Conversation

anirudhacharya
Copy link
Member

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

  • Import from Onnx.
  • Export to Onnx.

Comments

  • I have currently added this project under contrib, as it is used for experimental features which can later be moved elsewhere.

@spidydev @Roshrini @lupesko @szha

import onnx

def export_model(sym, params):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Member Author

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.

Copy link
Contributor

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

@@ -28,3 +28,4 @@
from . import tensorboard

from . import text
from . import serde
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

Copy link
Contributor

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"""
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this?

Copy link
Member Author

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):
Copy link
Contributor

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'
Copy link
Contributor

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

Copy link
Member Author

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):
Copy link
Contributor

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"""
Copy link
Contributor

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

Copy link
Member Author

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.

thinksanky and others added 12 commits February 27, 2018 11:50
* 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
Copy link
Contributor

@lupesko lupesko left a 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...

@@ -28,3 +28,4 @@
from . import tensorboard

from . import text
from . import serde
Copy link
Contributor

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):
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Member Author

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}
Copy link
Contributor

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.

Copy link
Member Author

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]>
@anirudhacharya
Copy link
Member Author

anirudhacharya commented Mar 1, 2018

will raise another PR. closing this PR

#9963

@anirudhacharya anirudhacharya deleted the serde branch March 1, 2018 23:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.