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

[MLF] Add support for multiple modules in Model Library Format #11464

Merged
merged 6 commits into from
Jun 17, 2022

Conversation

mehrdadh
Copy link
Member

@mehrdadh mehrdadh commented May 25, 2022

This PR implements this RFC: apache/tvm-rfcs#76

cc @areusch @gromero

@@ -449,47 +498,53 @@ def _eval_shape(param_name, buffer_shape):
return memory_map


def _export_operator_model_library_format(mod: build_module.OperatorModule, tempdir):
def _export_operator_model_library_format(
mods: typing.List[build_module.OperatorModule], tempdir: pathlib.Path
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if for operator MLF, we should just not allow multiple module export? if they don't have a mod_name, then we can't really identify them or namespace them properly. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah makes sense.

@mehrdadh mehrdadh force-pushed the mlf/multiple_modules branch 3 times, most recently from 6a94c64 to 8665d73 Compare June 2, 2022 01:23
@mehrdadh mehrdadh marked this pull request as ready for review June 7, 2022 18:01
@github-actions github-actions bot requested a review from gromero June 7, 2022 19:41
@mehrdadh mehrdadh requested a review from areusch June 9, 2022 16:36
Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

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

thanks @mehrdadh !

all_module_names = []
for name in metadata["modules"].keys():
all_module_names.append(name)
assert len(all_module_names) == 1, "Multiple modules is not supported."
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 you could simplify to just len(metadata["modules"])

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -24,6 +24,7 @@
import re
import tarfile
import typing
from typing import Union
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 should unify on style here (either also import List, etc) or just typing.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

def _populate_codegen_dir(mod, codegen_dir: str, module_name: str = None):
def _populate_codegen_dir(
mods: Union[
typing.List[executor_factory.ExecutorFactoryModule], typing.List[tvm.runtime.Module]
Copy link
Contributor

Choose a reason for hiding this comment

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

how come tvm.runtime.Module is allowed? also, do we want List[Union[ExecutorFactoryModule, tvm.runtime.Module]]?

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 changed it to build_module.OperatorModule
I think Union of List is correct because the input could be Union of two different list, but not a list of two different type

Copy link
Member Author

Choose a reason for hiding this comment

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

actually since we are passing modules like build_module.OperatorModule and tvm.support.FrontendTestModule I changed it back to tvm.runtime.Module

python/tvm/micro/model_library_format.py Show resolved Hide resolved
with pytest.raises(RuntimeError) as exc:
micro.export_model_library_format([mod, mod], mlf_tar_path)

assert str(exc.exception) == ("Multiple operator is not supported.")
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like in this case the error is that you've passed duplicate mod, right? maybe we should be checking for that or de-duping?

Copy link
Member Author

Choose a reason for hiding this comment

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

No I wanted to simply check the case where we pass multiple operator modules. I can add another module with different name to make it more obvious. thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah can you add another? it seems like passing duplicate modules is a separate error

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, will do a follow up PR. thanks!

Copy link
Member Author

@mehrdadh mehrdadh left a comment

Choose a reason for hiding this comment

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

@areusch thanks for the review! PTAL.

all_module_names = []
for name in metadata["modules"].keys():
all_module_names.append(name)
assert len(all_module_names) == 1, "Multiple modules is not supported."
Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -24,6 +24,7 @@
import re
import tarfile
import typing
from typing import Union
Copy link
Member Author

Choose a reason for hiding this comment

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

done.

def _populate_codegen_dir(mod, codegen_dir: str, module_name: str = None):
def _populate_codegen_dir(
mods: Union[
typing.List[executor_factory.ExecutorFactoryModule], typing.List[tvm.runtime.Module]
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 changed it to build_module.OperatorModule
I think Union of List is correct because the input could be Union of two different list, but not a list of two different type

python/tvm/micro/model_library_format.py Show resolved Hide resolved
with pytest.raises(RuntimeError) as exc:
micro.export_model_library_format([mod, mod], mlf_tar_path)

assert str(exc.exception) == ("Multiple operator is not supported.")
Copy link
Member Author

Choose a reason for hiding this comment

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

No I wanted to simply check the case where we pass multiple operator modules. I can add another module with different name to make it more obvious. thoughts?

@areusch
Copy link
Contributor

areusch commented Jun 15, 2022

@mkatanbaf could you try this out and verify it's working for you?

@mkatanbaf
Copy link
Contributor

@areusch sure, working on it now!

@mehrdadh mehrdadh force-pushed the mlf/multiple_modules branch from f284b60 to 06c9b51 Compare June 16, 2022 18:43
@mehrdadh mehrdadh force-pushed the mlf/multiple_modules branch from 06c9b51 to 36e38f9 Compare June 16, 2022 20:22
Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

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

thanks @mehrdadh ! we can address the comment in a follow-up PR.

for the record @mkatanbaf says this has unblocked him in porting multi-model Corstone-300 tests to Project API.

with pytest.raises(RuntimeError) as exc:
micro.export_model_library_format([mod, mod], mlf_tar_path)

assert str(exc.exception) == ("Multiple operator is not supported.")
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah can you add another? it seems like passing duplicate modules is a separate error

@mehrdadh mehrdadh merged commit 648154d into apache:main Jun 17, 2022
@mehrdadh mehrdadh deleted the mlf/multiple_modules branch June 17, 2022 19:27
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