Repository navigation
feat(mm_coding_training): add the visual-coding training environment - #6091
Conversation
Add a training environment for Chart2Code, MMSVG Img2SVG and Text2SVG, Image2Struct LaTeX and Design2Code. The model writes one answer file. A fresh remote sandbox renders it, and a judge model scores the render. The environment has a single-answer catalog entry with simple_agent and an OpenCode catalog entry with a lent task sandbox. Fuxiao Liu wrote this environment in 17 commits, and this commit joins them. The OpenCode configuration declares image input with image_input. Signed-off-by: Fuxiao Liu <[email protected]> [Yi-Fu Wu: removed internal addresses, defaults and evidence documents, and rewrote the internal README sections] Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
The renderer and the OpenCode route need a sandbox image with Matplotlib, CairoSVG, TeX Live, Poppler, Playwright Chromium and OpenCode 1.17.11. Add sandbox_image/Dockerfile. The build runs the dependency preflight of the renderer, so an incomplete image does not build. The OpenCode binary and its SHA-256 are the same as in the visual_coding_opencode image. A local build passed the preflight. Matplotlib, SVG, LaTeX and HTML inputs rendered with no network, as root and as another user. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
Signed-off-by: Fuxiao Liu <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
… check The media check read declared function tools as request content. A tool whose parameter schema has a property named image_url, such as a vision tool, then counted as an unresolved image, so check TE-7 failed for a complete request. Inspect the request without those parameter schemas. Co-authored-by: Fuxiao Liu <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
The catalog check accepted only flat rollout rows, so it refused the
typed {task_id, task_input} rows of an environment that routes a
taskset to a single_agent_turn Environment Server. Parse those rows
with the task input model of their Environment Server. Refuse a typed
row that also has a top-level responses_create_params.
Co-authored-by: Fuxiao Liu <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
The lock was made against a root pyproject.toml with an extra that main does not have. "Check locks" and every `uv sync --locked` of this server failed. uv 0.13.7 removes only those entries. No package version changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
`gym env validate` accepts typed `{task_id, task_input}` rows in a dataset
that declares a taskset, but collation sent every row of such a dataset to
`materialize_task`, which refuses a row that is already a task. So
`gym dataset collate` and the data step of `gym eval run` stopped on the
OpenCode entry. Collation now keeps a typed row of the dataset's own taskset
and refuses a typed row of another taskset.
The OpenCode entry also collated the 5 single-answer example rows of the
base config. It now clears that dataset list, so its example split holds
only the 5 OpenCode rows.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
…nvalid An OpenCode answer could embed the bytes of the reference image, for example as an SVG data URI or a hex literal that a chart program writes over render.png. Its render was then an exact copy, and the judge could give it reward without the task being done. grade_source now refuses a source with a chained run of 1024 or more base64 or hex characters before the grading sandbox starts, and scores it as invalid_artifact. The guard blocks the direct forms. It does not close every copy path, and the README now says so. The 5 example policy answers pass it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
…agent runs The OpenCode Environment Server had no max_concurrent_episodes. Every row was seeded at once and got a 4-CPU, 16 GiB task sandbox, but OpenCode runs 8 sessions at a time. Rows past the first 8 held their sandbox while their 10800 s deadline ran. The server now admits 8 episodes, and the others wait with no sandbox and no running deadline (queue_timeout_seconds: 86400). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
`gym eval reverify` and the end-of-run re-judgment build the /verify body from a fixed list of saved keys. A judge failure of the OpenCode route saves `source_artifact`, `source_sha256` and `source_binding_sha256`, but the list did not carry them. Reverify opens a fresh session, so every reverified OpenCode row came back masked as session_lost. The payload now keeps the three fields, and the server grades the saved source again. A session test runs a real judge failure through `_build_verify_payload` and a fresh-session /verify call. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
…ncelled When a client disconnect or a deadline cancelled /verify during a render, the unshielded `await sandbox.stop()` in the finally block was cancelled too. The grading sandbox then stayed up until its 14400 s TTL. The stop now runs in a shielded anyio scope with the 120 s bound that LentSandboxes uses for its own stop. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
…is unusable The single-answer seed did not read the reference image. With a wrong MM_CODING_REFERENCE_ROOT, every image task was seeded and then masked as verifier_error at /verify, so 4 of the 5 benchmarks stopped training and the run went on. The seed now checks the reference as the OpenCode seed does and answers 422 for a missing or changed image. A reference that changes after the seed is still masked at /verify. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
Both `\s*` in the fence pattern matched newlines. On a completed reply with an unclosed fence, the failed match tried every split of the blank lines, so the time grew with the cube of their count: 5000 blank lines took about 30 s, on the event loop, and every other verify, seed and close of the server waited. The fence whitespace now stays on one line, and leading blank lines are removed in a separate anchored step. The extracted source is the same as before, except that blank lines before the closing fence stay in it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
…at this code The 5 example rollouts came from an earlier version of this code and had no `evaluation_completed` field. The new rows are the 5 single-answer rollouts of a smoke at 96d5f92, with Super 3.5 VL as the policy model, OpenSandbox grading sandboxes and an OpenAI-compatible judge. All 5 were graded, with rewards from 0.64 to 1.0. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
|
/ok to test 7b4e27d |
yfw
left a comment
There was a problem hiding this comment.
SHIP. You can mark this PR ready for review after CI passes. The commits after 2f76845 fix each comment of this review, and a smoke ran at the fixed code.
The comments below point at 2f76845. This summary is for the head 7b4e27d. The design of the environment is sound. The resources server lends the OpenCode task sandbox with a model_only network. Grading reads the answer file, so any harness with shell and file tools can solve the task. The seed and close hooks are typed, and a test runs the resources session contract.
These commits fix the comments below:
- f41ea5f regenerates the component lock.
- 20ee5fb keeps typed rows in collation. It also empties the base dataset list of the OpenCode entry, so that entry collates only its 5 OpenCode rows.
- a842821 scores an answer that carries image data as invalid.
- 9b0cbd1 admits only as many OpenCode episodes as the agent runs.
- 7545a05 keeps the saved source fields in the reverify payload.
- 9c60548 stops the grading sandbox after a cancelled render.
- 86fe76b refuses a single-answer seed whose reference image is unusable.
- 96d5f92 matches code fences in linear time.
Each fix in Python has a test that fails without it. "Check locks" passes with the new lock, and gym dataset collate writes 5 rows for each catalog entry. At this head, the 124 server tests pass. The example rollouts now come from a smoke at 96d5f92, and the judge graded all 5 rows.
Process: DCO, Lint, copyright-check, secrets-detector, "Check locks", the core tests, the sandbox tests and 7 of the 8 server-suite shards pass at this head. When this summary was written, server-suite shard 4 was still running. The non-blocking harness conformance job fails with all 11 harnesses "unavailable", and each of its probe jobs passes. "Autobot lock-freshness" fails as an advisory. main changed only the import-linter list in the root pyproject.toml, and after a merge with main the component lock still passes uv lock --check.
Generated by Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
yuhezhang-ai
left a comment
There was a problem hiding this comment.
Thanks for preparing the public version. I reproduced three reward-correctness cases: valid compact SVG code is rejected, missing-answer zeros are dropped during full reverification, and oversized candidate renders are retried then masked. Please address these before approval.
For clarity, the SVG issue is new in the public-release changes. The other two grading gaps existed before the public port and were missed in my earlier review. I also left smaller checker, documentation and source-attribution requests.
Focused environment and core tests pass. The reduced reproductions exercise the verifier with external sandbox/judge transports mocked; I did not rerun live rollouts. The final head still needs its applicable CI.
Recognize encoded raster headers instead of rejecting long drawing commands. Retain a task/response-bound empty-source receipt for measured missing artifacts so full reverification keeps their zeros. Treat successfully rendered candidates exceeding image limits as measured execution failures while retaining infrastructure masks. Cover echoed response tool schemas and document typed taskset collation. Regression probes fail on 7b2ef1d and pass with these fixes. Signed-off-by: Fuxiao Liu <[email protected]>
Resolve the three overlapping regions in environment validation by keeping the typed taskset route map alongside Harbor target metadata, and retaining both validation helpers. Targeted merged-tree regressions: 2207 passed, 81 skipped; a 2-second OpenCode start-wait failure was retained and its full 234-case session suite passed separately. All-file pre-commit passed. Real smoke is being run separately on this exact merged source snapshot. Signed-off-by: Fuxiao Liu <[email protected]>
|
@yfw @yuhezhang-ai I validated public head The fixes are available on this branch:
Validation on merged source tree
Limits / remaining items:
|
A check of the decoded header misses image data that does not start a chain with a known image header. Two such answers get a reward: - an HTML data URL with a space after its first 16 characters (the data URL standard removes spaces before decoding), - raw RGB pixels, or compressed pixels, in a Python answer. Count a chain only when one of its runs has a character outside SVG path data instead. Path data uses only the command letters, digits, "+" and "e", so compact paths still render. The tests add the two answers above. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
…iles The code provenance rule asks for the source URL, revision and license in the header of each file with adapted code. renderer.py and extraction.py now name their source file, the revision b0d39e87f3a30391ae5aeaa02a08ff3cc539f9cc and the Apache-2.0 license. The source repository is NVIDIA-internal and has no public URL, so the headers say that in place of a URL. contract.json is JSON and has no comments, so the README gives the same revision for all three files. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Yi-Fu Wu <[email protected]>
|
Thanks @FuxiaoLiu. I added your two commits to this branch as they are (
Current |
|
/ok to test 08a2c15 |
yuhezhang-ai
left a comment
There was a problem hiding this comment.
Rechecked 08a2c151a1a874bd4c585a90354a1fcaed3bef68 against current main / merge-base 7f2a6634deaeee2d8e11dfdd5e5aec2233744f7f.
All six earlier comments are addressed: compact SVG drawing code is accepted, missing-answer zeros survive full reverification, oversized candidate renders get a measured execution-failure zero, echoed tool schemas are handled, the collation documentation matches the implementation, and release-safe source provenance is recorded. I found no remaining confirmed code defect in these fixes or the additional image-data check.
Validation:
- 1,095 component and relevant core tests passed.
- The three original reproductions plus three size/error-classification controls passed. These use isolated external sandbox/judge transports; they are not live rollouts.
- Eight image-data cases matched the expected classifications, and the five retained single-answer sources pass the final guard.
- Full NVIDIA CI passed on this exact head, including core, sandbox, server-suite, coverage and lock checks. The PR description's statement that this head still needs CI can now be updated.
One validation item remains before approval: the latest reported real smoke predates 2b9ddee308, which changes which answers receive an invalid-artifact zero. The component's validation instructions require a real model/remote-renderer/judge smoke on the reviewed revision. Please record a small representative smoke covering both the single-answer and OpenCode routes with the final guard, including the revision, sandbox image, completed/masked counts and inspected verifier results. The attribution-only change in 08a2c151 does not itself need another model run.
The earlier code findings are cleared; I am holding approval only for that final live-validation evidence.
|
Thanks @yuhezhang-ai. The smoke ran at
What I inspected in each row:
I updated the Validation section of the PR description with this smoke and the CI result on this head. |
yuhezhang-ai
left a comment
There was a problem hiding this comment.
Thanks, this closes the remaining validation request. The reported smoke covers both routes on the reviewed 08a2c151 revision with the final image-data check, and records completed grading, source bindings, judge inspection and cleanup.
All six earlier review comments are addressed, and full NVIDIA CI passes on this revision. I have no further blocking review comments.
|
/ok to test d0703ea |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/43922595156 |
Conflict in tests/unit_tests/data/test_task_data.py: both sides appended tests at the end of the file. Kept the PR's TestFindServerDirRejectsOutputOnlyDirs and TestExternalCwdThroughTheProcessor and main's test_rl_stream_index_is_not_part_of_task_schema (#6091). Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: qiaochuz <[email protected]>
What this PR adds
This PR adds a training environment for four visual-coding task families: Chart2Code, MMSVG (Img2SVG and Text2SVG), Image2Struct LaTeX and Design2Code. The model gets an image or a text task and writes one answer file in Python (Matplotlib), SVG, LaTeX or HTML. A fresh remote sandbox renders the answer. A judge model then scores the task fidelity and the visual fidelity of the rendering. The reward is
execution * (0.2 + 0.8 * Q), whereQis the mean of the two judge scores.Fuxiao Liu wrote the environment.
renderer.py,extraction.pyandcontract.jsonare adapted from NVIDIA's visual-coding RL research code at revisionb0d39e87f3a30391ae5aeaa02a08ff3cc539f9cc:mmrl/render.py,extract_answerinmmrl/artifacts.py, andmmrl/judge_contract.pyandmmrl/reward.py. That repository is NVIDIA-internal and has no public URL. NVIDIA releases these files under Apache-2.0.The PR has two catalog entries:
environments/mm_coding_single: one answer fromsimple_agent.environments/mm_coding_opencode: OpenCode in a task sandbox that the resources server lends throughLentSandboxes. The resources server seeds the task, grades the saved answer file and stops the sandbox.resources_servers/mm_coding_training/configs/mm_coding_mixed.yamlserves both harnesses in one run, for the mixed recipe in NeMo RL.resources_servers/mm_coding_training/sandbox_image/Dockerfilebuilds the sandbox image. The image renders Matplotlib, SVG, LaTeX and HTML answers, and it runs OpenCode 1.17.11 for the OpenCode entry.Two visual environments are already on
main.vision2codescores Python code that recreates an image.visual_coding_opencodescores a boxed answer to a question about an image. This environment scores four output formats, and the reward is zero unless the answer renders.Changes to Gym core
The PR has five small changes to Gym core. Each change has tests. The environment needs changes 1, 3, 4 and 5.
nemo_gym/data/task_data.pyandnemo_gym/data/task_materialization.py:_rowidxis now a reserved row key. NeMo RL adds_rowidxto each row to match streamed results. Without this change, the resources server refuses each flat NeMo RL row (the single-answer route) at seed with a 422 error. Typed rows are not affected. Fuxiao Liu wrote this commit.nemo_gym/rollouts/harness_capabilities/checker.py: the media check of TE-7 ignores the parameter schemas of function tools in the request and in the response, which repeats the request's tools. TE-7 failed for harnesses whose tools take animage_urlargument, such as Hermes'svision_analyze. This environment does not need it.nemo_gym/environment/validation.py: catalog datasets can hold typed{task_id, task_input}rows for a taskset that routes to asingle_agent_turnEnvironment Server. Gym parses each typed row with the task input model of that server. Gym refuses a typed row that also has a top-levelresponses_create_params.environments/mm_coding_opencodeuses typed rows.nemo_gym/data/dataset_preparation.py: collation keeps a typed row whose taskset is the dataset's taskset, and it refuses a typed row of another taskset. Without this change,gym dataset collateand the data step ofgym eval runstop on the OpenCode entry with "Expected a flat dataset row".fern/versions/latest/pages/environment-tutorials/resources-server-apis.mdxnow says this.nemo_gym/eval/rollout_reverification.py: the/verifybody ofgym eval reverifykeeps a savedsource_artifact,source_sha256andsource_binding_sha256. Without this change, every reverified OpenCode row comes back masked assession_lost.What is not in this PR
visionsetting (the same asimage_input),allow_request_output_limit,compaction.pruneand two repeated definitions. The environment uses none of them.mm_coding_multi.yamlsetsimage_input: true.sandbox_observation(). Only the Codex and Hermes harnesses used it, and they are not in this PR.Configuration
resources_servers/mm_coding_training/README.mdlists the environment variables. The sandbox image and the judge model have no default. Before a run, build the image, push it and setMM_CODING_SANDBOX_IMAGEto its digest reference. Then setMM_CODING_JUDGE_MODEL. The judge endpoint defaults tohttps://api.openai.com/v1. The OpenCode entry also needs the SHA-256 pins of the OpenCode binary, ripgrep and the plugin bundle.Validation
All local runs used CPU only. These checks ran at
08a2c151a1a874bd4c585a90354a1fcaed3bef68, which has the review fixes and Fuxiao Liu's merge ofmain:uv lock --checkinresources_servers/mm_coding_trainingwith uv 0.13.7: passed.pytest resources_servers/mm_coding_training/tests, in the venv fromuv sync --locked: 134 passed.pytest tests/unit_tests/data/test_dataset_preparation.py tests/unit_tests/data/test_task_data.py tests/unit_tests/data/test_task_materialization.py: 559 passed.tests/unit_tests/environment: 709 passed.tests/unit_tests/rollouts/harness_capabilities: 289 passed.tests/unit_tests/eval/test_rollout_reverification.py: 250 passed.gym env test mm_coding_singleandgym env test mm_coding_opencode: 3 verifier cases each, passed. Both entries need placeholder values forMM_CODING_SANDBOX_IMAGEandMM_CODING_JUDGE_MODEL, and the OpenCode entry also for itsMM_CODING_*pins.pre-commit run --all-files: passed, with no rewrites.aaea78d066adds: 9 of 12 cases fail with the code of7b2ef1dfad. The other 3 cover cases that already passed. The two cases that2b9ddee308adds fail with the image-data check ofaaea78d066.mainmerges into this head with no conflict.These checks ran at
96d5f920c9. After it, the configs and the data changed only indata/example_rollouts.jsonl, which these checks do not read:gym env validate(5 rows, no warnings) andgym env publishfor both entries: passed.gym dataset collate --mode example_validationon the OpenCode entry: 5 rows.gym env validate --strictwithmm_coding_training.yaml,mm_coding_multi.yamlandmm_coding_mixed.yaml: exit 0.2f768458e7,sandbox_image/Dockerfiledid not change, andrenderer.pychanged only in its header comment. At2f768458e7,docker buildpassed, including the dependency preflight of the renderer (renderer.py --check). In that image, with no network, a Matplotlib chart, an SVG, a LaTeX equation and an HTML page rendered to PNG as root and as another user.CI passed on
08a2c151a1, including the core, sandbox, server-suite, coverage and lock checks.A smoke at
08a2c151a1ran the 5 single-answer and the 5 OpenCode examples, 1 rollout each. The policy model was a hosted Super 3.5 VL, so the run used no GPU. The sandboxes were OpenSandbox sandboxes from the image built fromsandbox_image/Dockerfileat96d5f920c9(digestsha256:6708aba361612f60f56e5b4a0c74220ca8cb25940321f8f0d40dc91a7840951f).sandbox_image/did not change after it. The judge was an OpenAI-compatible endpoint. All 10 rows were graded, and none was masked. The single-answer rewards were 0.66 to 1.0, and the OpenCode rewards were 0.64 to 1.0. Each OpenCode row made 2 to 5 tool calls and saved its answer file. The image-data check found no image data in the 10 saved sources.Earlier smokes had the same counts. A smoke at
96d5f920c9with the same image and judge graded 10 of 10 rows, with none masked. Fuxiao Liu reports a smoke with the fixes ofaaea78d066and the merge ofmain, with an existing sandbox image: 10 of 10 graded, none masked.Rollout evidence:
resources_servers/mm_coding_training/data/example_rollouts.jsonlholds the 5 single-answer rollouts of the smoke at96d5f920c9.Related
Compatibility
Existing environments do not change. A task payload can no longer carry a field named
_rowidx, because change 1 makes it a reserved key. Change 3 adds a row shape and does not change the rows that Gym accepted before. Change 4 changes collation only for typed rows in a dataset with ataskset, which collation refused before. Change 5 adds three keys to the reverify payload, and only this environment saves them.🤖 Generated with Claude Code