someone-in-the-world's picture
Skip text_encoder CPU offload in fast mode; type mode as an enum
39867e3
Raw
History Blame Contribute Delete
1.13 kB
from enum import Enum
from dimensions import MAX_OUTPUT_DIM, MAX_OUTPUT_DIM_FAST
class Mode(str, Enum):
"""UI speed/quality presets. Behavior that depends on the mode lives here as a
property on the variant, rather than call sites branching on a raw mode string."""
FAST = "fast"
HIGH_DETAIL = "high_detail"
@classmethod
def from_value(cls, value) -> "Mode":
try:
return cls(value)
except ValueError:
return cls.HIGH_DETAIL
@property
def max_dim(self) -> int:
return MAX_OUTPUT_DIM_FAST if self is Mode.FAST else MAX_OUTPUT_DIM
@property
def offloads_text_encoder_before_decode(self) -> bool:
# Fast mode's small decode (<=768px) fits comfortably in the headroom already
# freed by the fp8-resident transformer, so evicting the ~15GB text encoder
# first — measured at ~9.7s on this Space's MIG slice — buys nothing there.
# High-detail's decode is up to ~8.5x more pixels (2048px), where that
# headroom margin is unverified, so it keeps the safety net.
return self is Mode.HIGH_DETAIL