Skip to content

feat(gym): add multimodal coding task integration for Megatron - #5122

Merged
yfw merged 54 commits into
NVIDIA-NeMo:mainfrom
FuxiaoLiu:mm-coding-super35-training
Nov 28, 2026
Merged

yfw merged 54 commits into
NVIDIA-NeMo:mainfrom
FuxiaoLiu:mm-coding-super35-training

Conversation

@FuxiaoLiu

@FuxiaoLiu FuxiaoLiu commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Visual-coding tasks need their prepared datasets, private grading metadata and supported Gym routes to reach the existing learner unchanged. This adds a model-neutral adapter and single-answer/OpenCode multi/mixed overlays for a Megatron learner with vLLM generation.

  • Prepare Chart2Code, MMSVG Img2SVG/Text2SVG, Image2Struct LaTeX and Design2Code rows. Preserve original prompts and image bytes; exclude verifier metadata from policy inputs. Require a self-contained OpenCode final answer file; reject Codex and Hermes routes.
  • Load NemoGymDataset explicitly for both splits and retain source task identities. Disable multimodal deduplication because captured rows already carry their own media, including when the supplied VLM base enables deduplication.
  • Default to 32,768 output tokens per call and 65,536 total tokens. Keep MM_CODING_MAX_NEW_TOKENS optional and retain native CLI overrides. Bind vLLM and OpenCode context limits to the policy sequence limit; cap output to remaining context. Prepared rows carry no fixed output limit.
  • Preserve typed TransferQueue columns when registering restored/shared partitions. Leave native GRPO loss, advantage estimation, optimizer code and checkpoint formats unchanged. Provide source/runtime checks and a save/resume operator helper with a four-epoch ceiling for small splits and a preflight check that training uses the guarded checkpoint directory.

Issues

Addresses the previous adapter, dataset, context-budget, runtime, test-lane and helper review findings, plus C33. C33 restores grpo.deduplicate_multimodal_data: false with its setup-time reason; all three overlays inherit it. A subsequent independent team review found three helper/preflight issues: an inherited one-epoch cap that shortened the four-step helper run, checkpoint-directory overrides that diverged from the guarded/inspected path, and nonpositive output budgets accepted by preflight. The first follow-up fixed the epoch and numeric bounds and rejected direct checkpoint redirection. Independent follow-up then identified a remaining dependent-path case: phase-specific logging overrides could change an interpolated checkpoint root after the common preflight. The latest helper builds both complete phase argument arrays, checks both against the guarded checkpoint root before either training process starts, and reuses those same arrays at launch. Publication of the separate independent review report is pending author approval.

Convergence / perf / functionality proof

Validation by revision:

  • Latest phase-complete helper follow-up: 21 actual shell-helper cases passed on macOS Bash 3.2, covering all three modes, with 30 real native configuration preflights. Default and budget-override controls pass both checks; direct, aggregate, duplicate-flag, dependent-path and resume-only redirects stop before any training invocation. The probe stubs module discovery and intercepts six would-be training launches before importing/executing training. No model, provider or checkpoint execution occurs. Shell syntax and diff checks pass. The same 21 helper cases and 30 native preflights also passed on Linux aarch64 (Bash 5.2.21). All 2,738 regular source-file hashes match this commit before and after execution; unchanged files were reused without modification and the two changed files were overlaid as owned copies. The macOS and Linux case outcomes match exactly. These are bounded CPU orchestration/configuration checks, with no actual model, provider, training or checkpoint execution.

The following helper/checker results are for predecessor 44e3427b16554e7f9aa74d08e64a02dfe23a5cda:

  • Current helper/preflight follow-up: macOS CPU 66 passed, zero failures. Linux CPU, exact committed source: 69 passed, zero failures (84.54 seconds), including all three C33 native setup regressions; 366 unrelated setup cases were deselected. All 2,738 source files were SHA-verified before execution. The real shell helper was exercised in 12 intercepted invocations across all three modes: the native clamp and epoch iterator retain four steps for five nonempty split sizes per mode; redirected paths are rejected by real config preflight. The interceptor deliberately stops before training and stubs module discovery. No GPU, model, checkpoint save or checkpoint recovery is executed in that probe.

The following broader validation is for predecessor b39eee391e9313f58b8078762b140997d5e34e4b:

  • The new regression calls native SingleController setup with the composed visual base and a processor. All three modes fail with the original deduplication error before the fix, and pass that guard after it. Model/data/cluster factories are mocked; the test deliberately stops at seed initialization. This is CPU setup evidence, not a GPU run.
  • macOS CPU: 914 passed, 1,765 configuration subtests passed, zero failures. The suite covers the adapter, all SingleController setup tests, config loading and the central shipped-config checks. Existing hardware/optional-dependency and inapplicable schema skips are retained.
  • Linux CPU, exact pushed source: 914 passed, 1,765 configuration subtests passed, zero failures (219.86 seconds), with the same 1,519 skips. All 2,738 RL source files and 538 runtime Python files from the fixed Gym revision were SHA-verified before execution. A first attempt used an unsuitable type-checking environment and stopped during collection on a Torch/torchvision mismatch; its logs are retained. The passing CPU run uses a matched Torch 2.13 / torchvision 0.28 environment with GPUs hidden.
  • Fixed public Gym 041060103fc3fc441eb17142b97c91d4133f34d2: all five task families across both routes pass 20 sibling seed-schema checks. Native sampling middleware applies the default 32,768 output limit. Six native OpenCode cases reach the provider-creation boundary, including default 32,768/65,536 budgets and environment/CLI overrides to 8,192/16,384. These checks make no model calls and create no remote sandboxes.
  • Repository-pinned Ruff, import sorting, formatting, whitespace and shell syntax checks pass for the current follow-up. No fresh full type-check or GPU save/resume result is claimed. The save/resume helper accepts an unset output variable and lets the recipe supply its default; GPU save/resume has not been rerun for this follow-up.

