[diffusion] fix: fix Diffusers backend ignores model-specific sampling parameter (#20080)
Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
@@ -360,12 +360,14 @@ def _get_diffusers_model_info(
|
|||||||
DiffusersPipeline,
|
DiffusersPipeline,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sampling_param_cls = DiffusersGenericSamplingParams
|
||||||
pipeline_config_cls = DiffusersGenericPipelineConfig
|
pipeline_config_cls = DiffusersGenericPipelineConfig
|
||||||
|
|
||||||
# If there is a registered native config for this model, inherit its task_type
|
# If there is a registered native config for this model, inherit its task_type
|
||||||
if model_path is not None:
|
if model_path is not None:
|
||||||
config_info = _get_config_info(model_path, model_id=model_id)
|
config_info = _get_config_info(model_path, model_id=model_id)
|
||||||
if config_info is not None:
|
if config_info is not None:
|
||||||
|
sampling_param_cls = config_info.sampling_param_cls
|
||||||
native_task_type = config_info.pipeline_config_cls.task_type
|
native_task_type = config_info.pipeline_config_cls.task_type
|
||||||
if native_task_type != DiffusersGenericPipelineConfig.task_type:
|
if native_task_type != DiffusersGenericPipelineConfig.task_type:
|
||||||
pipeline_config_cls = dataclasses.make_dataclass(
|
pipeline_config_cls = dataclasses.make_dataclass(
|
||||||
@@ -386,7 +388,7 @@ def _get_diffusers_model_info(
|
|||||||
|
|
||||||
return ModelInfo(
|
return ModelInfo(
|
||||||
pipeline_cls=DiffusersPipeline,
|
pipeline_cls=DiffusersPipeline,
|
||||||
sampling_param_cls=DiffusersGenericSamplingParams,
|
sampling_param_cls=sampling_param_cls,
|
||||||
pipeline_config_cls=pipeline_config_cls,
|
pipeline_config_cls=pipeline_config_cls,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ class DiffusersExecutionStage(PipelineStage):
|
|||||||
if batch.generator is not None:
|
if batch.generator is not None:
|
||||||
kwargs["generator"] = batch.generator
|
kwargs["generator"] = batch.generator
|
||||||
elif batch.seed is not None:
|
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)
|
kwargs["generator"] = torch.Generator(device=device).manual_seed(batch.seed)
|
||||||
|
|
||||||
# Image input for img2img or inpainting
|
# Image input for img2img or inpainting
|
||||||
@@ -307,15 +307,15 @@ class DiffusersExecutionStage(PipelineStage):
|
|||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def _get_pipeline_device(self) -> str:
|
def _get_generator_device(self, batch: Req) -> str:
|
||||||
"""Get the device the pipeline is running on."""
|
"""Resolve RNG device consistently with the non-diffusers path.
|
||||||
for attr in ["unet", "transformer", "vae"]:
|
|
||||||
component = getattr(self.diffusers_pipe, attr, None)
|
Diffusers CPU offload can temporarily park modules on CPU, but that
|
||||||
if component is not None:
|
should not silently switch a CUDA request to CPU RNG, otherwise the
|
||||||
try:
|
same seed produces different outputs depending on runtime placement.
|
||||||
return str(next(component.parameters()).device)
|
"""
|
||||||
except StopIteration:
|
if batch.generator_device == "cpu":
|
||||||
pass
|
return "cpu"
|
||||||
return current_platform.device_type
|
return current_platform.device_type
|
||||||
|
|
||||||
def _load_input_image(self, batch: Req) -> Image.Image | None:
|
def _load_input_image(self, batch: Req) -> Image.Image | None:
|
||||||
|
|||||||
Reference in New Issue
Block a user