Repository navigation
[rl] Muse Spark image prompts and a SLAKE LoRA GRPO recipe for Muse Spark 816B - #5998
Conversation
33b450e to
b299965
Compare
The generator's vision encoder ran eagerly on every call: TitanRL never set vLLM's `cudagraph_mm_encoder`, and the multimodal wrapper did not implement vLLM's `SupportsEncoderCudaGraph`, so only the language model was graphed. On an A100 the eager Qwen3.5-0.8B encoder takes ~20 ms per call for one 64-token image, almost all launch overhead. - `Qwen35VisionEncoder.forward_padded`: the encoder on inputs padded to a fixed patch count, with positions computed beforehand and `segment_ids` (-1 for padding); it reads nothing back to the host. `create_padded_block_diagonal_mask` lets padding attend only to itself. `forward` shares the body and is otherwise unchanged. - `VLLMMultimodalModelWrapper` implements `SupportsEncoderCudaGraph`: token budgets from the vision processor's smallest image to `max_num_batched_tokens`, replay buffers with the batch's patches, position embeddings (from the current weights), RoPE cache and segment ids. - `VLLMEngine.Config.cuda_graph.vision_encoder` (default False) turns it on; the engine raises if it is set without `Controller.Config.vision_processor`, and the wrapper raises at startup for a vision encoder other than Qwen3.5's (e.g. Muse Spark's NaViT, #5998, which has no padded forward yet). Local A100, Qwen3.5-0.8B, 48 Geometry3K images x 2 samples, greedy: every encode hit one of the 6 captured graphs; encoder time after warmup 287 ms -> 90 ms (max call 37 -> 13 ms). Graph vs eager outputs differ as much as eager vs eager with different request batching (mean |logprob diff| 0.0169 vs 0.0168).
The generator's vision encoder ran eagerly on every call: TitanRL never set vLLM's `cudagraph_mm_encoder`, and the multimodal wrapper did not implement vLLM's `SupportsEncoderCudaGraph`, so only the language model was graphed. On an A100 the eager Qwen3.5-0.8B encoder takes ~20 ms per call for one 64-token image, almost all launch overhead. - `Qwen35VisionEncoder.forward_padded`: the encoder on inputs padded to a fixed patch count, with positions computed beforehand and `segment_ids` (-1 for padding); it reads nothing back to the host. `create_padded_block_diagonal_mask` lets padding attend only to itself. `forward` shares the body and is otherwise unchanged. - `VLLMMultimodalModelWrapper` implements `SupportsEncoderCudaGraph`: token budgets from the vision processor's smallest image to `max_num_batched_tokens`, replay buffers with the batch's patches, position embeddings (from the current weights), RoPE cache and segment ids. - `VLLMEngine.Config.cuda_graph.vision_encoder` (default False) turns it on; the engine raises if it is set without `Controller.Config.vision_processor`, and the wrapper raises at startup for a vision encoder other than Qwen3.5's (e.g. Muse Spark's NaViT, #5998, which has no padded forward yet). Local A100, Qwen3.5-0.8B, 48 Geometry3K images x 2 samples, greedy: every encode hit one of the 6 captured graphs; encoder time after warmup 287 ms -> 90 ms (max call 37 -> 13 ms). Graph vs eager outputs differ as much as eager vs eager with different request batching (mean |logprob diff| 0.0169 vs 0.0168).
The generator's vision encoder ran eagerly on every call: TitanRL never set vLLM's `cudagraph_mm_encoder`, and the multimodal wrapper did not implement vLLM's `SupportsEncoderCudaGraph`, so only the language model was graphed. On an A100 the eager Qwen3.5-0.8B encoder takes ~20 ms per call for one 64-token image, almost all launch overhead. - `Qwen35VisionEncoder.forward_padded`: the encoder on inputs padded to a fixed patch count, with positions computed beforehand and `segment_ids` (-1 for padding); it reads nothing back to the host. `create_padded_block_diagonal_mask` lets padding attend only to itself. `forward` shares the body and is otherwise unchanged. - `VLLMMultimodalModelWrapper` implements `SupportsEncoderCudaGraph`: token budgets from the vision processor's smallest image to `max_num_batched_tokens`, replay buffers with the batch's patches, position embeddings (from the current weights), RoPE cache and segment ids. - `VLLMEngine.Config.cuda_graph.vision_encoder` (default False) turns it on; the engine raises if it is set without `Controller.Config.vision_processor`, and the wrapper raises at startup for a vision encoder other than Qwen3.5's (e.g. Muse Spark's NaViT, #5998, which has no padded forward yet). Local A100, Qwen3.5-0.8B, 48 Geometry3K images x 2 samples, greedy: every encode hit one of the 6 captured graphs; encoder time after warmup 287 ms -> 90 ms (max call 37 -> 13 ms). Graph vs eager outputs differ as much as eager vs eager with different request batching (mean |logprob diff| 0.0169 vs 0.0168).
159dfe3 to
f36c11c
Compare
f36c11c to
eadf8c6
Compare
eadf8c6 to
9fe5bfa
Compare
9fe5bfa to
3f72d8c
Compare
3f72d8c to
d7861f8
Compare
|
@claude Review this PR |
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
this approach, and what you checked yourself. -->
**Stack** (image RL; review bottom up, each PR is one commit on the one
below):
0. #5873 [multimodal] VisionProcessor: one per-model image and video
processor (merged)
1. #5823 [multimodal] Image-reference Qwen3.5 renderer and shared M-RoPE
positions (merged)
2. **→** #5824 [rl] Image prompts through rollouts and the vLLM
generator
3. #5825 [rl] Train on image prompts, with a Geometry3K recipe
4. #5844 [rl] LoRA RL: generators load the base checkpoint, weight syncs
carry only the adapters
5. #5845 [rl] CUDA graphs for the generator's vision encoder
6. #5998 [rl] Muse Spark image prompts and a SLAKE LoRA GRPO recipe for
Muse Spark 816B
7. #6016 [rl][docs] README: bring the RL model support table up to date
## Why
RL prompts are token ids only: the rollout worker, the router, the
generator and vLLM pass a bare `prompt_token_ids`, so an image prompt
from #5823's renderer has nowhere to carry its images, and the generator
has no way to run the TorchTitan vision encoder. This PR carries image
prompts from the renderer to vLLM (Qwen3.5); text runs are unchanged
apart from the `Prompt` wrapper.
**Example.** Before: `generate(prompt_token_ids=[...])`. After, an image
travels as file bytes plus where its placeholder run sits:
```
rollout worker generator (every TP rank) vLLM
-------------- ------------------------- ----
render() -> Prompt VisionProcessor (CPU): embed_multimodal: vision encoder,
token_ids (placeholder runs) -----> resize_and_normalize + patchify -----> once per mm hash while cached
images: PromptImage(hash_value, LRU cache of pixel values by hash embed_input_ids: image embeddings
grid_thw, data=file bytes) image_prompt_to_engine_input -> mm_input over the placeholders
image_placeholders forward(3D M-RoPE positions)
```
## What changed
**One generation input.** `Prompt(token_ids, images=(),
image_placeholders=())` replaces the bare `prompt_token_ids` everywhere
a prompt travels: `TokenEnvOutput.next_prompt`, `GenerateFn`, the
router, `Generator.generate` and `EngineRequest`. An image is a run of
placeholder tokens in `token_ids`; `Prompt.image_placeholders` says
where each run is, and its `PromptImage(hash_value, source_path,
grid_thw, data)` carries the image file's bytes (Geometry3K median 15
KB), so no process past the rollout worker needs the dataset's file
system. This is the shape vLLM (`mm_input`), SGLang and HF processors
take at the engine boundary, so no layer converts it.
**Rollouts store deltas.** A `RolloutTurn` stores only the images after
its shared prefix (`prompt_delta_images`,
`prompt_delta_image_placeholders`), like its tokens. `split_prompt` ends
the shared prefix at the first image that differs from the previous
turn's (another file with the same placeholder count, or a moved image),
so every changed image is in the delta. TokenEnv always calls
`render()`, passes the previous prompt's `multi_modal_data` to the
bridge when it has images, and reads the image files in a worker thread.
**One image preprocessing config.** `Controller.Config.vision_processor`
(the model's `VisionProcessor.Config` from #5873, next to `tokenizer`;
None = text only) is the only place image preprocessing is configured.
The controller and the rollout workers pass it to
`renderer.build(tokenizer=..., vision_processor=...)` (#5823), and the
generator takes it as a build argument. The controller requires a
generator model that is a `MultimodalModel` with a vision encoder. It
stays a config and not a property of the model type: every real Qwen3.5
flavor ships the vision encoder, and text RL recipes use them without
serving images.
**Generator.** With a vision processor, `VLLMEngine` turns each image
file into pixel values on the CPU, as the SFT dataloader does, keeps
them in an LRU cache by image hash (vLLM's `LRUCache`, 1 GiB:
preprocessing takes 6.5 ms per Geometry3K image on the engine loop
thread, and every sample of a group carries the same images), and
submits vLLM's `mm_input` directly, so vLLM's Hugging Face processor
never runs. vLLM still requires a registered multimodal processor for
the model class; it only sizes the encoder budget and profiles memory
with the vision processor's largest image (`_largest_patch_grid`, which
is not always square). A request whose image file does not decode is
rejected at admission like any request vLLM rejects: its rollout fails
and the engine keeps serving.
**Model wrapper.** `VLLMMultimodalModelWrapper` runs the model's
`get_vision_embeds` (made public) on the packed pixel values, writes the
image embeddings over the placeholder tokens, and computes M-RoPE
positions with `get_mrope_positions`, as the trainer does.
`model_config_to_hf_config_dict(serves_images=True)` declares M-RoPE to
vLLM and rejects a model whose attention is not `MRoPE.Config`. The
generator forward now returns plain tensors (spmd_types), so the DTensor
unwrap after it is gone. The generator's shared model build
(`build_inference_model`, #5811) drops the vision encoder unless the
wrapper serves images (`keep_vision_encoder`).
**Stale embeddings.** vLLM keeps an image's encoder output after its
requests finish (only `reset_encoder_cache` clears it), and the vision
weights train. Image mm hashes are therefore salted like the prefix
cache with the request's pinned policy version (`hash@version`). With
`reset_kv_cache_on_model_state_dict_load`, hashes are bare and the
engine resets the encoder cache on every load.
Until the trainer takes image inputs (next PR), the controller rejects
`vision_processor`, so image prompts never train on their placeholder
tokens alone. Verifiers environments reject it too (their env server
builds its own renderer).
### Why the deltas are safe
The generator always gets the full prompt; only stored turns are deltas,
and the trainer rebuilds exactly the input the generator saw:
1. Image offsets are full-prompt positions from the renderer
(`render()`; the Qwen3.5 bridge seeds its tokens with the previous
prompt, so its offsets are absolute too). TokenEnv copies them into the
delta unchanged: no offset arithmetic anywhere.
2. `split_prompt` keeps an image in the shared prefix only if it equals
the previous turn's image at the same index (hash, offset and length);
otherwise the prefix ends at its first placeholder. An identical image
has the same pad tokens at the same place, so the prefix never ends
inside an image.
3. So the previous turn's images inside the prefix are exactly this
turn's prefix images, and (previous images with offset < prefix) + delta
= the turn's full images, by induction from turn 0 (prefix 0). #5825's
`TrainingSampleBuilder` rebuilds them this way.
4. A training sample starts at a full prompt's first token, so
full-prompt offsets are sample offsets, and M-RoPE positions come from
the same `get_mrope_positions` over identical content on both sides.
5. A turn extends a training sample only when its prefix covers the
previous prompt + completion. A changed image shortens the prefix, so a
completion is never trained with an image it was not generated from.
Two things could break this, and each is caught: a rollout producer that
builds turns without TokenEnv (#5825's builder rejects a delta image
outside its delta), and a renderer bridge with tail-relative offsets
(generator and trainer would be wrong together; each image renderer
needs a multi-turn test like #5825's real-renderer
`test_multiturn_images.py` for Qwen3.5).
## Numerics / performance
- Text path: RL loss guard (`rl_grpo_qwen3_0_6b_varlen_batch_invariant`,
seed 42, deterministic, trainer TP4 + one generator TP4, on-policy, 10
steps) gives `loss/mean`, `trainer/grad_norm/mean` and the
generator-vs-trainer logprob diff (max 0) bitwise equal to the PR below
at all 10 steps (TensorBoard values, `scripts/rl/loss_compare.py`; on
b9b3620, this PR before the rename to `VisionProcessor`, which changes
no computation). This covers the `Prompt` wrapper and the generator
forward without the DTensor unwrap.
- Image path, measured on an earlier revision of this PR (SLAKE medical
VQA, Qwen3.5-0.8B): generator-only accuracy with images 0.81 vs 0.51
text-only (TP1 and TP2 identical); generator vs TorchTitan forward
logprobs on image prompts mean abs diff 0.0166 vs 0.0150 for the text
control; 128 requests over 4 images ran the vision encoder 4 times. The
end-to-end image run comes with #5825.
## Testing
- `test_vllm_multimodal_wrapper.py`: the engine input places each image
on its placeholders, with the pixel values whose patch count matches the
renderer's grid; M-RoPE input positions; the largest patch grid (square,
non-square, NaViT); profiling inputs; the HF config declares M-RoPE only
when serving images; the controller rejects a vision processor for a
model without a vision encoder; image embeddings land on the placeholder
tokens vLLM's mask marks, in order (`masked_scatter_`, which never syncs
the host).
- `test_generator.py`: admission salts image hashes with the pinned
version (bare in reset mode), preprocesses each file once while cached,
rejects image requests without a vision processor, and rejects only the
request whose image file does not decode; the encoder cache resets with
the KV cache.
- `test_token_env.py`, `test_rollout_utils.py`: images across turns, the
bridge extends earlier images, delta images, `split_prompt` ends the
prefix at a changed or moved image, rejection of pixels and non-image
modalities, a changed file.
- `test_rollout_worker.py`, `test_rollout_recorder.py`: the rollout
sends and records delta images, without their bytes.
- `pytest tests/rl/unit_tests/cpu`: 575 passed, 8 skipped.
d7861f8 to
6bfe553
Compare
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. I found no correctness problem in the model, renderer or generator changes. The open items are a missing upstream issue link and recipe arguments, test asserts and fields that nothing uses. This PR touches models/common/decoder.py, so a maintainer still needs to review it.
What this PR does.
- Renderer: Muse Spark renders image parts as
<|image_start|>+ N x<|patch|>+<|image_end|>, with N taken from the file header. - Models:
Decoder.forwardis split into the token embedding plus a newforward_embeddings. The vLLM multimodal wrapper now callsforward_embeddingsinstead of its own copy of the layer loop, so it picks up Muse Spark's residual and final-norm dtypes. - Generator positions: the vLLM HF config gets
mrope_sectiononly forMRoPE.Configmodels; other models keep 1D positions. - Generator fix: it patches vLLM's
strip_covered_mm_dataso a preempted, prefix-cached image request can resume. - SLAKE: a new SLAKE env/data/rubric and an 816B LoRA GRPO recipe.
Example.
prompt: [{"type": "image", "path": "a.png" (100x60)}, {"type": "text", "text": "Is this a CT?"}]
before: MuseSparkRendererConfig.build(vision_processor=...) -> ValueError
model_config_to_hf_config_dict(muse, serves_images=True) -> ValueError (needs MRoPE)
after: tokens ... user<|message|><|image_start|><|patch|>x6<|image_end|>Is this a CT?<|eot|>
mm_data image: hash=hash_image_file(bytes), grid_thw=(1,4,6), placeholder=run of 6
vLLM hf config: no mrope_section -> 1D positions; trainer: no mrope_positions
Must fix
torchtitan/rl/generator/vllm/multimodal_wrapper.py:121: the vLLM monkeypatch's TODO has no upstream issue link.torchtitan_recipes/rl/slake.py:109-114: the recipe exposes 19 arguments, including an unverified CP>1 path and a hardcoded{True: 377, False: 913}validation size. Keep only the paths andtarget_offpolicy_steps.tests/rl/unit_tests/cpu/test_slake.py:163-179: these asserts only re-read recipe constants. Keep the LoRA projection count and delete the rest.torchtitan/rl/examples/slake/env.py:41:include_imagehas no consumer.torchtitan/rl/examples/slake/data.py:63-64: theclosed_onlydefault and its docstring contradict the recipe, which trains on open questions too.
Should consider
torchtitan/models/muse_spark/renderer.py:214:_imageduplicatesQwen35ImageRefRenderer._process_image, and each render reads and hashes every image file twice.torchtitan/models/qwen3_5/model.py:706-723(not in the diff):Qwen35Model.forwardstill has its own copy of the layer loop and final norm. Now thatDecoder.forward_embeddingsexists, it can end withreturn self.forward_embeddings(x, positions, attention_metadata, padding_mask=..., aux_loss_denominators=...). That deletes the copy, which matches the stated goal of the wrapper change. It should be bitwise identical; please check with a loss comparison.
Details
- Gate. The problem is real: before this PR, the Muse Spark renderer and
model_config_to_hf_config_dictboth raise on image prompts. The layer is right: Muse Spark's code lives in its model folder, and the generator now dispatches onget_mrope_config, which the controller'sbuild_mrope_positionscheck also uses. The new example lives undertorchtitan/rl/examples/and the recipe undertorchtitan_recipes/rl/, as the other examples and recipes do. forward_embeddings. The old wrapper loop calledlayer(h, None, positions, padding_mask=...)and thennorm.Decoder.forward_embeddingsdoes the same withattention_metadata=Noneandaux_loss_denominators=None. The generator sets_skip_lm_head = True(rl/generator/model.py:140), so Qwen3.5 generator numerics don't change.- Rename to
image_vision_bank_indices_T. This is mechanical. The only other users are Qwen3.5 and the batcher (batcher.py:1125), and the SFT path builds the indices inpreprocess_inputs. The newbank_indices_name in batchskip matches Qwen3.5's (qwen3_5/model.py:448). - Patch scope. The monkeypatch takes effect only because the engine runs with
distributed_executor_backend="external_launcher"(engine.py:315), so the scheduler and the worker share one process. The added test catches vLLM moving the function: otherwise the assignment would silently set an attribute that nothing reads.
Not verified: the patched strip_covered_mm_data is the only call site in the installed vLLM (vLLM isn't installed in this environment); CP=8 fitting 64k tokens on 8 GPUs.
| The engine core and its worker run in this process, so the worker's features are the | ||
| scheduler's own objects: keeping the data costs no memory. | ||
|
|
||
| TODO: remove once vLLM resends a resumed request's dropped image data. |
There was a problem hiding this comment.
This overwrites a vLLM module function (vllm.v1.core.sched.output.strip_covered_mm_data) process-wide, and it works around a vLLM bug. CLAUDE.md principle 3 says workarounds like this need a TODO with an upstream issue link. Without one, nothing tracks the removal, and nobody can check on a vLLM bump whether the bug is fixed. Please file the vLLM issue (a preempted request whose prefix blocks were evicted reschedules an encoder run, but its data was stripped by strip_covered_mm_data, so _gather_mm_embeddings raises "Encoder cache miss") and link it here:
| TODO: remove once vLLM resends a resumed request's dropped image data. | |
| TODO(<vllm issue link>): remove once vLLM resends a resumed request's dropped image data. |
| trainer_context_parallel_degree: int = 1, | ||
| generator_gpus: int = 8, | ||
| closed_questions_only: bool = False, | ||
| drop_zero_std_reward_groups: bool = True, | ||
| target_offpolicy_steps: int = 7, | ||
| num_validation_prompts: int | None = None, |
There was a problem hiding this comment.
The recipe takes 19 arguments, but the PR measures only one configuration: CP=1, 8+3x8 GPUs, both question types, full validation. rules/config.md says to expose only options a verified recipe uses. The sibling muse_spark_816b_a42b_dapo_math_gb300_config takes only its three paths.
The worst cases:
trainer_context_parallel_degree: the CP>1 path (theContextParallelTransformbranch at L283, the divisibility check at L152, the Ulysses test) was never run. The docstring's "64k at CP=8 fit 8 GPUs" is unverified.closed_questions_onlyexists only to pick a hardcoded test-split size from_SLAKE_TEST_QUESTIONS = {True: 377, False: 913}(L91). That magic count breaks silently if the dataset filter changes.num_validation_prompts,trainer_gpus,generator_gpus,drop_zero_std_reward_groups,lora_rank/lora_alpha/lr: if a run needs a different value,--overridealready covers it.
Suggest keeping hf_assets_path, slake_data_dir and target_offpolicy_steps (the PR names that one as the knob to lower for long runs) and hardcoding the measured values. Drop the CP branch and test_muse_spark_lora_recipe_cp_8_uses_ulysses_attention. That deletes about 60 lines.
| assert config.vision_processor.patch_size == ( | ||
| MUSE_SPARK_VISION_PROCESSOR_KWARGS["patch_size"] | ||
| ) | ||
| # One greedy pass over the English test split before and after training. | ||
| assert config.async_loop.validation.steps == 913 | ||
| assert config.rollouter.validation_dataset.split == "test" | ||
| # The generators load the frozen base themselves; syncs carry only the adapters. | ||
| assert config.generator.checkpointer.initial_load_in_hf | ||
| # The measured 32-GPU configuration: an 8-GPU trainer and three 8-GPU generators. | ||
| parallelism = config.trainer.parallelism | ||
| assert ( | ||
| parallelism.data_parallel_shard_degree, | ||
| parallelism.context_parallel_degree, | ||
| parallelism.expert_parallel_degree, | ||
| ) == (8, 1, 8) | ||
| assert config.num_generators == 3 | ||
| assert config.generator.parallelism.expert_parallel_degree == 8 |
There was a problem hiding this comment.
These lines re-read values the recipe just set: patch_size, validation.steps == 913, split == "test", initial_load_in_hf, the parallelism tuple, num_generators == 3. rules/tests.md says not to add tests like this. They catch no regression, and they fail on every intentional recipe change.
L157-162 are worth keeping. LoRATransform doesn't raise when a target matches nothing, so the 3 * 62 count is what guards the target FQNs against Muse Spark module renames. Please delete L163-179.
|
|
||
| @dataclass(kw_only=True, slots=True) | ||
| class Config(MessageEnv.Config): | ||
| include_image: bool = True |
There was a problem hiding this comment.
include_image has no consumer. The recipe uses SlakeEnv.Config(), and the PR reports no text-only baseline run. Please drop the field and the False test parametrization. If the baseline is ever needed, it is a one-line change.
| closed_only: bool = True | ||
| """Keep only CLOSED questions, which exact-match rewards can grade.""" |
There was a problem hiding this comment.
This contradicts the only consumer. The default and docstring say to keep only CLOSED questions "which exact-match rewards can grade", and the class docstring (L45) says the same. But the recipe trains and validates on open questions too (closed_questions_only=False), graded by that same exact-match reward. Either drop the field and always keep both types, or keep the field and fix its default and the docstrings. If the recipe knob goes away (see the comment on slake.py), dropping the field is simplest. Also, split should be Literal["train", "validation", "test"] (rules/config.md).
| f"{IMAGE_END_STR} in the tokenizer." | ||
| ) | ||
|
|
||
| def _image(self, part: dict[str, Any]) -> _ImageFile: |
There was a problem hiding this comment.
This duplicates Qwen35ImageRefRenderer._process_image (torchtitan/models/qwen3_5/renderer.py:109-130) almost line for line: the path check, reading the file, the header-size Image.open, grid_thw, num_placeholder_tokens, hash_image_file. Two models now share it, so it can move next to hash_image_file in torchtitan/components/renderer.py, e.g. read_image_ref(part, vision_processor) -> (hash, grid_thw, num_tokens), and both renderers can call it.
Also, _image runs twice per image per render, once in span and once in multi_modal_data. Each run reads and SHA-hashes the file again, so every rollout of a 16-sample group does it twice. Recording the _ImageFiles during _render_content and reusing them in multi_modal_data would remove the second pass.
6bfe553 to
1206012
Compare
1206012 to
2b3952b
Compare
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
this approach, and what you checked yourself. -->
**Stack** (image RL; review bottom up, each PR is one commit on the one
below):
0. #5873 [multimodal] VisionProcessor: one per-model image and video
processor (merged)
1. #5823 [multimodal] Image-reference Qwen3.5 renderer and shared M-RoPE
positions (merged)
2. #5824 [rl] Image prompts through rollouts and the vLLM generator
(merged)
3. **→** #5825 [rl] Train on image prompts, with a Geometry3K recipe
4. #5844 [rl] LoRA RL: generators load the base checkpoint, weight syncs
carry only the adapters
5. #5845 [rl] CUDA graphs for the generator's vision encoder
6. #5998 [rl] Muse Spark image prompts and a SLAKE LoRA GRPO recipe for
Muse Spark 816B
7. #6016 [rl][docs] README: bring the RL model support table up to date
## Why
After #5824, rollouts carry image prompts and the generator serves them,
but the trainer cannot train on them: training samples have the
placeholder tokens without the images, so the controller rejects
`Controller.Config.vision_processor`. Training on image prompts needs
each sample's full images rebuilt from the turns' deltas, the images
moved from the batcher to the trainer and encoded there, and, for GRPO,
not encoding one image once per sample: the samples of a group show the
same images.
**Example.** Before: setting `vision_processor` raises at controller
setup. After:
```
RolloutTurn deltas --TrainingSampleBuilder--> TrainingSample(token_ids, images, image_placeholders)
--Batcher--> microbatches: each distinct image file once, every placeholder token's embedding row
--trainer, TrainingMicrobatch.preprocess_images--> pixel_values -> vision encoder -> embedding rows
```
How the same image is encoded once: 2 groups x 2 samples on 2 DP ranks,
image k in group g0 and image m in group g1, each placeholder token
drawn as its image's letter (also in `Batcher._pack_image_inputs`'s
docstring):
```
samples a0: t k k k t t a1: t k k k t t t (group g0)
b0: t m m t t b1: t m m t t t (group g1)
1. Batcher._pack_with_lpt picks each sample's microbatch, preferring one that already holds
the sample's image:
rank 0: [a0 a1] rank 1: [b0 b1] k and m each encoded once
instead of rank 0: [a0 b0] rank 1: [a1 b1] k and m each encoded on both ranks
2. Batcher._pack_image_inputs builds rank 0's image inputs. The image embeddings (the model's
"vision bank") are the vision encoder's output for the microbatch's distinct images,
stacked in order, one row per image token; each token gets its row:
tokens t k k k t t | t k k k t t t | pad
rows -1 0 1 2 -1 -1 |-1 0 1 2 -1 -1 -1 | -1 image_vision_bank_indices_T
image_files [file k] each distinct image (by hash) once, ~15 KB
grid_thw [grid of k]
3. TrainingMicrobatch.preprocess_images, on the trainer: file k -> resize_and_normalize
-> patchify_all -> pixel_values (~2.4 MB of float32), once per distinct image.
4. The model encodes k once into embedding rows [e0 e1 e2], and each placeholder token
takes its row: tokens 1 and 7 both take e0 (gather_vision_embeds, already on main).
In the backward, both runs' gradients add up into the one encoding.
```
## What changed
- **Training samples carry their images** (`TrainingSample.images` and
`image_placeholders`, aligned like `Prompt`'s). Rollout turns store only
their new images (#5824), so `TrainingSampleBuilder` rebuilds each
turn's full images like its tokens: the previous prompt's images inside
the shared prefix, then the turn's own. A turn that swaps an image in
place branches like a token edit, because `split_prompt` ends the shared
prefix at the changed image. The builder rejects a delta image outside
its delta (placeholders are full-prompt positions); otherwise a producer
that stored delta-relative offsets would put image embeddings on other
tokens without an error. Why the rebuild is exact: #5824, "Why the
deltas are safe".
- **The batcher ships files, the trainer preprocesses.** Per microbatch,
the batcher ships each distinct image file once (`image_files` +
`image_file_sizes`), each placeholder token's row in the image
embeddings (`image_vision_bank_indices_T`), `grid_thw`, and, with
`Batcher.Config.build_mrope_positions`, 3D M-RoPE positions from
`get_mrope_positions`, as the generator computes them. The recipe sets
the flag, as SFT's `MultiModalCollator.Config.build_mrope_positions`
does (Geometry3K: True); `Controller.Config` raises unless it matches
the trainer model's RoPE (`get_mrope_config`), since a Qwen3.5 run
without it would train image tokens on 1D positions while the generator
used M-RoPE. Packing prefers a microbatch that already holds a sample's
image. On the trainer, `TrainingMicrobatch.preprocess_images` (named
after the generator's `_preprocess_images`) turns each file into pixel
values on the CPU before the engine sees the microbatch, so
`as_input_dict` holds model inputs as for any other microbatch; with
RDMA it runs on the read-ahead thread, hidden behind training.
Placeholder counts are checked against the grids, and the decoded images
against the prompts' grids.
- **One config.** The batcher gets `Controller.Config.vision_processor`
at build time, as the renderer and the generator do (#5824), so all
three use one config and nothing has to be kept equal. This replaces the
previous PR's guard.
- **Qwen3.5 under CP** keeps the embedding rows the batch provides
(`image_vision_bank_indices_T`) instead of counting placeholder tokens:
several placeholder runs can share one encoded image, and a placeholder
id sampled in a completion is text.
- **Recipe.** `rl/examples/geometry3k` (Hugging Face
`hiyouga/geometry3k`; the dataset writes the parquet's images to files
once, since rendering reads image files) and
`torchtitan_recipes/rl/geometry3k.py::rl_grpo_qwen3_5_0_8b_geometry3k`
(4 GPUs), with
`vision_processor=VisionProcessor.Config(**QWEN3_5_VISION_PROCESSOR_KWARGS)`
next to the tokenizer. Rewards reuse the DAPO math Math-Verify grader on
the last `\boxed{}`.
- Mechanical: `VisionProcessor.patchify_all` (patchify and pack items)
is extracted from the SFT collator, which now calls it; the trainer uses
it too.
- CI: the RL CPU job fetches the Qwen3.5 tokenizer next to the Muse
Glimmer one; the RL multi-GPU job runs `test_cp_images.py` (fetches
Qwen3.5-0.8B).
## Alternatives considered
- Ship pixel values instead of files: ~2.4 MB instead of ~15 KB per
Geometry3K image over RPC or RDMA.
- Find images by scanning token ids for placeholder runs, as the SFT
collator does: the policy can sample the placeholder id in a completion.
- No dedup: simpler, but the trainer then encodes every sample's copy of
an image; on SLAKE (Qwen3.5-0.8B) packing by image cut the images
encoded per step from 109-128 to 26-48 (of 128) and the median step time
from 16.9 s to 14.9 s. The share is smaller for larger language models
(the vision encoder stays the same size).
## Numerics / performance
On 8e8950a93 (this PR before the rename to `VisionProcessor`, which
changes no computation), `rl_grpo_qwen3_5_0_8b_geometry3k` on 4 A100
(trainer FSDP=2 + 2 generators at TP=1, 16 prompts x 8 samples per
step), 30 steps:
- validation reward on the 601 test problems 0.285 -> 0.358 (truncation
rate 0.56 -> 0.18);
- rollout reward, mean of steps 1-10 vs 21-30: 0.15 -> 0.28;
- mean trainer-generator logprob difference -0.0003 to -0.0018 per
token;
- the trainer encoded 35-98 images per step for the samples' 128
(packing by image);
- the trainer waited ~7 ms per step for its batch; 30 steps plus both
validations took 14.5 min.
Measured on earlier revisions of this stack (same preprocessing
placement and packing):
- SLAKE (medical VQA): Qwen3.5-0.8B on-policy GRPO, reward 0.008 -> 0.85
in 12 steps; Qwen3.5-35B-A3B on 8 GB300, reward 0.31 -> 0.94 in 30
steps.
- Geometry3K on 4 GB300, 30 steps: validation reward 0.270 -> 0.361 with
the default RPC batcher path and 0.271 -> 0.351 with
`Batcher.Config(rdma_min_tensor_bytes=1024)` +
`preprocess_microbatch_groups_lazily=True`; steady-state step ~10 s.
## Testing
- `test_rollout_utils.py`: training samples rebuild their full images
from the turns' deltas (extend, then a new branch); an image swapped in
place branches; a delta image outside its delta raises.
- `test_multiturn_images.py`: a two-turn image rollout through the real
`Qwen35ImageRefRenderer`, TokenEnv, the rollout worker and
`TrainingSampleBuilder` (with and without thinking): the turns store [a]
then [b], the samples carry [a, b] (or [a] and [a, b]), and every image
sits on its placeholder run.
- `test_batcher.py`: embedding rows, one file per distinct image, pixel
values equal to `patchify(resize_and_normalize(file))`, packing by
image, placeholder and grid checks, text samples with a vision
processor.
- `test_trainer.py` / `test_rdma_microbatch.py`: the trainer
preprocesses images before training, on the read-ahead thread with RDMA.
- `test_qwen3_5_vision_bank.py`: the batch's rows place one encoding on
two placeholder runs, and both runs' gradients add up into it (equal to
encoding the image twice; fails if a run's gradient is dropped).
- `test_cp_images.py` (GPU, RL multi-GPU CI): Qwen3.5-0.8B through
`Trainer.forward_backward` without CP (FSDP=2) and with CP=2
(AllGatherKV with head-tail balancing, and Ulysses), on microbatches
with an image split by the CP boundary, one image shared by samples on
both ranks, an image longer than a head-tail chunk, sampled placeholder
ids and a text sample. The decoder's input embeddings and M-RoPE
positions must equal the no-CP ones bit for bit, and the vision
encoder's gradient must match (norm ratio 0.85-1.15, cosine > 0.98).
Catches a CP shard that puts image rows or positions on the wrong
tokens, or a vision gradient not summed over the CP ranks (half the norm
at CP=2).
- `test_geometry3k.py`: dataset, env, grading, and the recipe's vision
processor matches the generator's and the trainer's vision encoder.
- Broader CP check run locally on the same trainer path (bf16,
deterministic; seven microbatches, adding an image longer than a CP=4
shard and DP ranks where one trains images and the other text): CP=2
(AllGatherKV contiguous and head-tail, Ulysses), CP=4 (contiguous and
head-tail), CP=2 x FSDP=2, and mixed DP ranks. Input embeddings and
positions are bitwise equal to no CP everywhere; the vision gradient's
norm ratio is 0.91-1.08 and its cosine >= 0.987. With one image's rows
reversed (a negative control), the embeddings differ by 1.6-2.8 and the
cosine drops to 0.08-0.96.
- `pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/components
tests/unit_tests/cpu/models/qwen3_5/test_qwen3_5_vision_bank.py`: 1129
passed, 9 skipped; 1 failed
(`test_lora_head_only_matches_cross_entropy`, a local Inductor C++ build
error that main has too). `pytest
tests/rl/unit_tests/gpu/test_cp_images.py` on 2 A100: 4 passed (2m43s);
with this PR's Qwen3.5 CP change reverted, its launches fail
(`pixel_values require special_tokens with an 'image_id' entry`).
## Known issues / follow-ups
- Rank balancing counts attention work, not vision-encoder work, which
packing by image concentrates (TODO in `Batcher._attention_workload`).
- Images are deduplicated within a microbatch only; a group split across
microbatches encodes its image once per microbatch.
2b3952b to
c32038d
Compare
c32038d to
2d61d33
Compare
…park 816B (#6025) Replaces #5998, which GitHub closed as merged when a stack reorder pushed its base branch (#5845's) on top of it. Nothing reached main, and a merged PR cannot be reopened. Review comments so far are on #5998. ## Summary (human-written) <!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why this approach, and what you checked yourself. --> **Stack** (image RL; review bottom up, each PR is one commit on the one below): 0. #5873 [multimodal] VisionProcessor: one per-model image and video processor (merged) 1. #5823 [multimodal] Image-reference Qwen3.5 renderer and shared M-RoPE positions (merged) 2. #5824 [rl] Image prompts through rollouts and the vLLM generator (merged) 3. #5825 [rl] Train on image prompts, with a Geometry3K recipe (merged) 4. #5844 [rl] LoRA RL: generators load the base checkpoint, weight syncs carry only the adapters (merged) 5. **→** #6025 [rl] Muse Spark image prompts and a SLAKE LoRA GRPO recipe for Muse Spark 816B 6. #5845 [rl] CUDA graphs for the generator's vision encoder This PR has three commits: Muse Spark image RL and the SLAKE recipe; a generator fix for preempted image requests; the recipe's `target_offpolicy_steps` default. ## Why 1. Image RL runs only Qwen3.5. The Muse Spark renderer rejects image parts. 2. The generator assumes M-RoPE: the vLLM HF config always gets an `mrope_section`. Muse Spark uses 1D positions for image tokens. 3. The generator's multimodal wrapper keeps its own copy of the decoder layer loop, which skips Muse Spark's residual and final-norm dtypes. 4. A preempted image request can crash the generator. vLLM drops the data of images that a new request's prefix-cache hit covers before sending the request to the worker (`strip_covered_mm_data`). With the V1 model runner, a preempted request resumes from the worker's copy of its features. If its prefix blocks were evicted in the meantime: - the scheduler schedules the image's encoder run; - the worker skips the run for lack of data; - `_gather_mm_embeddings` raises "Encoder cache miss" and the engine loop dies. GRPO samples share their group's prompt, so all but the first hit the prefix cache over their images. The first Muse Spark 816B SLAKE validation run crashed this way at step 4, twice, each time on a resumed request (128 prefix-cached tokens, encoder run scheduled). That run lacked #5982, so the preemption came from max-length garbage rollouts. Any preemption with eviction hits this bug, though. **Example.** A SLAKE prompt with one image, rendered for Muse Spark: ``` prompt: [{"type": "image", "path": "<image file>"}, {"type": "text", "text": "Which organ is shown?"}] before: Muse Spark renderer -> one <|patch|> per image (the SFT dataset expands it) generator HF config -> always mrope_section after: tokens <|image_start|> <|patch|> x N <|image_end|> Which organ is shown? ... positions 1D, like text: no mrope_section; the recipe leaves build_mrope_positions False, so no mrope_positions N the patch grid of the image size in the file header ``` ## What changed - **Muse Spark renderer**: built with a vision processor, an image part `{"type": "image", "path": ...}` renders as `<|image_start|>` + N x `<|patch|>` + `<|image_end|>`, as in Muse Spark's multimodal SFT data. N comes from the patch grid of the size in the file header. `multi_modal_data` carries each image's file hash, grid and `<|patch|>` run, as `Qwen35ImageRefRenderer` does, and `bridge_to_next_turn` places a later turn's images after the previous prompt's. Without a vision processor, an image part still renders as one `<|patch|>`, which the multimodal SFT data expands (#5885). - **Models**: `Decoder.forward_embeddings` runs the decoder after the token embedding, and `forward` calls it (mechanical split); `Qwen35Model.forward` ends with it too, so each model has one layer loop that the trainer and the generator share (bitwise-identical loss, see Numerics). Muse Spark overrides it with its residual and final-norm dtypes, adds `get_vision_embeds`, and takes the RL microbatch's bank rows (`image_vision_bank_indices_T`, the Qwen3.5 name). - **Generator**: image tokens of a model without M-RoPE get 1D positions. The HF config gets `mrope_section` only for `MRoPE.Config` (`get_mrope_config`, which #5825's controller check of `build_mrope_positions` uses too), and positions are transposed only when they are 3D. The multimodal wrapper calls `forward_embeddings` instead of copying the layer loop. - **Batcher**: unchanged. The SLAKE recipe leaves `Batcher.Config.build_mrope_positions` (#5825) False, as Muse Spark's SFT recipe leaves the collator's; `Controller.Config` checks it against the trainer model. - **SLAKE example** (`torchtitan/rl/examples/slake`): the English release, closed and open questions, with knowledge-graph questions dropped; the short-answer instruction from Muse Spark's SLAKE SFT recipe; reward by exact match after normalization. - **Recipe** `rl_muse_spark_816b_a42b_slake_lora_gb300`: - LoRA r8/a16 on `wqkv`, `wo` and `output_gate`, with the generators loading the HF base (adapter-only syncs, #5844); - Dist-MoE on both roles, without in-place WGRAD accumulation into the frozen experts; - the measured 32-GPU configuration, fixed in the recipe: an 8-GPU trainer and three 8-GPU generators, 32 prompts x 16 samples, 8K tokens per microbatch, low reasoning effort, 4K response tokens, zero-std groups dropped. Only the paths and `target_offpolicy_steps` (7, third commit) are arguments. The frozen bf16 base needs #5894 (frozen parameters stored in `param_dtype`, now on main) to fit the 8-GPU trainer. Adapter-only syncs need #5982 (generator weight loads finish the lm_head group's forward before resharding it). Without #5982 the generator's lm_head is corrupted from the third sync on. - **Generator, second commit**: `keep_prefix_cached_image_data` makes the scheduler send every new request's image data when the engine serves images. The engine core and its worker run in the generator's process, so the worker's features are the scheduler's own objects and keeping the data costs no memory. - **Recipe, third commit**: `target_offpolicy_steps` defaults to 7. With zero-std groups dropped, the run needs ~118 generated groups per step for 32 kept ones, so rollout supply is capped by the controller's active groups, `(target_offpolicy_steps + 1) x P`, not by the number of generators. - Unchanged: Qwen3.5's M-RoPE path (3D positions, `mrope_section`), and text-only rendering for Muse Spark. ## Alternatives considered - More generators instead of a higher `target_offpolicy_steps`: at 3, two more generators (48 GPUs) only reach 29.4 s per step, vs 24.0 s at 7 on 32 GPUs. ## Numerics / performance Muse Spark Open 816B-A42B on SLAKE, 32 GB300 GPUs (8-GPU trainer, three 8-GPU generators), the recipe's defaults before the third commit (32 x 16, `target_offpolicy_steps` 3, 10 steps), with #5894 and #5982. The comparison run uses the same configuration on the development branch this PR was ported from. Medians are over steps 5-10. | | this PR | development branch | |---|---|---| | step time | 36.0 s | 36.7 s | | trainer forward/backward | 20.8 s | 20.3 s | | trainer waiting for a batch (zero-std groups dropped) | 14.6 s | 16.3 s | | trainer/generator logprob diff, steps 1-10 | -0.004 to -0.006 | -0.004 to -0.005 | | prompt / response tokens | 726 / 224 | 731 / 223 | | reward | 0.511 | 0.504 | | trainer peak reserved memory | 258.8 GiB | 257.8 GiB | All 2,602 rollouts completed, none truncated. Prompt lengths match, so the Muse Spark image renderer emits the same tokens as the development branch's. Time per request outside the generator (router hop and payload): 13 ms. `target_offpolicy_steps` on the same 32 GPUs and tree (medians of steps 5-10): | `target_offpolicy_steps` | step | trainer waits | mean / max policy age | reward | logprob diff | |---|---|---|---|---|---| | 3 | 36.0 s | 14.6 s | 1.4 / 3 | 0.511 | -0.005 | | 5 | 24.0 s (mean 26.9 s) | 10-15 s at 2 of 6 steps | 3.0 / 5 | 0.518 | -0.005 | | **7 (default)** | 24.0 s (mean 23.6 s) | 0.002 s at every step | 4.0 / 7 | 0.526 | -0.005 | At 7 the trainer never waits: 1.5x the samples per second of 3. All rollouts completed, none truncated. `Qwen35Model.forward` ending with `forward_embeddings` (no computation change): `scripts/loss_compare.py` before vs after on the Qwen3.5 debug model (`qwen35_debugmodel`, cc12m-test with M-RoPE positions, FSDP=2, 20 steps, seed 42, deterministic, accelerator graphs off since the multimodal batches change shape each step): loss and grad norm bitwise identical at every step (TensorBoard values, max difference 0.0). ## Testing - New CPU tests: - renderer: an image renders as a `<|patch|>` run with the file hash; a bridge places new images after the previous ones; - vLLM wrapper: the HF config keeps 1D positions for Muse Spark images; - SLAKE dataset, env and rubric; - the recipe puts LoRA on wqkv, wo and output_gate of all 62 layers; - `test_scheduler_sends_prefix_cached_image_data_to_the_worker`: a request whose prefix-cache hit covers its image still sends the image data to the worker. Fails without the second commit (the data is None). - `pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/models/common`: 1009 passed. - After the third commit, on the rebased base: `pytest tests/rl/unit_tests/cpu/test_slake.py`: 18 passed. The 5 failures (`test_dapo_math` Math-Verify worker start, `test_lora_forward` inductor ABI) fail the same way on the base branch in this environment. ## Known issues / follow-ups - Staler samples at `target_offpolicy_steps` 7 (mean policy age 4 instead of 1.4). The effect on learning past 10 steps is not measured; the recipe takes `target_offpolicy_steps` as an argument, so a long run that suffers from staleness can lower it. - `keep_prefix_cached_image_data` is a workaround (TODO in code): remove it once vLLM resends a resumed request's dropped data. - The recipe needs #5982 (see What changed); #5894 is on main.
Summary (human-written)
Stack (image RL; review bottom up, each PR is one commit on the one below):
0. #5873 [multimodal] VisionProcessor: one per-model image and video processor (merged)
This PR has three commits: Muse Spark image RL and the SLAKE recipe; a generator fix for preempted image requests; the recipe's
target_offpolicy_stepsdefault.Why
Image RL runs only Qwen3.5. The Muse Spark renderer rejects image parts.
The generator assumes M-RoPE: the vLLM HF config always gets an
mrope_section. Muse Spark uses 1D positions for image tokens.The generator's multimodal wrapper keeps its own copy of the decoder layer loop, which skips Muse Spark's residual and final-norm dtypes.
A preempted image request can crash the generator. vLLM drops the data of images that a new request's prefix-cache hit covers before sending the request to the worker (
strip_covered_mm_data). With the V1 model runner, a preempted request resumes from the worker's copy of its features. If its prefix blocks were evicted in the meantime:_gather_mm_embeddingsraises "Encoder cache miss" and the engine loop dies.GRPO samples share their group's prompt, so all but the first hit the prefix cache over their images. The first Muse Spark 816B SLAKE validation run crashed this way at step 4, twice, each time on a resumed request (128 prefix-cached tokens, encoder run scheduled). That run lacked [rl] Generator weight loads: finish the lm_head group's forward before resharding it #5982, so the preemption came from max-length garbage rollouts. Any preemption with eviction hits this bug, though.
Example. A SLAKE prompt with one image, rendered for Muse Spark:
What changed
Muse Spark renderer: built with a vision processor, an image part
{"type": "image", "path": ...}renders as<|image_start|>+ N x<|patch|>+<|image_end|>, as in Muse Spark's multimodal SFT data. N comes from the patch grid of the size in the file header.multi_modal_datacarries each image's file hash, grid and<|patch|>run, asQwen35ImageRefRendererdoes, andbridge_to_next_turnplaces a later turn's images after the previous prompt's. Without a vision processor, image parts still raise.Models:
Decoder.forward_embeddingsruns the decoder after the token embedding, andforwardcalls it (mechanical split). Muse Spark overrides it with its residual and final-norm dtypes, addsget_vision_embeds, and takes the RL microbatch's bank rows (image_vision_bank_indices_T, the Qwen3.5 name).Generator: image tokens of a model without M-RoPE get 1D positions. The HF config gets
mrope_sectiononly forMRoPE.Config(get_mrope_config, which [rl] Train on image prompts, with a Geometry3K recipe #5825's controller check ofbuild_mrope_positionsuses too), and positions are transposed only when they are 3D. The multimodal wrapper callsforward_embeddingsinstead of copying the layer loop.Batcher: unchanged. The SLAKE recipe leaves
Batcher.Config.build_mrope_positions([rl] Train on image prompts, with a Geometry3K recipe #5825) False, as Muse Spark's SFT recipe leaves the collator's;Controller.Configchecks it against the trainer model.SLAKE example (
torchtitan/rl/examples/slake): the English release, closed and open questions, with knowledge-graph questions dropped; the short-answer instruction from Muse Spark's SLAKE SFT recipe; reward by exact match after normalization.Recipe
rl_muse_spark_816b_a42b_slake_lora_gb300:wqkv,woandoutput_gate, with the generators loading the HF base (adapter-only syncs, [rl] LoRA RL: generators load the base checkpoint, weight syncs carry only the adapters #5844);target_offpolicy_steps7.The frozen bf16 base needs [distributed] Store frozen parameters in param_dtype #5894 (frozen parameters stored in
param_dtype) to fit the 8-GPU trainer. Adapter-only syncs need [rl] Generator weight loads: finish the lm_head group's forward before resharding it #5982 (generator weight loads finish the lm_head group's forward before resharding it). Without [rl] Generator weight loads: finish the lm_head group's forward before resharding it #5982 the generator's lm_head is corrupted from the third sync on.Generator, second commit:
keep_prefix_cached_image_datamakes the scheduler send every new request's image data when the engine serves images. The engine core and its worker run in the generator's process, so the worker's features are the scheduler's own objects and keeping the data costs no memory.Recipe, third commit:
target_offpolicy_stepsdefaults to 7. With zero-std groups dropped, the run needs ~118 generated groups per step for 32 kept ones, so rollout supply is capped by the controller's active groups,(target_offpolicy_steps + 1) x P, not by the number of generators.Unchanged: Qwen3.5's M-RoPE path (3D positions,
mrope_section), and text-only rendering for Muse Spark.Alternatives considered
target_offpolicy_steps: at 3, two more generators (48 GPUs) only reach 29.4 s per step, vs 24.0 s at 7 on 32 GPUs.Numerics / performance
Muse Spark Open 816B-A42B on SLAKE, 32 GB300 GPUs (8-GPU trainer, three 8-GPU generators), the recipe's defaults before the third commit (32 x 16,
target_offpolicy_steps3, 10 steps), with #5894 and #5982. The comparison run uses the same configuration on the development branch this PR was ported from. Medians are over steps 5-10.All 2,602 rollouts completed, none truncated. Prompt lengths match, so the Muse Spark image renderer emits the same tokens as the development branch's. Time per request outside the generator (router hop and payload): 13 ms.
target_offpolicy_stepson the same 32 GPUs and tree (medians of steps 5-10):target_offpolicy_stepsAt 7 the trainer never waits: 1.5x the samples per second of 3. All rollouts completed, none truncated.
Testing
<|patch|>run with the file hash; image parts need a vision processor; a bridge places new images after the previous ones;test_scheduler_sends_prefix_cached_image_data_to_the_worker: a request whose prefix-cache hit covers its image still sends the image data to the worker. Fails without the second commit (the data is None).pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/models/common: 1009 passed.pytest tests/rl/unit_tests/cpu/test_slake.py: 18 passed. The 5 failures (test_dapo_mathMath-Verify worker start,test_lora_forwardinductor ABI) fail the same way on the base branch in this environment.Known issues / follow-ups
target_offpolicy_steps7 (mean policy age 4 instead of 1.4). The effect on learning past 10 steps is not measured; the recipe takestarget_offpolicy_stepsas an argument, so a long run that suffers from staleness can lower it.keep_prefix_cached_image_datais a workaround (TODO in code): remove it once vLLM resends a resumed request's dropped data.