[diffusion] refactor: remove enums and unify attention backends (#19149)
This commit is contained in:
committed by
GitHub
parent
ea1bc1c578
commit
1efc33c640
@@ -50,10 +50,6 @@ class DiffusersGenericPipelineConfig(PipelineConfig):
|
||||
vae_slicing: bool = False # slice VAE decode for lower memory usage
|
||||
vae_sp: bool = False
|
||||
|
||||
# Attention backend for diffusers models (e.g., "flash", "_flash_3_hub", "sage", "xformers")
|
||||
# See: https://huggingface.co/docs/diffusers/main/en/optimization/attention_backends
|
||||
diffusers_attention_backend: str | None = None
|
||||
|
||||
# Quantization config for pipeline-level quantization
|
||||
# See: https://huggingface.co/docs/diffusers/main/en/quantization/overview
|
||||
# Use PipelineQuantizationConfig for component-level control:
|
||||
|
||||
@@ -490,11 +490,6 @@ class DiffusersPipeline(ComposedPipelineBase):
|
||||
"""
|
||||
backend = server_args.attention_backend
|
||||
|
||||
if backend is None:
|
||||
config = server_args.pipeline_config
|
||||
if config is not None:
|
||||
backend = getattr(config, "diffusers_attention_backend", None)
|
||||
|
||||
if backend is None:
|
||||
return
|
||||
|
||||
|
||||
@@ -152,59 +152,6 @@ def _sanitize_for_logging(obj: Any, key_hint: str | None = None) -> Any:
|
||||
return "<unserializable>"
|
||||
|
||||
|
||||
class ExecutionMode(str, Enum):
|
||||
"""
|
||||
Enumeration for different pipeline modes.
|
||||
|
||||
Inherits from str to allow string comparison for backward compatibility.
|
||||
"""
|
||||
|
||||
INFERENCE = "inference"
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, value: str) -> "ExecutionMode":
|
||||
"""Convert string to ExecutionMode enum."""
|
||||
try:
|
||||
return cls(value.lower())
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
f"Invalid mode: {value}. Must be one of: {', '.join([m.value for m in cls])}"
|
||||
) from None
|
||||
|
||||
@classmethod
|
||||
def choices(cls) -> list[str]:
|
||||
"""Get all available choices as strings for argparse."""
|
||||
return [mode.value for mode in cls]
|
||||
|
||||
|
||||
class WorkloadType(str, Enum):
|
||||
"""
|
||||
Enumeration for different workload types.
|
||||
|
||||
Inherits from str to allow string comparison for backward compatibility.
|
||||
"""
|
||||
|
||||
I2V = "i2v" # Image to Video
|
||||
T2V = "t2v" # Text to Video
|
||||
T2I = "t2i" # Text to Image
|
||||
I2I = "i2i" # Image to Image
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, value: str) -> "WorkloadType":
|
||||
"""Convert string to WorkloadType enum."""
|
||||
try:
|
||||
return cls(value.lower())
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
f"Invalid workload type: {value}. Must be one of: {', '.join([m.value for m in cls])}"
|
||||
) from None
|
||||
|
||||
@classmethod
|
||||
def choices(cls) -> list[str]:
|
||||
"""Get all available choices as strings for argparse."""
|
||||
return [workload.value for workload in cls]
|
||||
|
||||
|
||||
class Backend(str, Enum):
|
||||
"""
|
||||
Enumeration for different model backends.
|
||||
@@ -648,13 +595,6 @@ class ServerArgs:
|
||||
default=None,
|
||||
help="Configuration for the attention backend. Can be a JSON string, a path to a JSON/YAML file, or key=value pairs.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--diffusers-attention-backend",
|
||||
type=str,
|
||||
dest="attention_backend",
|
||||
default=None,
|
||||
help=argparse.SUPPRESS,
|
||||
)
|
||||
parser.add_argument(
|
||||
"--cache-dit-config",
|
||||
type=str,
|
||||
@@ -1070,12 +1010,6 @@ class ServerArgs:
|
||||
|
||||
@classmethod
|
||||
def from_kwargs(cls, **kwargs: Any) -> "ServerArgs":
|
||||
# Convert mode string to enum if necessary
|
||||
if "mode" in kwargs and isinstance(kwargs["mode"], str):
|
||||
kwargs["mode"] = ExecutionMode.from_string(kwargs["mode"])
|
||||
# Convert workload_type string to enum if necessary
|
||||
if "workload_type" in kwargs and isinstance(kwargs["workload_type"], str):
|
||||
kwargs["workload_type"] = WorkloadType.from_string(kwargs["workload_type"])
|
||||
# Convert backend string to enum if necessary
|
||||
if "backend" in kwargs and isinstance(kwargs["backend"], str):
|
||||
kwargs["backend"] = Backend.from_string(kwargs["backend"])
|
||||
|
||||
Reference in New Issue
Block a user