Skip to content

fix: preserve underscores in FLUX.3 LoRA tensor names - #2462

Merged
leejet merged 1 commit into
leejet:masterfrom
PanosPetrou:fix/flux3-lora-name-conversion
Nov 29, 2026
Merged

leejet merged 1 commit into
leejet:masterfrom
PanosPetrou:fix/flux3-lora-name-conversion

Conversation

@PanosPetrou

@PanosPetrou PanosPetrou commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Protect FLUX.3-specific module names during separator conversion to support Fizgig-exported LoRA weights.

Complements #2214.

Problem

FLUX.3 Image Klein LoRA weights exported by Fizgig are only partially applied because convert_sep_to_dot() replaces underscores that are part of valid FLUX.3 module names.

For example, content_mode_blocks becomes content.mode.blocks, preventing the corresponding LoRA tensors from matching their target model weights.

Solution

Extend the protected token list in convert_sep_to_dot() specifically for FLUX.3 models:

  • content_mode_blocks
  • txt_mode_blocks
  • image_cond
  • attn_out
  • mlp_in
  • mlp_out

This change is restricted to FLUX.3 and complements the Diffusers LoRA naming support introduced in #2214.

Validation

Performed a controlled A/B test using two independent builds of upstream commit 3d0df00, with and without this patch.

Both builds used identical model weights, LoRA weights, prompts, seeds, generation parameters and hardware.

Results

Generation mode Unpatched Patched
Text-to-image 252/774 684/774
With reference image 252/774 774/774

All four generation runs completed successfully and saved their output images.

The remaining 90 LoRA tensors in the patched text-to-image run appear to belong to the reference-image processing branch. All 774 tensors are applied when a reference image is provided.

Test configuration

  • Model: FLUX.3 Image Klein Q6_K GGUF
  • Text encoder: Qwen3VL-4B-Instruct Q4_K_M GGUF
  • VAE: FLUX.2
  • LoRA: Fizgig-trained, rank 32, alpha 32
  • LoRA weight: 1.0
  • Backend: CPU
  • Hardware: Dual Intel Xeon E5-2699 v4
  • Threads: 60
  • Resolution: 512 × 768
  • Sampler: Euler
  • Steps: 16
  • CFG scale: 1.0
  • Seed: 4242
  • Build configuration: Release

The fix was also successfully tested in a local image-generation pipeline.

Scope

One source file, six added lines. No dependency updates, model weight modifications or unrelated changes.

Summary by CodeRabbit

  • Bug Fixes
    • Flux3 tensor names containing content_mode_blocks, txt_mode_blocks, image_cond, attn_out, mlp_in, or mlp_out now retain their underscores during name conversion, preventing these identifiers from being altered.

Protect FLUX.3-specific module names during separator conversion to support Fizgig-exported LoRA weights.

Complements leejet#2214.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

For Flux3, convert_sep_to_dot now protects six additional tokens from underscore-to-period conversion.

Changes: Flux3 name conversion

Layer / File(s) Summary
Protect Flux3 tokens
src/name_conversion.cpp
When the version is Flux3, convert_sep_to_dot adds content_mode_blocks, txt_mode_blocks, image_cond, attn_out, mlp_in, and mlp_out to the protected-token list.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: leejet, stduhpf

Merge Risk: Minimal · up to 5f7ba

This change keeps FLUX.3 LoRA tensor names such as content_mode_blocks from being rewritten, so more LoRA weights are applied. It affects only the FLUX.3 path, and no merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: preserving underscores in FLUX.3 LoRA tensor names during separator conversion. The raw summary confirms that convert_sep_to_dot now protects FLUX.3-specific tokens fr…
Description check Passed The description follows the repository template. It has a Summary section that explains the problem, the fix, and the validation, with a clear A/B test and a scope statement. The Related Issue / Discu…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: preserving underscores in FLUX.3 LoRA tensor names during separator conversion. The raw summary confirms that convert_sep_to_dot now protects FLUX.3-specific tokens from underscore-to-period replacement. The title is specific and concise, and it matches the changeset.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary section that explains the problem, the fix, and the validation, with a clear A/B test and a scope statement. The Related Issue / Discussion section is not filled in, though the description mentions #2214 in prose. The Additional Information content is covered by the validation section. The Checklist section is missing, including the contribution guidelines confirmation and the model documentation confirmation.

Resolution

