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

Allow tvmc to compile models with AOT executor in MLF #8331

Merged
merged 3 commits into from
Jul 1, 2021

Conversation

Mousius
Copy link
Member

@Mousius Mousius commented Jun 24, 2021

The tflite_compiled_model fixture was getting duplicated a few times so I've added a parameterized fixture tflite_tvmc_compiler which combines tmpdir_factory setup with compile_model

Nested target params broke a basic string split, so in cases where we use nested target params I replaced the string split with shlex split

@Mousius
Copy link
Member Author

Mousius commented Jun 24, 2021

@leandron @gromero

Copy link
Contributor

@gromero gromero left a comment

Choose a reason for hiding this comment

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

Hi @Mousius . Thanks for adding these AOT bits to tvmc.

Please see my comments inline

I really liked your commit message and I get happy when I see that format instead of the "bullet format", like adding the comment about shlex etc. Thank you. The only thing I missed is that you actually added an important change in TVMCPackage.import_package() which is the ability to distinguish Graph from AOT runtime based on graph, so it would be nice to mention it also in the commit message, I think :)

if "graph" in metadata["runtimes"]:
graph = temp.relpath("runtime-config/graph/graph.json")
else:
graph = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. I just think a hint about AOT should exist here. How about adding a comment above graph = None, like "AOT runtime"?

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'll use the code as docs rather than a comment and pop the condition in a variable:

is_graph_runtime = "graph" in metadata["runtimes"]
graph = temp.relpath("runtime-config/graph/graph.json") if is_graph_runtime else None

@pytest.fixture(scope="session")
def tflite_compiled_model_mlf(tmpdir_factory):
@pytest.fixture
def tflite_tvmc_compiler(tmpdir_factory):
Copy link
Contributor

@gromero gromero Jun 24, 2021

Choose a reason for hiding this comment

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

How about renaming the tflite_tvmc_compiler fixture to tflite_compile_model, just because I don't think that tvmc in there is informative. But no strong feelings about it. Feel free also to get more input from Leandro before sending a v2.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, this is in the tvmc conftest so context makes more sense 😸 good call!

@@ -82,9 +85,13 @@ def test_tvmc_export_package_mlf(tflite_mobilenet_v1_1_quant, tmpdir_factory):
assert str(exp.value) == expected_reason, on_error


def test_tvmc_import_package_mlf(tflite_compiled_model_mlf):
def test_tvmc_import_package_mlf(tflite_mobilenet_v1_1_quant, tflite_tvmc_compiler):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can rename test_tvmc_import_package_mlf to test_tvmc_import_package_mlf_graph.

@@ -97,3 +104,27 @@ def test_tvmc_import_package_mlf(tflite_compiled_model_mlf):
assert tvmc_package.graph is not None, ".graph must be set in the MLF archive."
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message must be adapted here, adding "[...] if not AOT". Maybe:
`".graph must be set in the MLF archive if not AOT runtime"

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, I'll say "if Graph" to make it clear where the distinction is

Copy link
Contributor

@leandron leandron left a comment

Choose a reason for hiding this comment

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

LGTM, agree with @gromero's suggestions.

The tflite_compiled_model fixture was getting duplicated a few times so
I've added a parameterized fixture tflite_tvmc_compiler which combines
tmpdir_factory setup with compile_model

Nested targets broke a basic string split, so in cases where we use
nested targets I replaced the string split with shlex split
@leandron
Copy link
Contributor

This is is failing in the latest version of this PR. I'm pasting the error below, to save a trip to Jenkins:

==================================== ERRORS ====================================

____________ ERROR collecting tests/python/driver/tvmc/test_mlf.py _____________
/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:87: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:249: in pytest_pycollect_makeitem
    res = list(collector._genfunctions(name, obj))
/usr/local/lib/python3.6/dist-packages/_pytest/python.py:470: in _genfunctions
    self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:324: in call_extra
    return self(**kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/usr/local/lib/python3.6/dist-packages/pluggy/manager.py:87: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
conftest.py:35: in pytest_generate_tests
    tvm.testing._auto_parametrize_target(metafunc)
python/tvm/testing.py:800: in _auto_parametrize_target
    for mark in metafunc.definition.iter_markers("parametrize")
python/tvm/testing.py:801: in <listcomp>
    for arg in mark.args[0].split(",")
E   AttributeError: 'list' object has no attribute 'split'
=============================== warnings summary ===============================
../usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/utils/testing.py:21
  /usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/utils/testing.py:21: DeprecationWarning: the imp module is eprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

- Docs: https://docs.pytest.org/en/stable/warnings.html
- generated xml file: /workspace/build/pytest-results/python-integration-driver-ctypes.xml -
=========================== short test summary info ============================
ERROR tests/python/driver/tvmc/test_mlf.py - AttributeError: 'list' object ha...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
========================= 1 warning, 1 error in 0.97s ==========================

Apart from that, LGTM. Happy to review/merge once we get CI working.

@Mousius
Copy link
Member Author

Mousius commented Jun 30, 2021

Hopefully that should do it, thanks for your feedback @gromero 😸

Copy link
Contributor

@leandron leandron left a comment

Choose a reason for hiding this comment

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

LGTM

@leandron leandron merged commit 9112b6e into apache:main Jul 1, 2021
@leandron
Copy link
Contributor

leandron commented Jul 1, 2021

This is now merged, thanks @Mousius and @gromero

lygztq pushed a commit to lygztq/tvm that referenced this pull request Jul 1, 2021
* Allow tvmc to compile models with AOT executor

The tflite_compiled_model fixture was getting duplicated a few times so
I've added a parameterized fixture tflite_tvmc_compiler which combines
tmpdir_factory setup with compile_model

Nested targets broke a basic string split, so in cases where we use
nested targets I replaced the string split with shlex split

* Clarify that graph JSON is required only for graph executor

Plus other clean ups

* Change parametrize fixture to use string instead of list
ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
* Allow tvmc to compile models with AOT executor

The tflite_compiled_model fixture was getting duplicated a few times so
I've added a parameterized fixture tflite_tvmc_compiler which combines
tmpdir_factory setup with compile_model

Nested targets broke a basic string split, so in cases where we use
nested targets I replaced the string split with shlex split

* Clarify that graph JSON is required only for graph executor

Plus other clean ups

* Change parametrize fixture to use string instead of list
zxy844288792 pushed a commit to zxy844288792/tvm that referenced this pull request Mar 4, 2022
* Allow tvmc to compile models with AOT executor

The tflite_compiled_model fixture was getting duplicated a few times so
I've added a parameterized fixture tflite_tvmc_compiler which combines
tmpdir_factory setup with compile_model

Nested targets broke a basic string split, so in cases where we use
nested targets I replaced the string split with shlex split

* Clarify that graph JSON is required only for graph executor

Plus other clean ups

* Change parametrize fixture to use string instead of list
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