[Fix] diffusion/lora: revalidate FLUX.2 FP8/NVFP4 fast paths after LoRA attach (#40171)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
@@ -962,6 +962,28 @@ class Flux2ParallelSelfAttention(torch.nn.Module, AttentionModuleMixin):
|
||||
supported_attention_backends=supported_attention_backends,
|
||||
)
|
||||
|
||||
def revalidate_fp8_fast_paths(self) -> None:
|
||||
"""Recompute fused FP8/NVFP4 fast-path eligibility after submodule changes.
|
||||
|
||||
LoRA wrapping replaces quantized linears with wrappers that do not
|
||||
expose ``quant_method``/``input_scale``; flags decided at ``__init__``
|
||||
against the raw modules then go stale and ``forward`` would read those
|
||||
attributes off the wrapper and crash. Read them defensively here so a
|
||||
recheck after wrapping disables the fusion instead.
|
||||
"""
|
||||
self._enable_fp8_token_cat = self.tp_size == 1 and isinstance(
|
||||
getattr(self.to_out, "quant_method", None), ModelOptFp8LinearMethod
|
||||
)
|
||||
capability = current_platform.get_device_capability()
|
||||
self._enable_nvfp4_token_cat = (
|
||||
self.tp_size == 1
|
||||
and capability is not None
|
||||
and (capability.major, capability.minor) == (10, 3)
|
||||
and isinstance(
|
||||
getattr(self.to_out, "quant_method", None), ModelOptFp4LinearMethod
|
||||
)
|
||||
)
|
||||
|
||||
def _patch_to_out_weight_loader(self) -> None:
|
||||
inner_dim, mlp_dim = self.inner_dim, self.mlp_hidden_dim
|
||||
tp_size, tp_rank = self.tp_size, self.to_out.tp_rank
|
||||
@@ -1553,6 +1575,18 @@ class Flux2Transformer2DModel(CachableDiT, LayerwiseOffloadableModuleMixin):
|
||||
total,
|
||||
)
|
||||
|
||||
def revalidate_fp8_fast_paths(self) -> None:
|
||||
"""Recheck FP8 fast paths after LoRA (or other) submodule replacement.
|
||||
|
||||
``configure_fp8_norm_quant`` is getattr-safe, so a wrapper that hides
|
||||
the quant attributes simply turns each flag off.
|
||||
"""
|
||||
for block in self.transformer_blocks:
|
||||
block.configure_fp8_norm_quant()
|
||||
for block in self.single_transformer_blocks:
|
||||
block.configure_fp8_norm_quant()
|
||||
block.attn.revalidate_fp8_fast_paths()
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: FluxConfig,
|
||||
|
||||
@@ -563,6 +563,15 @@ class LoRAPipeline(ComposedPipelineBase):
|
||||
converted_count_critic,
|
||||
)
|
||||
|
||||
# The wrappers replaced quantized linears; FP8 fused fast paths decided
|
||||
# against the raw modules are stale and would read quant attributes
|
||||
# (input_scale/quant_method) off the wrappers. Let each DiT recheck.
|
||||
for module_name in ("transformer", "transformer_2"):
|
||||
module = self.modules.get(module_name)
|
||||
revalidate = getattr(module, "revalidate_fp8_fast_paths", None)
|
||||
if callable(revalidate):
|
||||
revalidate()
|
||||
|
||||
def _normalize_lora_params(
|
||||
self,
|
||||
lora_nickname: str | list[str],
|
||||
|
||||
Reference in New Issue
Block a user