[diffusion] fix: fix Diffusers backend ignores model-specific sampling parameter (#20080)

Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
Junhao Liu
2026-03-17 01:10:46 -07:00
committed by GitHub
parent 9a697ceabb
commit ee106757df
2 changed files with 13 additions and 11 deletions

View File

@@ -360,12 +360,14 @@ def _get_diffusers_model_info(
DiffusersPipeline,
)
sampling_param_cls = DiffusersGenericSamplingParams
pipeline_config_cls = DiffusersGenericPipelineConfig
# If there is a registered native config for this model, inherit its task_type
if model_path is not None:
config_info = _get_config_info(model_path, model_id=model_id)
if config_info is not None:
sampling_param_cls = config_info.sampling_param_cls
native_task_type = config_info.pipeline_config_cls.task_type
if native_task_type != DiffusersGenericPipelineConfig.task_type:
pipeline_config_cls = dataclasses.make_dataclass(
@@ -386,7 +388,7 @@ def _get_diffusers_model_info(
return ModelInfo(
pipeline_cls=DiffusersPipeline,
sampling_param_cls=DiffusersGenericSamplingParams,
sampling_param_cls=sampling_param_cls,
pipeline_config_cls=pipeline_config_cls,
)

View File

@@ -288,7 +288,7 @@ class DiffusersExecutionStage(PipelineStage):
if batch.generator is not None:
kwargs["generator"] = batch.generator
elif batch.seed is not None:
device = self._get_pipeline_device()
device = self._get_generator_device(batch)
kwargs["generator"] = torch.Generator(device=device).manual_seed(batch.seed)
# Image input for img2img or inpainting
@@ -307,15 +307,15 @@ class DiffusersExecutionStage(PipelineStage):
return kwargs
def _get_pipeline_device(self) -> str:
"""Get the device the pipeline is running on."""
for attr in ["unet", "transformer", "vae"]:
component = getattr(self.diffusers_pipe, attr, None)
if component is not None:
try:
return str(next(component.parameters()).device)
except StopIteration:
pass
def _get_generator_device(self, batch: Req) -> str:
"""Resolve RNG device consistently with the non-diffusers path.
Diffusers CPU offload can temporarily park modules on CPU, but that
should not silently switch a CUDA request to CPU RNG, otherwise the
same seed produces different outputs depending on runtime placement.
"""
if batch.generator_device == "cpu":
return "cpu"
return current_platform.device_type
def _load_input_image(self, batch: Req) -> Image.Image | None: