[NPU][Diffusion] MiniMax-H3 RainFusion end_step tail fallback (#6037)
Signed-off-by: HAAZZZEEEE <wang-taicheng@qq.com>
This commit is contained in:
1 parent
a5b8c82788
commit
c50b7de167
8 files changed
+243
-14
No files matched your search
@@ -7,7 +7,7 @@ import os
|
||||
import random
|
||||
from collections.abc import Callable, Mapping
|
||||
from dataclasses import dataclass, field, fields
|
||||
from enum import Enum
|
||||
from enum import Enum, StrEnum
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import diffusers
|
||||
@@ -1675,6 +1675,20 @@ class AttnQuantSpec:
|
||||
BLOCK_SPARSE_BACKENDS = frozenset({"RAINFUSION_ATTN"})
|
||||
|
||||
|
||||
class RainFusionPrecision(StrEnum):
|
||||
"""Execution precision for block-sparse RainFusion (rf_v3) attention.
|
||||
|
||||
``bf16``: no quantization, pure BF16 sparse attention (official baseline).
|
||||
``fp8``: BSA FP8 path - Hadamard rotation then full FP8 block quantization
|
||||
of Q/K/V before the BSA kernel.
|
||||
``mix``: EagleQBSA mixed precision - Q/K per-block INT8 + V per-channel FP8.
|
||||
"""
|
||||
|
||||
BF16 = "bf16"
|
||||
FP8 = "fp8"
|
||||
MIX = "mix"
|
||||
|
||||
|
||||
@dataclass
|
||||
class BlockSparseSpec:
|
||||
"""User-facing controls shared by block-sparse attention backends.
|
||||
@@ -1683,10 +1697,13 @@ class BlockSparseSpec:
|
||||
``start_step`` keeps the first N denoise steps dense and ``skip_layers`` (an
|
||||
index selector such as "0-3,38") exempts individual DiT blocks. Those two are
|
||||
the accuracy knobs to trade back quality at a fixed ``sparsity``.
|
||||
``precision`` selects the kernel precision mode (see ``RainFusionPrecision``).
|
||||
"""
|
||||
|
||||
sparsity: float = 0.8
|
||||
start_step: int = 0
|
||||
end_step: int = 0
|
||||
precision: str = RainFusionPrecision.BF16.value
|
||||
skip_layers: str | list[int] | None = None
|
||||
skip_layer_indices: set[int] | None = field(default=None, repr=False)
|
||||
|
||||
@@ -1694,6 +1711,13 @@ class BlockSparseSpec:
|
||||
self.sparsity = _in_range(self.sparsity, "block_sparse.sparsity", 0.0, 1.0) or 0.0
|
||||
if self.start_step < 0:
|
||||
raise ValueError(f"block_sparse.start_step must be >= 0; got {self.start_step!r}.")
|
||||
if self.end_step < 0:
|
||||
raise ValueError(f"block_sparse.end_step must be >= 0; got {self.end_step!r}.")
|
||||
if self.precision not in {p.value for p in RainFusionPrecision}:
|
||||
raise ValueError(
|
||||
f"block_sparse.precision must be one of {sorted(p.value for p in RainFusionPrecision)}; "
|
||||
f"got {self.precision!r}."
|
||||
)
|
||||
self.skip_layer_indices = parse_kv_cache_skip_selector(self.skip_layers)
|
||||
|
||||
|
||||
@@ -1776,6 +1800,8 @@ class AttentionSpec:
|
||||
bs = self.block_sparse
|
||||
kw["sparsity"] = bs.sparsity
|
||||
kw["start_step"] = bs.start_step
|
||||
kw["end_step"] = bs.end_step
|
||||
kw["precision"] = bs.precision
|
||||
if bs.skip_layer_indices:
|
||||
kw["skip_layers"] = sorted(bs.skip_layer_indices)
|
||||
|
||||
|
||||
Reference in new issue
Block a user