Skip to content

FLUX.3 LoRA: keep underscores in FLUX.3 module names for underscore-style LoRAs - #107

Merged
danielhanchen merged 1 commit into
masterfrom
flux3-lora-underscore-tokens
Nov 29, 2026
Merged

danielhanchen merged 1 commit into
masterfrom
flux3-lora-underscore-tokens

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Underscore-style FLUX.3 LoRAs (kohya-style lora_unet_* keys) were mostly ignored. convert_sep_to_dot turns every unprotected underscore into a dot, so content_mode_blocks, txt_mode_blocks, image_cond, attn_out, mlp_in and mlp_out became dotted paths that match no model tensor. Only the single_blocks q/k/v projections survived.

This protects those six tokens, for FLUX.3 only (sd_version_is_flux3). Port of upstream leejet#2462 (MIT), same six lines.

Test: synthetic FLUX.3 LoRA name lists covering all 43 blocks (image x5, image_cond x5, txt x5, single x28) and all 6 linears, run through convert_tensor_name and counted against the real FLUX.3 tensor names, base vs head:

List Before After
Underscore style (lora_unet_*, down/up/alpha) 252/774 774/774
PEFT native (diffusion_model.*) 516/516 516/516
Diffusers style (transformer.*) 516/516 516/516

The same names plus FLUX/SDXL/text encoder probes, converted under every non-FLUX.3 version, give byte-identical output before and after (47,702 conversions).

Built sd-cli on CPU (Release, GGML_NATIVE=OFF).

…underscore-style tensor names

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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T14:17:17.516667Z a50ceaa Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: a50ceaad31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 9213d05 into master Nov 29, 2026
Debug-Fate pushed a commit to Debug-Fate/unsloth that referenced this pull request Nov 29, 2026
…tyle LoRA names) (unslothai#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. unslothai#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 unslothai#103 (implicit GEMM
Metal CONV_2D) and unslothai#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.

1 participant