[Hardware] Extend diffusion engine plugin extensibility for out-of-tree hardware backends (#3239)
Signed-off-by: Yuchen Jiang <yucjiang@amazon.com> Co-authored-by: Yuchen Jiang <yucjiang@amazon.com> Co-authored-by: Canlin Guo <canlinguosdu@gmail.com>
This commit is contained in:
4 files changed
+196
-3
No files matched your search
@@ -487,10 +487,65 @@ _DIFFUSION_PRE_PROCESS_FUNCS = {
|
||||
}
|
||||
|
||||
|
||||
def register_diffusion_model(
|
||||
model_arch: str,
|
||||
module_name: str,
|
||||
class_name: str,
|
||||
pre_process_func_name: str | None = None,
|
||||
post_process_func_name: str | None = None,
|
||||
) -> None:
|
||||
"""Register a diffusion model pipeline from an out-of-tree plugin.
|
||||
|
||||
This can be used to add new model architectures or to replace an
|
||||
existing built-in pipeline with a platform-optimised implementation
|
||||
(same ``model_arch`` key).
|
||||
|
||||
Args:
|
||||
model_arch: Architecture name (e.g. ``"WanPipeline"``).
|
||||
module_name: Fully qualified module path
|
||||
(e.g. ``"my_plugin.diffusion.pipeline_wan"``).
|
||||
class_name: Class name within *module_name*.
|
||||
pre_process_func_name: Optional name of the pre-process function
|
||||
located in *module_name*. Pass ``None`` to keep the existing
|
||||
entry when replacing a built-in model.
|
||||
post_process_func_name: Optional name of the post-process function
|
||||
located in *module_name*. Pass ``None`` to keep the existing
|
||||
entry when replacing a built-in model.
|
||||
"""
|
||||
# Register model class in DiffusionModelRegistry
|
||||
DiffusionModelRegistry.register_model(
|
||||
model_arch,
|
||||
f"{module_name}:{class_name}",
|
||||
)
|
||||
|
||||
# Store in _DIFFUSION_MODELS so _load_process_func can resolve the
|
||||
# module. Convention: when mod_relname is empty the mod_folder field
|
||||
# stores a *full* module path instead of a relative folder.
|
||||
_DIFFUSION_MODELS[model_arch] = (module_name, "", class_name)
|
||||
|
||||
# Optionally register pre/post process funcs.
|
||||
if pre_process_func_name is not None:
|
||||
_DIFFUSION_PRE_PROCESS_FUNCS[model_arch] = pre_process_func_name
|
||||
if post_process_func_name is not None:
|
||||
_DIFFUSION_POST_PROCESS_FUNCS[model_arch] = post_process_func_name
|
||||
|
||||
logger.info(
|
||||
"Registered diffusion model %s -> %s.%s",
|
||||
model_arch,
|
||||
module_name,
|
||||
class_name,
|
||||
)
|
||||
|
||||
|
||||
def _load_process_func(od_config: OmniDiffusionConfig, func_name: str):
|
||||
"""Load and return a process function from the appropriate module."""
|
||||
mod_folder, mod_relname, _ = _DIFFUSION_MODELS[od_config.model_class_name]
|
||||
module_name = f"vllm_omni.diffusion.models.{mod_folder}.{mod_relname}"
|
||||
if mod_relname == "":
|
||||
# Full module path (registered via register_diffusion_model)
|
||||
module_name = mod_folder
|
||||
else:
|
||||
# Built-in model (relative path convention)
|
||||
module_name = f"vllm_omni.diffusion.models.{mod_folder}.{mod_relname}"
|
||||
module = importlib.import_module(module_name)
|
||||
func = getattr(module, func_name)
|
||||
return func(od_config)
|
||||
|
||||
Reference in new issue
Block a user