File size: 1,134 Bytes
39867e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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