Consider adding the Related Issue / Discussion link explicitly (for example, a link to #2214), and complete the Checklist section from the template, including the contribution guidelines confirmation and the model documentation item. The model documentation item applies because the change affects FLUX.3 model support.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0cfa7072-df8d-4918-b652-0199fe12dc82
Commits

Reviewing files that changed from the base of the PR and between 3d0df00 and 5f7baf4.

Files selected for processing: 1

  • src/name_conversion.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

danielhanchen added a commit to unslothai/stable-diffusion.cpp that referenced this pull request Nov 29, 2026
…underscore-style tensor names (#107)

convert_sep_to_dot turned content_mode_blocks, txt_mode_blocks, image_cond,
attn_out, mlp_in and mlp_out into dotted paths, so kohya-style FLUX.3 LoRAs
(lora_unet_*) only matched the single_blocks q/k/v projections (252 of 774
tensors). Protect these tokens for FLUX.3 only. Port of upstream
leejet#2462.
@leejet
leejet merged commit 7cf6887 into leejet:master Nov 29, 2026
2 checks passed
@leejet

leejet commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Thank you for your contribution.

danielhanchen added a commit to unslothai/unsloth that referenced this pull request Nov 29, 2026
…tyle LoRA names) (#20326)

## Summary

Moves the Studio sd.cpp prebuilt pin from `master-982-0518b34-ub6ed0ee`
to `master-982-0518b34-u9213d05` (unslothai/stable-diffusion.cpp at
`9213d05c37`).

The new build adds one change on top of the previous pin:
unslothai/stable-diffusion.cpp#107, a port of
leejet/stable-diffusion.cpp#2462. Underscore-style FLUX.3 LoRAs
(kohya-style `lora_unet_*` keys) were mostly ignored, because
`convert_sep_to_dot` turned `content_mode_blocks`, `txt_mode_blocks`,
`image_cond`, `attn_out`, `mlp_in` and `mlp_out` into dotted paths that
match no model tensor. Only the `single_blocks` q/k/v projections were
applied. #107 keeps those six tokens intact, for FLUX.3 only. The range
`b6ed0ee40b..9213d05c37` is that one commit, 6 added lines in
`src/name_conversion.cpp`.

- `install_sd_cpp_prebuilt.py`: `DEFAULT_TAG` and
`PINNED_RELEASE_ASSETS` move to the new tag, with all 22 assets and
their sha256.
- `sd_cpp_args.py`: the new tag joins `METAL_IMPLICIT_GEMM_CONV_TAGS`
and `VULKAN_PAGEABLE_OFFLOAD_TAGS`. `9213d05c37` descends from
`b6ed0ee40b` and `6bc0f393c9`, so it still carries #103 (implicit GEMM
Metal CONV_2D) and #106 (Vulkan offload in pageable RAM). Without this
change both features would turn off on fresh installs.
- No Studio gate depends on the FLUX.3 LoRA name mapping, so nothing
else is tag-gated.

## Evidence

- Release check: the release is published, not a draft, and has 22
assets. The shipped digests come from the release's
`sd-prebuilt-sha256.json`. The two JSON files were hashed after
download. All 22 match the digests the GitHub releases API reports. The
CUDA coverage rows in `sd-prebuilt-manifest.json` are the same 12 rows
as the previous pin, so `test_sd_cpp_pinned_prebuilt.py` needed no
change.
- Linux x86_64 CPU zip, old pin vs new pin: `sd-cli`, `sd-server`,
`libggml.so.0`, `libggml-base.so.0` and all 14 `libggml-cpu-*.so`
variants are byte-identical. Only `libstable-diffusion.so` differs
(42,997,240 vs 42,997,376 bytes), plus the build stamp in
`UNSLOTH_BUILD.txt`.
- CPU render, old pin vs new pin, using the released Linux x86_64 CPU
zips on a Colab CPU runtime (Intel Xeon @ 2.20GHz, 8 vCPU, ggml loads
`libggml-cpu-haswell.so`). The flags match Studio's: `--flash-attn
off,diffusion=on,te=auto`, seed 42, `--rng cpu`, 8 threads. Each case
ran 4 times in A B B A order:

| Case | Old pin | New pin | Result |
| --- | --- | --- | --- |
| FLUX.2 klein 4B Q4_K_M, Qwen3-4B Q4_K_M, 256x256, 2 steps, cfg 1 | 2
runs, 1 hash | 2 runs, 1 hash | byte-identical |
| Z-Image-Turbo Q4_K_M, Qwen3-4B Q4_K_M, 256x256, 4 steps, cfg 1,
5-token caption | 2 runs, 1 hash | 2 runs, 1 hash | byte-identical |
| Wan2.2 TI2V-5B Q4_K_M, umt5-xxl Q8_0, 128x128, 5 frames, 2 steps, cfg
5 | 2 runs, 1 hash (5 frames) | 2 runs, 1 hash (5 frames) |
byte-identical |

The Z-Image case uses a short caption (13 tokens with the chat template)
so that the one-chunk flash attention path, which changed in the
previous pin, is covered.

- FLUX.3 LoRA: no small underscore-style FLUX.3 LoRA is published under
unsloth/, so no LoRA was loaded here. The fork PR's test runs synthetic
FLUX.3 LoRA name lists for all 43 blocks and all 6 linears through
`convert_tensor_name`. Underscore-style names go from 252 of 774 matched
to 774 of 774. PEFT and diffusers-style names stay at 516 of 516. Name
conversion under every non-FLUX.3 version gives byte-identical output
before and after (47,702 conversions).

## Tests

- Pin references moved in `test_diffusion_more_families.py`,
`test_sd_cpp_args.py` (`ub6ed0ee` kept as the previous pin),
`test_sd_cpp_cuda_cpu_torch.py`, `test_sd_cpp_vulkan_cpu_torch.py`,
`test_sd_cpp_metal_vae_conv_default.py`,
`test_sd_cpp_metal_vae_conv_direct.py` and
`test_h3_native_pageable_offload.py`. The last one now also checks that
`ub6ed0ee` stays pageable.
- sd.cpp, installer and H3 native suites (74 files): 3539 passed, 7
skipped on this branch, against 3538 passed, 7 skipped on main. No
failures on either side. The extra case is the new previous-pin row in
`test_sd_cpp_args.py`.
- With only the installer pin moved and `sd_cpp_args.py` left as on
main, `test_sd_cpp_pinned_prebuilt.py` fails 3 of 42 (the two allowlist
cases and the gated-features case). So the allowlist check catches a pin
bump that misses `sd_cpp_args.py`.

## Not covered

- No GPU render. CUDA, Vulkan and Metal binaries were not run. The
source change is limited to LoRA name conversion, and in the Linux CPU
zip every ggml library is byte-identical.
- No underscore-style FLUX.3 LoRA was loaded end to end on either pin.
The 774 of 774 result comes from the fork PR's name-mapping test.
- The CPU renders ran on one AVX2 variant (haswell). The AVX-512 and AMX
variants are byte-identical libraries, but they were not rendered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants