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

[Feature Request] Support returning the main function of 'train', and 'test' scripts #182

Open
nijkah opened this issue Dec 19, 2022 · 1 comment
Assignees

Comments

@nijkah
Copy link
Contributor

nijkah commented Dec 19, 2022

Describe the feature
Support returning the main function of 'train', and 'test' scripts like mim.train(return_function=True)(args).

Motivation
Currently, mim.train and mim.test works as running the script as a subprocess.
In addition to this, if it can work as returning the main function of these scripts,
it would be nice for third-party frameworks to utilize these scripts in runtime.
For example, our work had to copy-and-paste train scripts to utilize these as function.

One of the possible ways to support this feature is described in https://stackoverflow.com/a/67692.

import importlib.util
import sys

pkg_root = get_installed_path(package)
train_script = osp.join(pkg_root, '.mim', 'tools', 'train.py')

spec = importlib.util.spec_from_file_location("mm.train", train_script)
foo = importlib.util.module_from_spec(spec)
sys.modules["mm.train"] = foo
spec.loader.exec_module(foo)
foo.main()

Although it can be done in other libraries, it seems safer to be supported by mim.

In addition to this, like our example in the above link, it would be helpful to be able to give custom args in parse_args(args) in the scripts to customize its functionality.

Although it affects many other frameworks and packages, I think it would benefit other frameworks in the future! :)

@nijkah nijkah changed the title [Feature Request] Support returning the main function of 'train', and 'test` scripts [Feature Request] Support returning the main function of 'train', and 'test' scripts Dec 19, 2022
@ice-tong
Copy link
Collaborator

ice-tong commented Jan 13, 2023

Hi @nijkah, I'm sorry for the late reply~

Firstly, thanks for your kind advice about this feature request! 🥰

After an internal discussion, we gave our opinion on this feature request. We may not plan to support this feature in MIM, but could provide an API that returns the path to the train and test scripts.

Here are some of the reasons:

  • It's simple to implement the ability to return a function via a given python file, and you've given examples. The important thing is to get the exact train and test script paths. So we think it makes sense to provide this API.

  • The mim train and mim test commands are mainly used to parse command arguments and launch distributed. We tend not to put in other features that would make the code more difficult to maintain.

These are some of our thoughts. If you agree with the above solution, we will create a PR to add an API that returns the path to the train and test scripts.

If you have any other comments, please let us know. Feedback from the community is very important to us!

Thanks again!

cc @pppppM

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

No branches or pull requests

2 participants