support custom weight loader for model runner (#7122)
Co-authored-by: kavioyu <kavioyu@tencent.com>
This commit is contained in:
@@ -2340,3 +2340,16 @@ class LazyValue:
|
||||
self._value = self._creator()
|
||||
self._creator = None
|
||||
return self._value
|
||||
|
||||
|
||||
def dynamic_import(func_path: str):
|
||||
parts = func_path.split(".")
|
||||
if len(parts) < 2:
|
||||
raise ValueError(
|
||||
"func_path should contain both module name and func name (such as 'module.func')"
|
||||
)
|
||||
module_path = ".".join(parts[:-1])
|
||||
func_name = parts[-1]
|
||||
module = importlib.import_module(module_path)
|
||||
func = getattr(module, func_name)
|
||||
return func
|
||||
|
||||
Reference in New Issue
Block a user