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

generate op frontend code for IDE auto-complete #8244

Merged
merged 4 commits into from
Oct 16, 2017
Merged

Conversation

szha
Copy link
Member

@szha szha commented Oct 12, 2017

Description

This PR aims at providing auto-complete for text editors by actually writing the generated op functions to module source codes. The solution should work for pip/setuptools install command. python setup.py develop should remain runtime-generated.

Checklist

Essentials

  • Changes are complete (i.e. I finished coding on this PR)
  • Passed code style checking (make lint)
  • All changes have test coverage
  • To my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Decouple code generation and function registration. Existing tests already covered this change.
  • Write generated code to source files as part of the post-install script of install-command.

Comments

  • Backward compatible.
  • This change should not affect python setup.py develop.
  • Since pip uses a separate setup.py, another change will happen in the distro package to take effect in pip.

@szha szha force-pushed the code_gen branch 2 times, most recently from 6078bb0 to 420f222 Compare October 13, 2017 00:42
@reminisce
Copy link
Contributor

As a PyCharm user, I am looking forward to this very much. :)

try:
if int(_os.environ.get("MXNET_ENABLE_CYTHON", True)) == 0:
from .._ctypes.ndarray import NDArrayBase
from .._ctypes.ndarray import CachedOp, _imperative_invoke
from .._ctypes.ndarray import NDArrayBase, CachedOp
Copy link
Contributor

Choose a reason for hiding this comment

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

Import these from register?

symbol_function.__module__ = 'mxnet.symbol'
return symbol_function

if not _internal.__dict__.get('skip_register'):
Copy link
Contributor

Choose a reason for hiding this comment

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

where does skip_register come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is that if the code is already generated, a flag will be written to the internal module indicating that. I will include its generation in the next commit.
I'm currently testing locally the generation on different python versions.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can detect it from len(op.__all__)

@szha szha force-pushed the code_gen branch 2 times, most recently from 09133e7 to 0fa1528 Compare October 13, 2017 23:11
@eric-haibin-lin
Copy link
Member

awesome feature!

@szha szha changed the title [WIP] generate op frontend code for IDE auto-complete generate op frontend code for IDE auto-complete Oct 14, 2017
"""Post-installation for installation mode."""
def run(self):
install.run(self)
from mxnet.base import _generate_op_module_signature
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 guaranteed to import the mxnet that's just installed? Can you read the path from install or self?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no guarantee, and neither is there guarantee that self or install resides in the target site-packages. Currently what this code does in practice is:

  1. generate the code in the source code folder first (hence the .gitignore change)
  2. copy source codes into $PWD/build/mxnet and add packaging info
  3. copy $PWD/build to the site-packages and byte-compile the .py files.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens for pip package?

Copy link
Member Author

@szha szha Oct 15, 2017

Choose a reason for hiding this comment

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

It copies the whole tree from mxnet-distro/mxnet-build/python/mxnet (without generated source) to mxnet-distro/mxnet, and does the above step 1 and 2. Finally, the whole tree in mxnet-distro/build is packaged into a wheel which contains the generated source.

@piiswrong piiswrong merged commit 99099fa into apache:master Oct 16, 2017
@szha szha deleted the code_gen branch October 16, 2017 03:18
crazy-cat pushed a commit to crazy-cat/incubator-mxnet that referenced this pull request Oct 26, 2017
* decouple codegen and register

* address comments on refactor

* auto generate code

* trigger test
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.

4 participants