MCPcopy Create free account
hub / github.com/modelscope/modelscope / _register_module

Method _register_module

modelscope/utils/registry.py:55–77  ·  view source on GitHub ↗
(self,
                         group_key=default_group,
                         module_name=None,
                         module_cls=None,
                         force=False)

Source from the content-addressed store, hash-verified

53 return self._modules[group_key].get(module_key, None)
54
55 def _register_module(self,
56 group_key=default_group,
57 module_name=None,
58 module_cls=None,
59 force=False):
60 assert isinstance(group_key,
61 str), 'group_key is required and must be str'
62
63 if group_key not in self._modules:
64 self._modules[group_key] = dict()
65
66 # Some registered module_cls can be function type.
67 # if not inspect.isclass(module_cls):
68 # raise TypeError(f'module is not a class type: {type(module_cls)}')
69
70 if module_name is None:
71 module_name = module_cls.__name__
72
73 if module_name in self._modules[group_key] and not force:
74 raise KeyError(f'{module_name} is already registered in '
75 f'{self._name}[{group_key}]')
76 self._modules[group_key][module_name] = module_cls
77 module_cls.group_key = group_key
78
79 def register_module(self,
80 group_key: str = default_group,

Callers 2

register_moduleMethod · 0.95
_registerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected