Skip to content
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

[MO] pip packaging #3123

Merged
merged 6 commits into from
Feb 9, 2021
Merged

[MO] pip packaging #3123

merged 6 commits into from
Feb 9, 2021

Conversation

dkurt
Copy link
Contributor

@dkurt dkurt commented Nov 13, 2020

Usage

import mo_tf
import sys
import subprocess

subprocess.run([sys.executable,
                mo_tf.__file__,
                '--input_model', 'mobilenet_v1_1.0_224_frozen.pb',
                '--input_shape', '[1,224,224,3]'],
               check=True)

Install

  • now
pip install git+https://github.com/dkurt/openvino.git@mo_pip#subdirectory=model-optimizer
  • after merge
pip install git+https://github.com/openvinotoolkit/openvino.git#subdirectory=model-optimizer

or by wheel

Key features:

  • No test data (*_test.py and test-generator)
  • Only minimal set of dependencies (no frameworks) to make package light

@dkurt dkurt requested a review from a team November 13, 2020 10:59
@dkurt dkurt marked this pull request as draft November 13, 2020 10:59
@openvino-pushbot openvino-pushbot added the category: MO Model Optimizer label Nov 13, 2020
@dkurt dkurt marked this pull request as ready for review November 16, 2020 13:13
@dkurt dkurt mentioned this pull request Dec 17, 2020
@dkurt dkurt requested a review from a team December 30, 2020 08:43
@dkurt dkurt force-pushed the mo_pip branch 8 times, most recently from 976928d to a68e5ad Compare December 30, 2020 10:02
@dkurt
Copy link
Contributor Author

dkurt commented Dec 30, 2020

@lazarevevgeny, @mryzhov, please review updated version of PR

model-optimizer/setup.py Outdated Show resolved Hide resolved
@SDxKeeper
Copy link
Contributor

SDxKeeper commented Jan 12, 2021

@dkurt Can you please describe how user should use this package?

  1. Currently package installs requirements_*.txt files directly into root of virtual env if user uses it. Will you add documentation to the package how to install deps?
  2. Cloning full openvino repo is quite long process. Will there be a pip distribution of release on pypi.org similar to https://pypi.org/project/openvino/ package
  3. Using subprocess is good for first step, do you see direct MO software API usage from python code in the future (without spawning new process)?

@dkurt
Copy link
Contributor Author

dkurt commented Jan 12, 2021

@dkurt Can you please describe how user should use this package?

See example here: deepchem/deepchem#2332. We need this usage to use MO from GitHub as pip dependency.

Currently package installs requirements_*.txt files directly into root of virtual env if user uses it. Will you add documentation to the package how to install deps?

Not clear for me what kind of documentations should be added? requirements_*.txt is required by MO and that's why it's added to the package.

Cloning full openvino repo is quite long process. Will there be a pip distribution of release on pypi.org similar to https://pypi.org/project/openvino/ package

setup.py still required for both. You may install in two ways: as git repo or as a wheel. See the tests workflow with wheel example.

Using subprocess is good for first step, do you see direct MO software API usage from python code in the future (without spawning new process)?

There were a proposal at initial commit 6a663f3. But we need this feature ASAP so don't want to block on API review.

model-optimizer/setup.py Outdated Show resolved Hide resolved
model-optimizer/setup.py Outdated Show resolved Hide resolved
model-optimizer/setup.py Show resolved Hide resolved
model-optimizer/setup.py Outdated Show resolved Hide resolved
Comment on lines +70 to +79
def find_package_modules(self, package, package_dir):
modules = super().find_package_modules(package, package_dir)
return [
(pkg, module, filename)
for (pkg, module, filename) in modules
if not filename.endswith('_test.py')
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we reuse the CMake script which is already available for the MO to get list of files which needes to be included into the package?

CC @slyubimt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure that CMake dependency is a good option.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a script "/automation/create_package.py" which will create an archive with all necessary files. Instead of implementing logic to determine list of files to be included in the wheel we can re-use this script.

model-optimizer/setup.py Outdated Show resolved Hide resolved
Comment on lines +58 to +69
path = os.path.join(self.install_purelib, package_name, '__init__.py')
with open(path, 'wt') as f:
f.write('import os, sys\n')
f.write('from {} import mo\n'.format(package_name))
# This is required to fix internal imports
f.write('sys.path.append(os.path.dirname(__file__))\n')
# We install a package into custom folder "package_name".
# Redirect import to model-optimizer/mo/__init__.py
f.write('sys.modules["mo"] = mo')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change something in the MO so we could get rid of this workaround?

@dkurt
Copy link
Contributor Author

dkurt commented Jan 13, 2021

@SDxKeeper,

Currently package installs requirements_*.txt files directly into root of virtual env if user uses it. Will you add documentation to the package how to install deps?

I got your point, sorry for confusion. I'll try to fix that.

UPD: Solved

@SDxKeeper
Copy link
Contributor

Currently package installs requirements_*.txt files directly into root of virtual env if user uses it. Will you add documentation to the package how to install deps?

Not clear for me what kind of documentations should be added? requirements_*.txt is required by MO and that's why it's added to the package.

What I mean here is that wrapper which you are making at https://github.com/deepchem/deepchem/pull/2332/files#diff-26fde86013198b5c8d4604dae3d3bd4ed19c9aa18de4db58a4b83dd786c6613fR128 calls MO as it's already installed and configured for tf usage, but MO requires installation of requirements_tf.txt or requirements_tf2.txt before it can be used.
How will user find out that he needs to go to venv folder and call installation of venv/requirements_*.txt files from unusual place in deepchem scenario?

@dkurt
Copy link
Contributor Author

dkurt commented Jan 21, 2021

@SDxKeeper, I fixed this problem so no venv/requirements_*.txt is installed.

@SDxKeeper
Copy link
Contributor

@dkurt thank you for removing venv/requirements*.txt files. Sorry I didn't notice update on comment 9 days ago.

@mryzhov mryzhov added this to the 2021.3 milestone Feb 8, 2021
Copy link
Contributor

@mryzhov mryzhov left a comment

Choose a reason for hiding this comment

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

@dkurt could you please rebase PR to rerun the tests

@ilya-lavrenov ilya-lavrenov removed their assignment Feb 8, 2021
@mryzhov mryzhov merged commit 14d3310 into openvinotoolkit:master Feb 9, 2021
@dkurt dkurt deleted the mo_pip branch February 18, 2021 14:18
@dkurt dkurt mentioned this pull request Feb 25, 2021
@clouds56
Copy link

Cloning full openvino repo is quite long process. Will there be a pip distribution of release on pypi.org similar to https://pypi.org/project/openvino/ package

setup.py still required for both. You may install in two ways: as git repo or as a wheel. See the tests workflow with wheel example.

Shall we release a wheel (maybe named openvino-mo) on pypi.org?

@dkurt
Copy link
Contributor Author

dkurt commented Aug 15, 2021

@clouds56, there is already openvino-dev. Does it fit your requirements?

@clouds56
Copy link

@dkurt thanks for the information! That's exactly what I need.
(Maybe we should add a link to openvino-dev in package openvino)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: MO Model Optimizer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants