Repository navigation
Studio: live denoising canvas for transformers diffusion LMs - #13593
Conversation
… a diffusion model the config probe missed
…p for diffusion, keep max_length on unpatched TRL
… the 5.5 sidecar does not ship it
…annot reach the worker processes
…e pickled for dataset workers
…mbedding learning rate, refuse MLX training of text-diffusion models
…les, refuse MLX chat for text-diffusion models, turn layer offloading off before the VRAM budget
…rs, refuse an autoregressive load in diffusion chat, resolve Hub LoRA bases before the MLX refusal, keep the denied-credential sentinel in detection
…be export limits with the caller's credential
…ed diffusion Studio tests without unsloth_zoo
…ar exists, classify a Hub LoRA by its base before the vision loader
# Conflicts: # studio/backend/core/training/trainer.py
…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.
Forward per-step canvas frames from FastDiffusionModel.generate_text(on_frame=...) as the existing diffusion_frame SSE event, only for streaming single-reply chats with X-Unsloth-Events: 1. The relay throttles to one frame per 100 ms, renders masked positions as a placeholder glyph and never raises into the sampler. An older core without on_frame is never passed one.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b6e822fd44
ℹ️ 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".
| return backend.generate_chat_response( | ||
| cancel_event = cancel_event, | ||
| stats_holder = stats_holder, | ||
| **_sf_frame_kwargs, |
There was a problem hiding this comment.
Forward diffusion frames for adapter-controlled replies
When Studio runs a base-vs-LoRA thread, the request carries use_adapter, so execution takes the branch above and never expands _sf_frame_kwargs; consequently generate_with_adapter_control does not receive diffusion_frames=True, the worker never installs the frame sink, and qualifying streaming diffusion-LM replies show no live canvas. Pass the frame kwargs through the adapter-controlled call as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f28103a: the adapter-controlled branch now passes the frame kwargs to generate_with_adapter_control, whose dispatched path already carries diffusion_frames.
| frame_kwargs = {} | ||
| sink = getattr(self, "diffusion_frame_sink", None) | ||
| if sink is not None and _accepts_on_frame(generate_text): | ||
| frame_kwargs["on_frame"] = _diffusion_frame_relay(model_info["tokenizer"], sink) |
There was a problem hiding this comment.
Apply stop sequences to canvas frames
When a streaming request supplies stop, the relay publishes the fully decoded frame without applying those sequences, while the completed text is truncated only after generate_text returns. A client opting into UI events can therefore receive and display the settled suffix after the requested stop sequence before the final reply suddenly contracts, exposing output the request explicitly asked the API to suppress; pass the stop list into the relay and truncate each rendered frame at the earliest match.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f28103a: the relay takes the request's stop list and cuts each rendered frame at the earliest match, as the final reply is cut.
| { | ||
| "type": "diffusion_frame", | ||
| "block": int(frame.get("block", 0)), | ||
| "step": int(frame.get("step", 0)), |
There was a problem hiding this comment.
Normalize sampler steps before emitting canvas frames
The sampler counter is treated as one-based here—the block-end check considers step == total final, and the callback fixture starts at step 1—but the existing diffusion_frame frontend contract is zero-based: DiffusionCanvas renders canvas.step + 1. Forwarding the counter unchanged therefore labels the first transformer frame as step 2 and the final frame as total + 1/total; normalize it to the event contract before sending it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f28103a: frames are sent with a zero-based step clamped to total - 1, so the block-end frame renders as total/total.
…uences, zero-based steps The base-vs-LoRA compare path now asks for diffusion frames like the plain path. Each rendered frame is cut at the request's stop sequences, as the final reply is, and the sampler's block-end step (step == total) is sent as the zero-based step the canvas renders as step + 1 of total.
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
time.monotonic() can be smaller than the relay interval right after boot, so a zero start time dropped the first canvas frame.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
# Conflicts: # studio/backend/core/inference/inference.py # studio/backend/tests/test_diffusion_lm_studio.py
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d7c1c5d253
ℹ️ 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".
| return | ||
| last[0] = now | ||
| try: | ||
| text = _render_canvas(tokenizer, frame.get("tokens") or (), frame.get("mask_id")) |
There was a problem hiding this comment.
Truncate canvas frames at the model's EOS
When a diffusion block places an EOS or assistant-turn-end token before other generated slots, generate_text truncates the final completion at that token, but this relay decodes the entire frame. Because skip_special_tokens=True hides the EOS marker while leaving later ordinary tokens visible, the canvas can briefly expose a trailing suffix that is absent from the final reply. Apply the same EOS boundary used by the sampler before rendering each frame.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 307437c: the frame relay now gets the same EOS and turn-end ids generate_text cuts at (_diffusion_eos_ids) and drops everything from the first one before rendering, so a frame never shows text past the point the final reply ends. Covered by test_frame_relay_cuts_frames_at_the_first_eos and test_diffusion_eos_ids_match_the_sampler_cut.
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…nt the diffusion shard (#17736) ## Summary Follow-up to #17723, which moved `test_diffusion*` into its own `(Python 3.13, diffusion)` backend shard. Two things went red once that shard ran (seen on a staging run against current main): 1. `Repo tests (CPU, studio)` and `workflow-trigger lint`: ``` tests/studio/test_backend_ci_parallel_isolation.py::test_the_command_scan_sees_the_parallel_run_and_the_serial_steps AssertionError: expected fourteen parallel pytest runs, four shards of the backend matrix and ten of repo-cpu-tests ... assert 15 == 14 ``` That test pins the number of parallel pytest runs on purpose, so a new shard has to be stated there. #17723 updated `test_ci_backend_pytest_shards.py` but missed this one. My mistake. 2. `(Python 3.13, diffusion)`: five tests in `studio/backend/tests/test_diffusion_lm_studio.py` fail with `PackageNotFoundError: No package metadata was found for unsloth_zoo`: - `test_frame_relay_throttles_and_never_raises_into_the_sampler` - `test_frame_relay_sends_zero_based_steps_and_honours_stop_sequences` - `test_frame_relay_cuts_frames_at_the_first_eos` - `test_diffusion_eos_ids_match_the_sampler_cut` - `test_chat_diffusion_load_refuses_an_unmarked_model_and_keeps_the_token_boundary` They import `core.inference.inference`, which imports `unsloth`, and the backend job installs neither `unsloth_zoo` nor `trl`. They only passed in the old a-f shard because an earlier file on the same worker (`test_audio_chat_load.py`, `test_chat_prompt_bos.py`) had already imported that module with its own `unsloth` stubs and left it cached. In a shard of only `test_diffusion*` files that never happens. So these tests have depended on xdist scheduling since #13593; the split only made it deterministic. ## Change - `tests/studio/test_backend_ci_parallel_isolation.py`: 15 parallel runs, 5 backend shards. - `studio/backend/tests/test_diffusion_lm_studio.py`: a small `inference_mod` fixture the five tests now take. - When `unsloth_zoo` is installed, or the module is already imported, it returns the real module. Nothing changes there. - Otherwise it stubs `unsloth` and `unsloth.chat_templates` (the same two names the other backend tests stub) through `monkeypatch`, and also drops the freshly imported `core.inference.inference`. So no later test inherits a module bound to these stubs. - The tests keep running in the backend job instead of being skipped there. ## Testing - Locally, with `diffusers`, `unsloth_zoo` and `trl` hidden from import (the backend job's environment): `test_diffusion_lm_studio.py`, `test_diffusion_int8_attention.py` and `test_diffusion_rocm_tag_detect.py` on their own. The five tests fail on main with the same error and pass here. They also pass with the real packages installed. - The same files in one process, before and after `test_audio_chat_load.py` and `test_chat_prompt_bos.py`: 78 passed, 33 skipped in both orders. - Every test that reads `studio-backend-ci.yml` (15 files): 341 passed, 3 skipped. The isolation test fails on main. - `test_backend_tests_stub_heavy_imports.py` and `test_sibling_imported_tests_import_their_helpers_top_level.py`: pass. The other failures on the new shard come from #17718 and are fixed in #17737.
Stacked on #13342 (base
diffusion-studio-training); retarget tomainonce #13342 merges. The canvas lights up with theon_framesupport in #13592; without it this change is a no-op.DiffusionGemma already shows its denoising canvas in Studio chat. This does the same for the transformers diffusion LMs (LLaDA, LLaDA-MoE, Dream, SDAR, LLaDA2, Nemotron-Labs-Diffusion): while a reply denoises, the chat shows the canvas filling in, and the final reply streams as usual.
How
routes/inference.py: when a chat request streams with events on (X-Unsloth-Events: 1), the route asks for diffusion frames.orchestrator.py/worker.py: a frame sink travels with the request to the worker and frames come back on the same event stream DiffusionGemma uses ({"type": "diffusion_frame", "block", "step", "total", "text"}), so the existing frontend canvas renders them. Frames never enter the transcript.core/inference/inference.py:_diffusion_frame_relaydecodes the canvas (masked slots rendered as placeholders) and hands at most one frame per interval to the sink. A block's last frame is never throttled away, since it is the settled block the next frames build on. A failing sink never raises into the sampler.on_frameis only passed when the installed coregenerate_textaccepts it (_accepts_on_frame), so older cores keep working unchanged.step + 1oftotal).use_adapter) get frames through the dispatched path too.Tests
studio/backend/tests/test_diffusion_lm_studio.py: frame relay throttling and block-end frames, sink failures, the request flag plumbing through route, orchestrator and worker, and the old-core path withouton_frame. 81 passed.Before / after
Studio chat with JetLM/SDAR-1.7B-Chat, "Explain in a short paragraph why the sky is blue." Both sides run the #13592 core (BEFORE = #13342 + #13592, AFTER = #13342 + #13592 + this PR), so the only difference is this change. BEFORE streams 0
diffusion_frameevents and shows "Working..." until the reply lands; AFTER streams 37 and shows the canvas filling in (mask slots as░) until the reply replaces it.The AFTER side while it denoises:
(The recording predates the step-numbering fix in this PR, so a block's last frame there still reads step 5/4; it now reads 4/4.)