Separately, a real mixed-route visual-model smoke at predecessor f3eb8430fe25f7015fd83a9078ff7c350f867167 completed three native optimizer updates across 16 learner ranks: 48 real scored episodes, 24 per route. Eleven overlong OpenCode rows were masked, leaving 37 gradient-bearing rows. Independent checks verified PPO ratios and clipping, sampling-importance metric normalization, RLOO values, reward/image/sample bindings and actual parameter changes. Maximum absolute PPO-ratio formula error was below 1e-6.

That smoke used 8,192 output tokens, 16,384 total tokens and separately qualified role environments, including a public Gym source override and a genuine fast-hadamard-transform dependency override. It does not qualify the new default 32,768/65,536 budget, the unchanged default lockfile, checkpoint recovery, long-run stability or convergence. Longer contexts require an appropriately sized model runtime and allocation.

Needs upstream changes

The deployment needs the public environment from Gym #6091, including compatible session/token-capture APIs. RL's Gym pin does not contain it yet. The integration guide gives a public Gym commit and source/dependency/cache provisioning steps. This PR does not bump the Gym pin or lockfile; Gym #6451 is not required.

PR commands and CI
  • Update this existing PR only; no automatic merge requested.
  • Runner CI may require maintainer authorization for the new head. Author-side checks do not replace that authorization.
  • The personal-review checkbox remains reserved for the human author.
  • Contributor guidelines.

@copy-pr-bot

copy-pr-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 8, 2026
nvlf added 21 commits November 9, 2026 20:08
Enable the existing VLM entrypoint for all coding recipes. The text workplace parent did not select a processor. Verified five resolved SingleController configurations and the real row90 processor on a source image: CPU pixels [1,3,480,576], 270 image tokens; no model weights or optimizer updates. Focused behavior regressions: 33 passed. GPU training and recovery remain pending.

Signed-off-by: Fuxiao Liu <[email protected]>
@yfw yfw added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 19, 2026
@FuxiaoLiu FuxiaoLiu changed the title feat(gym): add Super VL single, multi and mixed visual coding recipes feat(gym): add multimodal coding task integration for Megatron Nov 20, 2026

@yfw yfw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, Fuxiao, for narrowing this PR.

The PR is now a task integration for the Megatron learner with vLLM generation. It has a row builder, three recipes that compose onto a base recipe, a configuration and runtime check, and a guide. It also has a train-and-resume helper and one TransferQueue fix.

Several parts are in good shape and are worth keeping:

The PR cannot merge yet. Three problems stop the recipes at setup or at the first rollout, and one problem turns unit CI red:

  • (C24) The training split loads the OpenMathInstruct-2 math set instead of the prepared rows.
  • (C17) With the guide's output budget on the test base, Gym refuses every multi and mixed episode at seed.
  • (C23) Gym main refuses every single-answer row that carries problem_id.
  • (C26) A unit test that loads every example recipe fails, because mm_coding_single.yaml needs MM_CODING_BASE_CONFIG when it loads.

Main has moved since this review. The PR now conflicts with main in one file, pyrefly.toml. Since #5298, main checks every Python file under examples/, so the two lines that this PR adds there (#L58-L59) are no longer needed.

What to change, in order

  1. Merge main. Then fix (C24), (C17), (C23) and (C26). These four stop the merge.
  2. (C27) the resume helper fails when it restores the scheduler. (C16) the fixed output limit in each row. (C29) the environment and the overrides of the runtime check. (C28) the Gym revision in the guide.
  3. (C30) a test that no CI lane runs. (C32) a TransferQueue assert that passes with no placeholder. (C31) a checkpoint at every step. (C25) the guide index and scope. (C19) the task ID length cap.

Follow-up, not asked in this PR

The builder copies about nine values that Gym owns. Examples are benchmark names, task fields, image limits, answer file names, sandbox paths, and the taskset and agent names. Assume that one of them drifts, for example an answer file name. Then every OpenCode episode of that family scores a 0 that is not masked, and nothing raises. If the builder lives next to TaskData in Gym, like Gym's deepcad/prepare_opencode.py, Gym's own tests can check the rows.

Copied values, with the RL line and the Gym line for each
Value RL builder Gym server
Benchmark names prepare_mm_coding.py#L38-L44 task_data.py#L11
Task ID limit prepare_mm_coding.py#L45 task_data.py#L19
Answer file names (ARTIFACTS, LANGUAGES) prepare_mm_coding.py#L132-L138 remote_renderer.py#L17-L23
Renderer path /opt/mmrl/render.py prepare_mm_coding.py#L242 session_app.py#L117
Reference path /workspace/reference<ext> prepare_mm_coding.py#L233-L235 session_app.py#L126
Agent name mm_coding_training_simple_agent prepare_mm_coding.py#L269-L272 mm_coding_training.yaml#L30
Taskset name mm-coding:opencode prepare_mm_coding.py#L251 mm_coding_multi.yaml#L13-L14

A second follow-up: a general check in test_shipped_config that every split with the Gym processor loads NemoGymDataset can catch the C24 problem in any recipe. Main's circle-click recipe has the same problem (vlm_grpo-nemotron-omni-30ba3b-circle-click-2n8g-megatron-tp2ep8.v1.yaml#L127-L130), so that fix can go in the same change.

Context, not asked in this PR

  • The recipes need a Gym revision that contains Gym #6091. RL's Gym pin does not contain it yet (C28, mm-coding.md#L40).

  • Two notes on TransferQueue:

    Log noise from the new schema query, and what the fixed bug does on main
    • The new schema query (transfer_queue.py#L1412-L1415) makes the controller log one WARNING ("Partition ... not found" or "Keys [...] were not found") for each register_partition call that adds fields. SFT v2 Energon makes one partition per batch per DP rank (sft_worker.py#L161-L163), so expect one such line per batch. Both warnings come from NeMo RL's own patched kv_retrieve_meta (tq_controller_patch.py#L66-L68, #L80-L83), so a fix can live in NeMo RL.
    • On main, without this PR's fix, a client that re-registers a partition that still holds rows sends float placeholders for integer and boolean columns. One example is the SingleController driver after a SimpleStorage or NIXL restore: it restores (setup.py#L2469-L2473) and then re-registers (#L2548-L2549). The Mooncake path already skips the re-registration after a restore (single_controller.py#L479-L483).
    • The controller then raises on the dtype change (controller.py#L226-L235), logs an ERROR (dtype mismatch) and stops that placeholder's metadata update partway (#L556-L558). The client then clears the placeholder. In a local CPU run, the existing rows read back unchanged.
  • Evidence: this review ran on CPU only, at 04ce237d45 and with the PR merged onto main 95963d732e. The (C26) test also fails with the PR merged onto main 5e2711744e. No CI test job has run on this PR yet.

Thank you again.

Generated by Claude Code

Comment thread docs/guides/mm-coding.md Resolved
Comment thread tests/unit/utils/test_mm_coding.py Resolved
Comment thread docs/guides/mm-coding.md Resolved
@yfw
yfw marked this pull request as ready for review November 23, 2026 07:18

@yfw yfw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, Fuxiao, for fixing every comment from the last review in one push.

All 13 comments are done as asked at f3eb843. This review adds a "fixed in" reply to each thread.

One of our asks was wrong, though. (C25) asked you to delete grpo.deduplicate_multimodal_data: false. SingleController setup needs that line when the base turns multimodal dedup on, as the test base does. So the recipes now fail at setup with such a base. (C33) asks you to put the line back. It is the only change left in this review. Sorry for the extra round.

The four blockers from the last review are fixed:

  • (C24) All three recipes now load only the prepared rows. The new test test_composed_recipe_loads_only_prepared_training_and_validation_rows checks single, multi and mixed.

  • (C17) OpenCode's context window is now the full sequence length (mm_coding_multi.yaml#L24).

  • (C23) Rows no longer carry problem_id. The Gym-marked test test_training_reader_and_processor_preserve_materialized_rows passes against RL's Gym pin.

  • (C26) A session fixture sets the recipe variables (conftest.py#L256-L273). All of tests/unit/utils/test_config.py and tests/unit/test_config_validation.py passes.

  • Evidence: this check ran on CPU only, at f3eb8430fe. The PR merges with main da067f1331 without conflicts. The runs were tests/unit/utils/test_mm_coding.py (with its Gym-marked test against the pinned Gym), tests/unit/utils/test_config.py, tests/unit/test_config_validation.py, the TransferQueue registration test and the (C33) setup repro. The save-and-resume helper and GPU training were not run.

Comment thread docs/guides/mm-coding.md Resolved
Comment thread tests/unit/utils/test_mm_coding.py Resolved
@FuxiaoLiu

Copy link
Copy Markdown
Contributor Author

/ok to test b39eee3

@FuxiaoLiu

Copy link
Copy Markdown
Contributor Author

/ok to test 44e3427

@FuxiaoLiu

Copy link
Copy Markdown
Contributor Author

/ok to test 38038af

@yfw

yfw commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

/ok to test 38038af

@yfw
yfw enabled auto-merge (squash) November 24, 2026 18:15
@yfw

yfw commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

/ok to test 38038af

@yfw

yfw commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

/ok to test 5900329

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 26, 2026
@yfw
yfw merged commit 74dba21 into NVIDIA-NeMo:main Nov 28, 2026
116 of 167 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) community-request Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants