Skip to content

[Fix] diffusion/lora: revalidate FLUX.2 FP8/NVFP4 fast paths after LoRA attach - #40171

Merged
mickqian merged 3 commits into
sgl-project:mainfrom
heiculi98:fix/flux2-fp8-lora-fast-path
Oct 17, 2026
Merged

mickqian merged 3 commits into
sgl-project:mainfrom
heiculi98:fix/flux2-fp8-lora-fast-path

Conversation

@heiculi98

@heiculi98 heiculi98 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Fix a crash when attaching a LoRA adapter at runtime to a FLUX.2 (multimodal_gen) model loaded from an FP8-quantized checkpoint (ModelOpt FP8).

Motivation

Flux2ParallelSelfAttention.__init__ decides the fused fast-path flags
_enable_fp8_token_cat / _enable_nvfp4_token_cat by inspecting
self.to_out.quant_method on the raw quantized RowParallelLinear. When a
LoRA adapter is attached, the LoRA pipeline replaces those quantized linears
with wrapper modules that do not expose quant_method / input_scale. The
init-time flags then go stale, and forward() reads those attributes off the
wrapper, crashing instead of falling back to the unfused path.

Reproduced on an L20 GPU (SM89) with the official FLUX.2-klein-9b-fp8
checkpoint and a runtime-attached LoRA adapter (locally trained, cannot be
shared): the model crashes on the first forward pass after the adapter is
mounted.

Related: #35970 (diffusion LoRA + FP8 crash on static merge) — the merge-policy
half is handled by the can_merge_base_weight dynamic fallback; this PR fixes
the stale fast-path flags on the dynamic path.

Modifications

attributes, the fusion is simply disabled.

  • Add Flux2Transformer2DModel.revalidate_fp8_fast_paths() which also re-runs
    configure_fp8_norm_quant() per block.
  • Call the hook from LoRAPipeline after the wrappers are installed (for
    modules that expose it, e.g. transformer / transformer_2).

No behavior change when no LoRA is attached — the revalidation hook only runs
after LoRA wrappers are installed.

Accuracy Tests

End-to-end A/B on a single L20 GPU (SM89) with the official
FLUX.2-klein-9b-fp8 checkpoint and a runtime-attached LoRA adapter (locally
trained, cannot be shared), built on this PR branch (latest main):

  • Without the patch: non-LoRA generation succeeds; after POST /v1/set_lora
    (merge_mode=dynamic), the first LoRA generation fails immediately with
    AttributeError: 'ColumnParallelLinearWithLoRA' object has no attribute 'input_scale' inside Flux2Transformer2DModel.forward.
  • With the patch: the same request completes normally and produces valid
    1024x1024 output; no errors in the server log.
  • Non-LoRA inference is untouched: same prompt/seed before and after the
    patch yields bit-identical output images.
  • ruff / ruff-format / isort pass per pre-commit rules.

Speed Tests and Profiling

N/A — this change only disables fused fast paths that would otherwise crash
under LoRA; it does not affect the non-LoRA serving path.


CI States

Latest PR Test (Base): ✅ Run #39017061749
Latest PR Test (Extra): ❌ Run #39017061730
Latest PR Test (AMD ROCm 10): ❌ Run #39017061718

…tach

LoRA wrapping replaces quantized linears with wrappers that do not expose
quant_method/input_scale. The _enable_fp8_token_cat/_enable_nvfp4_token_cat
flags decided in Flux2ParallelSelfAttention.__init__ against the raw modules
then go stale, and forward() reads those attributes off the wrapper and
crashes.

Add revalidate_fp8_fast_paths() on Flux2ParallelSelfAttention and
Flux2Transformer2DModel, and call it from LoRAPipeline after wrappers are
installed so each DiT rechecks fusion eligibility (getattr-safe) and
disables the fused path instead of crashing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@heiculi98

Copy link
Copy Markdown
Contributor Author

Hi maintainers — this is a small bugfix for the FLUX.2 runtime LoRA + FP8 crash, verified end-to-end on an L20 GPU (A/B results in the description: crash without the patch, clean generation with it). Since CI is gated on the run-ci label, could someone with permission help trigger it? Happy to address any feedback.

@mickqian

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 14, 2026
detain pushed a commit to detain/sglang that referenced this pull request Oct 15, 2026
…t paths after LoRA attach [batch-apply-b 2026-10-14]

Cherry-pick -x of cdaa999 (single commit). PR base 9784d5f pre-dates
merges sgl-project#3/sgl-project#4 (both files drifted +394/-72) yet 3way auto-merged: hunks are
pure additions with unchanged context (post-__init__ slot in
Flux2ParallelSelfAttention, tail of convert_to_lora_layers after critic
conversion). Manually verified landing spots: required symbols
(ModelOptFp{8,4}LinearMethod imports, configure_fp8_norm_quant) exist;
only return in enclosing method is the lora_initialized guard so the
revalidate loop is reachable. Composition with sgl-project#43793 (42e43cf, in
merge sgl-project#4): disjoint files (group_coordinator/layer.py vs
flux_2/lora-pipeline), both concerns live — sgl-project#43793 non-contiguous K/V
gather fix retained at layer.py:488-491.
@github-actions

This comment has been minimized.

@mickqian mickqian changed the title [diffusion] lora: revalidate FLUX.2 FP8/NVFP4 fast paths after LoRA attach [Fix] diffusion/lora: revalidate FLUX.2 FP8/NVFP4 fast paths after LoRA attach Oct 17, 2026
@mickqian
mickqian merged commit b15a78a into sgl-project:main Oct 17, 2026
136 of 150 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants