mmengine icon indicating copy to clipboard operation
mmengine copied to clipboard

[Bug] Unable to Inherit Configuration Files Across Repositories

Open ryan-minato opened this issue 2 years ago • 0 comments

Prerequisite

  • [X] I have searched Issues and Discussions but cannot get the expected help.
  • [X] The bug has not been fixed in the latest version(https://github.com/open-mmlab/mmengine).

Environment

Any OS and PyTorch version

Reproduces the problem - code sample

According to the documentation (url), creating a Python library based on mmdet's file structure should allow for inheritance using {package_name}::, but in practice, this approach is blocked.

Config will parse mmdet:: to find mmdet package and inherits the specified configuration file. Actually, as long as the setup.py of the repository(package) conforms to MMEngine Installation specification, Config can use {package_name}:: to inherit the specific configuration file.

Reproduces the problem - command or script

from mmengine.config import Config
cfg = Config.fromfile('test.py')

test.py

_base_=['mylib::datasets/example.py']

Reproduces the problem - error message

AssertionError: mmengine dose not support to load mylib config.

Additional information

The issue likely originates from (url), where a hardcoded dictionary is checked.

...
MODULE2PACKAGE = {
    'mmcls': 'mmcls',
    'mmdet': 'mmdet',
...
    'mmagic': 'mmagic',
}
...
# L134C1-L136C38
assert package in MODULE2PACKAGE, (
    f'mmengine does not support to load {package} config.')
package = MODULE2PACKAGE[package]

To bypass this problem, either add a key-value pair mylib:mylib to the MODULE2PACKAGE constant in mmengine/config/utils.py, or remove the check and replace it with importlib-based imports.

ryan-minato avatar Oct 30 '23 09:10 ryan-minato