support custom weight loader for model runner (#7122)

Co-authored-by: kavioyu <kavioyu@tencent.com>
This commit is contained in:
KavioYu
2025-06-17 07:28:15 +08:00
committed by GitHub
parent c64290dcb5
commit 873ae12cee
4 changed files with 64 additions and 0 deletions

View File

@@ -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