Repository navigation
fix: preserve underscores in FLUX.3 LoRA tensor names - #2462
Conversation
Protect FLUX.3-specific module names during separator conversion to support Fizgig-exported LoRA weights. Complements leejet#2214.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…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.
|
Thank you for your contribution. |
…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.
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_blocksbecomescontent.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_blockstxt_mode_blocksimage_condattn_outmlp_inmlp_outThis 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
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
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
content_mode_blocks,txt_mode_blocks,image_cond,attn_out,mlp_in, ormlp_outnow retain their underscores during name conversion, preventing these identifiers from being altered.