Skip to content

Studio Ideogram 4: load musubi-tuner LoRAs (transformer. fused qkv and kohya keys) - #18082

Merged
danielhanchen merged 2 commits into
mainfrom
studio-ideogram4-lora-transformer-prefix
Nov 17, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-ideogram4-lora-transformer-prefix

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Ideogram 4 LoRAs saved by musubi-tuner did not load.

  • diffusers' converter only knows one prefix. It only strips diffusion_model. / conditional_transformer. before splitting the checkpoint's fused attention.qkv.
  • transformer. + fused-qkv files raised. convert_lora.py --target other --diffusers_prefix transformer writes transformer.layers.N.attention.qkv.lora_A/B, and loading that raised "state_dict should be empty".
  • musubi's default lora_unet_layers_N_attention_qkv keys loaded into no layer. The render then failed with "Adapter name(s) ... not in the list of present adapters".

For Ideogram 4, Studio now renames both spellings to the diffusion_model. layout first. It folds alpha, or the header's lora_alpha, into lora_B; diffusers' converter then splits the qkv as usual.

  • The rename only applies when the fused attention.qkv / attention.o names are present. Files in diffusers' own split layout, which share the feed_forward names, still load unchanged.
  • An Ideogram 4 file that loads into no layer is now refused with a clear error instead of failing later.

Layouts that already worked keep working: ai-toolkit, RulZ and AcademiaSD (diffusion_model. with fused qkv), and diffusers' training script (transformer. with split q/k/v).

Testing

CPU: test_diffusion_lora_ideogram4.py builds a tiny Ideogram4 pipeline.

  • All four layouts must give the same per-module deltas.
  • Also covered: metadata strength, and refusal of a file that loads into nothing.
  • Main fails the musubi kohya and transformer. fused cases, the metadata and refusal checks, and one test of the new helper. The ai-toolkit and diffusers-split cases pass on both, confirming the working formats are untouched.
  • LoRA suites on this branch: 893 passed.

GPU: RTX PRO 6000, ideogram-ai/ideogram-4-fp8 at bf16, 768x768, 20 steps. The same synthetic adapter was saved in three spellings, with the tensors verified identical.

  • Main: the diffusion_model. file renders 06960312; the transformer. and kohya files fail.
  • This branch: all three render 06960312, bit-identical.
  • Weight 0.5 gives a different image (69ce2d5e).
  • The plain render before and after is 21d078f9 on both.

Not covered: the adapters were synthetic files in each trainer's key format, not downloaded LoRAs. musubi LoKR keys are not handled; they fail with the new clear error.

…s under transformer. or kohya keys

diffusers' Ideogram 4 converter splits the fused attention.qkv only under the
diffusion_model. prefix: a transformer.-prefixed file with the checkpoint's own
names (musubi-tuner convert_lora.py --diffusers_prefix transformer) raised, and
musubi-tuner's lora_unet_ keys loaded into no layer without an error. Both are
renamed to the diffusion_model. layout first, with alpha or the header's
lora_alpha folded in, and an Ideogram 4 file that loads into no layer is refused.
@danielhanchen danielhanchen self-assigned this Nov 17, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T06:52:07.523643Z 32ecfa7 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: b0423a4600

ℹ️ 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 added a commit to Etherll/unsloth that referenced this pull request Nov 17, 2026
…source lint red since unslothai#18070) (unslothai#18086)

## Summary

`Source lint (Python + shell + YAML + JSON + safety nets)` fails on main
since unslothai#18070 (seen on the staging runs for unslothai#18080 and unslothai#18082, both on
`8c99caf36c`):

```
1 risky loader call site(s) not in the baseline:

  unsloth/models/rl.py:5481  [dynamic-import] import_module
```

unslothai#18070 finds TRL's `AsyncGRPOTrainer` at its 1.18 location as well as
the older experimental one, which needs a second
`importlib.import_module(name)` call site.
`scripts/lint_risky_loaders.py` flags every new dynamic import until
someone reviews it and records it in
`scripts/risky_loaders_baseline.json`, and that entry was not added.

## Review

`name` comes from a fixed tuple of two literal module names,
`trl.trainer.async_grpo_trainer` and
`trl.experimental.async_grpo.async_grpo_trainer`, and each is checked
with `importlib.util.find_spec` first. No user or remote input reaches
it. It is the same kind of site as the other TRL `import_module` entries
already recorded for `rl.py`.

## Change

One entry added to `scripts/risky_loaders_baseline.json`, written by
`python scripts/lint_risky_loaders.py --update` (which marks it `REVIEW
ME`), with the reason filled in. No other entry moves.

## Verification

In a clean `git archive` of main:

- `python scripts/lint_risky_loaders.py` exits 1 on main (the site
above) and exits 0 with this change (`ok: 118 risky loader call site(s),
all recorded`).
- `tests/security/test_lint_risky_loaders.py`: 46 passed.
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 17, 2026
…latest red on TRL 1.18) (unslothai#18088)

## Summary

`Core (HF=latest + TRL=latest)` fails on main now that CI installs TRL
1.18.0 (seen on the staging run for unslothai#18082, on `8c99caf36c`):

```
tests/_trl_trainer_discovery_shim.py::test_unsloth_patches_every_canonical_trainer_in_this_trl_version
AssertionError: unsloth.models.rl.patch_trl_rl_trainers did NOT patch: async_grpo_trainer:AsyncGRPOTrainer
```

TRL 1.18 moved `AsyncGRPOTrainer` into `trl.trainer.async_grpo_trainer`.
unslothai#18070 handles that on purpose: `patch_trl_rl_trainers` skips
`async_grpo_trainer`, and `patch_trl_async_grpo` patches the class in
place, because it needs TRL's own module globals
(`create_model_from_path`, the lm_head helpers). The class keeps its
name. The discovery shim in `consolidated-tests-ci.yml` counts a trainer
as patched only if its class name starts with `Unsloth`, and it did not
know about that exclusion.

unslothai#18070 is right. The shim did not follow it.

## Change

In the shim embedded in `.github/workflows/consolidated-tests-ci.yml`:

- `PATCHED_IN_PLACE = {"async_grpo_trainer"}` mirrors the exclusion in
`patch_trl_rl_trainers`, and the canonical-trainer test leaves those
modules out of its renamed-class check.
- New `test_trainers_patched_in_place_are_wrapped`: where TRL ships one
of those modules, it runs `patch_trl_async_grpo()` and checks that each
`*Trainer` class's `__init__` has a layer whose code is in
`unsloth/models/rl.py`, following the `__wrapped__` chain since other
Unsloth patches wrap on top. On TRL versions without the module it
skips. So the trainer is still checked, only in the way it is actually
patched.

## Verification

The shim extracted from the workflow and run locally:

- TRL 1.18.0: main's shim fails as in CI (`1 failed, 4 passed`); this
one passes (`6 passed`).
- TRL 1.18.0 with `patch_trl_async_grpo` made a no-op: the new test
fails (`__init__ has no layer from Unsloth's in-place patch ...:
[unsloth/trainer.py, trl/trainer/async_grpo_trainer.py]`).
- TRL 1.15.0: `5 passed, 1 skipped` (no
`trl.trainer.async_grpo_trainer`).
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…d since #18065) (#18091)

## Summary

`Repo tests (CPU, studio)` fails on main since #18065 (seen on the
staging run for #18082):

```
tests/python/test_accelerator_skip_guards.py::test_no_skip_guard_reads_a_spoofable_accelerator_probe
AssertionError: these skip guards read a probe tests/_zoo_aggressive_cuda_spoof.py patches to True process-wide ...
    test_forced_float32_grad_scaler.py:92: torch.cuda.is_available()
    test_forced_float32_grad_scaler.py:117: torch.cuda.is_bf16_supported()
    test_forced_float32_grad_scaler.py:190: torch.cuda.is_available()
```

#18065 added `tests/test_forced_float32_grad_scaler.py` with three GPU
tests guarded by `torch.cuda.is_available()`. The CUDA spoof used by the
zoo suite makes that probe return True for the whole pytest session, so
on a CPU runner these tests would un-skip and fail whenever they share a
session with it. The repo guard catches exactly that and asks for
`has_real_cuda()`.

The GradScaler change in #18065 is fine; only the new test's skip guards
miss the convention.

## Change

`tests/test_forced_float32_grad_scaler.py` gates its three GPU tests on
`has_real_cuda()` from `tests/_shared/real_accelerator.py`, as the other
GPU tests do. The bfloat16 case keeps `torch.cuda.is_bf16_supported()`
behind it (`has_real_cuda() and torch.cuda.is_bf16_supported()`), which
the guard accepts. On a real CUDA box the gates resolve the same as
before.

## Verification

- `tests/python/test_accelerator_skip_guards.py`: 1 failed on main (the
lines above), 24 passed with this change.
- `tests/test_forced_float32_grad_scaler.py` on a CPU host: 3 skipped,
with the same reasons as before.
danielhanchen added a commit to unslothai/unsloth-zoo that referenced this pull request Nov 17, 2026
…twise on CPU (Core zoo red since #2566) (#2568)

## Summary

Since #2566, unsloth's `Core zoo` jobs fail on one test (seen in both
`HF=4.57.6 + TRL<1` and `HF=latest + TRL=latest` on the staging run for
unslothai/unsloth#18082, zoo `04538fa3`):

```
tests/test_gemma4_packed_documents.py::test_equal_length_documents_share_one_call_and_the_kill_switch_restores_the_loop
    assert torch.equal(batched, loop)
E   assert False
```

#2566 runs equal-length packed documents through one SDPA call with a
batch of `n` instead of `n` batch-1 calls. The CPU tests then require
the two to match bit for bit. On the CI runners they do not: CPU SDPA
can split a batch of `n` across threads and blocks differently from `n`
separate calls, so the last bits differ. On this host the kill-switch
test fails 2 times in 5 with `OMP_NUM_THREADS=4
ATEN_CPU_CAPABILITY=avx2` (the runners' shape: 4 vCPUs, AVX2), and
passes every time with 1 or 2 threads or the AVX-512 kernels.

The batching in #2566 is right. Bitwise equality on CPU is a stronger
claim than the kernels promise.

## Change

- The two CPU comparisons
(`test_equal_length_documents_share_one_call_and_the_kill_switch_restores_the_loop`
and the parametrised
`test_equal_length_runs_match_the_loop_bit_for_bit`, renamed to
`test_equal_length_runs_match_the_loop`) use
`torch.testing.assert_close` instead of `torch.equal`, for outputs and
gradients. The call-count assertions stay exact.
- The CUDA float16 test keeps `torch.equal`: that is the measured claim
for the CUDA kernels.

## Verification

- `tests/test_gemma4_packed_documents.py`: 57 passed, 2 skipped (CUDA).
With `OMP_NUM_THREADS=4 ATEN_CPU_CAPABILITY=avx2`, the CPU cases pass 6
runs in 6.
- Sabotage: interleaving the documents in the batched path
(`unflatten(2, (L, n))` in place of `(n, L)`) fails both CPU tests (639
/ 720 elements mismatched in the kill-switch test), so the closeness
check still catches a wrong batch.
…-transformer-prefix

# Conflicts:
#	studio/backend/core/inference/diffusion_lora_files.py

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 32ecfa74b6

ℹ️ 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 37be408 into main Nov 17, 2026
@danielhanchen
danielhanchen deleted the studio-ideogram4-lora-transformer-prefix branch November 17, 2026 08:27
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