Skip to content

Studio: train and chat with every text-diffusion LM family - #13342

Merged
danielhanchen merged 23 commits into
mainfrom
diffusion-studio-training
Oct 13, 2026
Merged

danielhanchen merged 23 commits into
mainfrom
diffusion-studio-training

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Studio can now train and chat with every text-diffusion family Unsloth Core supports: LLaDA, LLaDA-MoE, Dream, Nemotron-Labs-Diffusion, LLaDA2, SDAR and DiffusionGemma. Picking one of these models on the training page now runs the family's denoising objective via DiffusionTrainer, instead of failing or silently training it as an autoregressive model. Needs #13341 (Core dispatch and samplers); without it Studio says which Unsloth update is required.

What changes

Training

  • Detection is torch-free, from the model config (utils/models/diffusion_lm.py), and also resolves local checkpoints and Hub adapters back to their base. After load, the loaded model's profile is re-checked, so a model is never trained as autoregressive by mistake.
  • Loading goes through FastModel. LoRA's default "all linear" choice maps to the family's own target modules. DoRA and LoftQ fail with a clear message instead of being ignored.
  • The text path builds DiffusionTrainer / DiffusionConfig from the same arguments and keeps the chosen context length. Packing is turned off for diffusion runs. CPT supervises every token.
  • Dream and SDAR train at 5e-5 when the learning rate is left at Studio's 2e-4 default (any other value is kept, and the log says so). Their output-head rows for <|im_end|>, <tool_call>, <|fim_pad|> and the other special tokens are near-duplicates (cosine 0.97), so at 2e-4 a LoRA run swaps them: replies ended in <tool_call> or came back empty. At 5e-5 both answer cleanly; the other families are fine at 2e-4.
  • When the tokenizer is a remote-code class that cannot be pickled for dataset workers, Studio tokenizes and formats in one process. This was Dream: cannot pickle 'SSLContext' object.
  • The six remote-code families use the 5.5 transformers sidecar. Nemotron's code needs check_model_inputs, which 5.3 does not have.
  • DiffusionGemma, which needs a newer transformers than any sidecar ships, now gets the existing "install latest transformers" prompt.

Chat

  • Diffusion models and adapters load through FastModel. Replies come from the family's denoising sampler as one completion, held under the generation lock, with Stop cancelling it.

Export

  • GGUF is unavailable for all diffusion families (llama.cpp has no runtime for them). Merged 16-bit export is unavailable because Core has no merged save for these models yet.
  • The export page shows these methods as disabled with the reason. The backend refuses them before any conversion work.
  • Saving the LoRA adapter and pushing it to the Hub work as before.

Hub

  • Text-diffusion models no longer get the image / video generation badge.

Testing

End to end through the Studio HTTP API on a fresh install (install.sh --local). For each family: remote-code scan and approval, /api/train/start, poll to completion, adapter on disk, /api/inference/load of the adapter, then /v1/chat/completions. The server log must say the diffusion sampler answered.

Family Checkpoint transformers Train (3 steps) Losses Adapter Chat via diffusion sampler
LLaDA random-init copy of GSAI-ML/LLaDA-8B-Instruct 5.5 sidecar completed 9.44, 17.56, 4.53 yes yes
LLaDA-MoE random-init copy of inclusionAI/LLaDA-MoE-7B-A1B-Instruct 5.5 sidecar completed 11.59, 9.12, 6.16 yes yes
Dream random-init copy of Dream-org/Dream-v0-Instruct-7B 5.5 sidecar completed 20.92, 33.17, 32.59 yes yes
Nemotron-Labs-Diffusion random-init copy of nvidia/Nemotron-Labs-Diffusion-3B 5.5 sidecar completed 18.55, 30.65, 32.63 yes yes
LLaDA2 random-init copy of inclusionAI/LLaDA2.0-mini 5.5 sidecar completed 12.10, 12.01, 11.99 yes yes
SDAR random-init copy of JetLM/SDAR-1.7B-Chat 5.5 sidecar completed 7.59, 19.91, 6.90 yes yes
DiffusionGemma trl-internal-testing/tiny-DiffusionGemmaForBlockDiffusion latest sidecar (5.19.0, via the upgrade prompt) completed 24.94, 24.85, 24.82 yes yes

Tiny checkpoints are random weights, so the chat text itself is noise; the check is that the request is answered by the family's sampler.

Then the real checkpoints, 30 LoRA steps each at Studio's defaults, chat "Question 3: what is 3 plus 3?" (greedy; needs the companion PR's weight-loading and end-of-turn fixes):

Family Chat answer
LLaDA-8B-Instruct The answer is 6.
LLaDA-MoE-7B-A1B-Instruct 3 plus 3 is 6.
Dream-v0-Instruct-7B The answer is 6.
Nemotron-Labs-Diffusion-3B The answer is 6.
LLaDA2.0-mini The answer is 6.
SDAR-1.7B-Chat The answer is 6.
diffusiongemma-26B-A4B-it The answer is 6.
  • tests/test_diffusion_lm_studio.py: 72 tests covering detection, LoRA targets, trainer choice, packing, the Dream / SDAR learning-rate default, export refusals, chat dispatch and the pickling fallback.
  • Related suites (transformers tiers, chat templates and datasets, export, training) pass. Frontend: text-diffusion-lm-capabilities.test.ts; the build passes.
  • Autoregressive models take the same code path as before. Every new branch is gated on the diffusion profile, or on a remote-code tokenizer that fails to pickle.

Export page, before and after

The same LLaDA LoRA training run (trained in Studio) is selected on both sides. Before, GGUF and Merged can be picked: there is no merged save for these models yet, and Studio would serve a GGUF through llama-server as an ordinary left-to-right model. After, both are disabled with the reason on hover, and LoRA Only remains.

Export page before and after

@danielhanchen danielhanchen self-assigned this Oct 12, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-13T17:17:31.167572Z 0225be2 New commits
ℹ️ 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d16a16101

ℹ️ 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".

Comment on lines +1467 to +1471
temperature = temperature,
max_new_tokens = max_new_tokens,
cancel_event = cancel_event,
_adapter_state = _adapter_state,
stop = stop,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not silently discard diffusion sampling controls

When a diffusion chat request supplies non-default top_p, top_k, min_p, repetition_penalty, or presence_penalty, this early branch forwards only temperature and the token limit; the raw-prompt diffusion branch does the same. The API accepts those controls but they have no effect on the generated result, which makes client-side sampling configurations misleading. Forward the controls supported by the family sampler, or explicitly reject/disable unsupported settings.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The family samplers decode by confidence remasking, which has no top-p / top-k / min-p / penalty analogue. The chat UI sends those fields on every request, so rejecting them would break diffusion chat for everyone; they are ignored like other unsupported fields.

…mbedding learning rate, refuse MLX training of text-diffusion models
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b415b88ca1

ℹ️ 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".

Comment on lines +1464 to +1466
yield from self._generate_diffusion_lm(
model_info,
messages = _without_image_parts(template_messages),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include tool schemas in diffusion chat prompts

When tools are enabled, this early diffusion branch forwards only the conversation messages to the family sampler and bypasses the normal renderer below that supplies tools to apply_chat_template. The agentic loop still expects a tool call, but the model is never shown the available tool names or argument schemas, so diffusion-model tool turns generally produce ordinary text or exhaust the loop. Render the prompt with the same tool-aware template path before invoking the sampler, or explicitly disable tool mode for these models.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diffusion LMs are not trained for tool calling and the family samplers decode one completion by remasking, with no tool-call parser behind them. When no tool call comes back the agentic loop returns the text as the final answer, so nothing is lost; rendering tool schemas would only add prompt text these models do not use.

…les, refuse MLX chat for text-diffusion models, turn layer offloading off before the VRAM budget
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f49fa175fd

ℹ️ 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".

candidate
for candidate in candidates
if candidate not in hardcoded
if not _hardcoded_tier_ships(candidate)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Check the aliased DiffusionGemma type for upgrades

For a legacy DiffusionGemma checkpoint whose model_type is diffusion_gemma, this now correctly notices that the installed 5.5 sidecar lacks the type, but it then queries latest-transformers support using that same legacy name. Current Transformers registers the implementation as diffusion_gemma4—the core loader explicitly rewrites the legacy type to that name—so latest_transformers_supports("diffusion_gemma") reports unsupported and the validation path never offers the required latest-transformers install. The worker subsequently selects the hardcoded 5.5 tier and fails when the loader imports DiffusionGemma4Config; normalize this legacy candidate before checking the latest mappings.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transformers registers this model as diffusion_gemma (plus diffusion_gemma_text), not diffusion_gemma4: CONFIG_MAPPING_NAMES in both 5.17.0 and 5.19.0 lists only those, and latest_transformers_supports('diffusion_gemma') returns supported_in_pypi=True for 5.19.0 while 'diffusion_gemma4' returns False. Normalising to diffusion_gemma4 would break the prompt.

…rs, refuse an autoregressive load in diffusion chat, resolve Hub LoRA bases before the MLX refusal, keep the denied-credential sentinel in detection
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…be export limits with the caller's credential
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ar exists, classify a Hub LoRA by its base before the vision loader
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48789ad7e6

ℹ️ 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".

Comment on lines +1640 to +1641
if use_rslora:
peft_kwargs["use_rslora"] = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor rsLoRA in diffusion adapter setup

When a text-diffusion run enables rsLoRA, this forwards use_rslora=True, but the dispatched FastDiffusionModel.get_peft_model in unsloth/models/diffusion.py filters extra kwargs to only modules_to_save and init_lora_weights, so PEFT receives an ordinary LoraConfig and the experiment silently uses standard LoRA scaling. Either pass use_rslora through to LoraConfig or reject it alongside DoRA and LoftQ so the recorded configuration matches the training algorithm.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR depends on #13341 (stated at the top of the description; merge #13341 first), which passes use_rslora into LoraConfig in FastDiffusionModel.get_peft_model, with a test asserting config.use_rslora.

Comment on lines +2407 to +2411
generate_text = getattr(require_diffusion_api("FastDiffusionModel"), "generate_text", None)
if generate_text is None:
raise RuntimeError(
"Unsloth: chatting with a text-diffusion model needs a newer Unsloth "
"(FastDiffusionModel.generate_text). Update with `unsloth studio update`."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Ship the sampler used by diffusion chat

On an installation built from this repository revision, every text-diffusion chat reaches this check and fails because the bundled FastDiffusionModel in unsloth/models/diffusion.py has no generate_text method, and there is no other sampler implementation that adds it. Consequently the newly added chat path can only emit the update error rather than generate a response; the sampler API needs to be included in the same release or this path must call an API that the bundled core actually provides.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR depends on #13341 (stated at the top of the description; merge #13341 first), which adds FastDiffusionModel.generate_text and the per-family samplers. Against an older core this path stops with a clear update message rather than decoding through the wrong path.

Comment on lines +4733 to +4739
embedding_lr = training_args.get("embedding_learning_rate") if is_cpt else None
if embedding_lr is not None:
if "embedding_learning_rate" not in fields:
raise RuntimeError(
"Continued pretraining of a text-diffusion model with an embedding "
"learning rate needs a newer Unsloth. Upgrade with: "
"`pip install -U unsloth unsloth_zoo`."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Support the default diffusion CPT optimizer settings

The default Studio continued-pretraining configuration includes embed_tokens and lm_head, so the worker derives a non-null embedding_learning_rate (defaulting it to lr/10) and this branch is taken. However, the bundled unsloth.models.diffusion_trainer.DiffusionConfig has no embedding_learning_rate field, causing default diffusion CPT runs to terminate with this upgrade error even on the same repository revision. Add the optimizer-field support to the bundled diffusion trainer or provide a working fallback for CPT.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR depends on #13341 (stated at the top of the description; merge #13341 first), which adds DiffusionConfig.embedding_learning_rate and builds the optimizer through UnslothTrainer so embeddings get their own group. Against an older core the CPT run stops with the upgrade message instead of training at the wrong rate.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 48789ad7e6

ℹ️ 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".

# Conflicts:
#	studio/backend/core/training/trainer.py
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c29d253984

ℹ️ 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".

…eam and SDAR

Their output-head rows for <|im_end|>, <tool_call>, <|fim_pad|> and the other special tokens are near-duplicates,
so at 2e-4 a LoRA run swaps them: replies end in <tool_call> or come back empty. Clean at 5e-5. Only the
untouched Studio default is lowered; any other value is kept.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: de9e814146

ℹ️ 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".

# Conflicts:
#	studio/backend/core/inference/inference.py
#	studio/backend/core/training/trainer.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant