Repository navigation
fix(code_gen): make LCB mock sys.stdin.buffer a real byte stream - #2824
Merged
Merged
Conversation
The LCB grader's MockBuffer replayed the first input line on every readline() call and exposed no readlines()/iteration, so submitted solutions that read via sys.stdin.buffer were graded against corrupted input. readline()-based solutions silently scored as wrong answers and readlines()-based solutions raised AttributeError and were recorded as runtime errors, in both cases penalizing correct code. Back MockBuffer with a BytesIO and delegate to it, mirroring how the sibling text mock already delegates to StringIO. This also makes seek() and the rest of the byte-stream API available instead of raising. Note read() is now positional: read() after readline() returns the remainder rather than the whole payload again, matching real stream semantics. This changes LiveCodeBench scores for models that emit sys.stdin.buffer-based solutions. Signed-off-by: fgalko <[email protected]>
agronskiy
approved these changes
Aug 27, 2026
fgalko-oss
added a commit
that referenced
this pull request
Sep 2, 2026
…CB grading Three further false-negative sources in LCB grading, found by diffing against the Nemotron-Cascade evaluation harness and confirmed against real rollouts. stdout.buffer: Capturing swapped sys.stdout for a StringIO, which has no .buffer attribute, so any solution using the sys.stdout.buffer.write fast-output idiom died with AttributeError and was scored a Runtime Error. Capture through a BytesIO with a write_through TextIOWrapper instead, so text and byte writes share one stream and keep their relative order. This is the output-side counterpart of the sys.stdin.buffer fix in #2824. Large integers: the graded environment kept CPython's default 4300-digit cap on int-to-str conversion, so printing a large answer raised ValueError and was also scored a Runtime Error. import_string now raises the limit, alongside the existing recursion-limit bump. Call-based float lists: only scalar predictions got np.allclose, so a returned list of floats within tolerance was scored Wrong Answer. Compare element-wise when both sides are lists. Measured on a 1362-rollout DeepSeek-V4-Flash LiveCodeBench v6 run: 9 of the 16 Runtime Errors are exactly the stdout.buffer AttributeError. Together with the float tolerance fix this recovers 21 rollouts, 93.39% -> 94.93%, which lines up with the 95.05% the Cascade harness reports on the same generations. Deliberately unchanged: case-insensitive Yes/No matching and the 4GB memory cap both alter accept/reject semantics rather than fixing a defect, so they are left for a protocol decision. Signed-off-by: fgalko <[email protected]>
5 tasks done
fgalko-oss
added a commit
that referenced
this pull request
Sep 2, 2026
…2956) ## What does this PR do? Fixes four sources of **false negatives** in LiveCodeBench grading: correct solutions that were scored Wrong Answer or Runtime Error by the grader rather than by any fault of the model. All four were found by diffing against the Nemotron-Cascade evaluation harness and then confirmed against real rollouts from a 1362-rollout DeepSeek-V4-Flash LCB v6 run. | # | Defect | Was scored | Rollouts affected | |---|---|---|---| | 1 | stdout float comparison required exact `Decimal` equality | Wrong Answer | 12 | | 2 | `sys.stdout.buffer.write` crashed (`StringIO` has no `.buffer`) | Runtime Error | 9 | | 3 | int→str limited to CPython's 4300-digit default | Runtime Error | 0 in this run | | 4 | call-based float **lists** never got tolerance | Wrong Answer | 0 in this run | **Measured effect: 93.39% → 94.93%** (1272 → 1293 of 1362). The Cascade harness independently reports **95.05%** on the same generations, so this closes the gap to within roughly one rollout. ## 1. Float tolerance on stdout comparison `grade_stdio` compared answers token-by-token as exact `Decimal`s. Competitive judges accept 1e-6 absolute or relative error, so a correct solution printing `0.333333` against a reference of `0.333333333333` was a false negative. Real examples recovered from the run: | our output | expected | |---|---| | `6.06449510224597965191` | `6.06449510224597979401` | | `0.076923076923077` | `0.076923076923` | | `17.142857142857142` | `17.142857142857142350` | The call-based path already had `np.allclose` (adopted from Nemotron-Cascade's `code_verifier_utils`), so only stdin/stdout problems were affected — which is exactly where float-output problems live (AtCoder `abc374_d`, `abc375_b`, `abc385_f`). **Integers stay exact.** The comment above this comparison explains why the path used `Decimal` rather than `np.isclose`: ``` ## otherwise gotcha: np.isclose(50000000000000000, 50000000000000001) = True ``` That concern is real, so tolerance applies only to tokens that are genuinely floating-point (containing `.` or an exponent). `50000000000000000` vs `50000000000000001` still fails, with a regression test pinning it. Non-finite values are rejected rather than run through the tolerance branch. Worth noting this is stricter than a `float()`-based comparator: parsing with `float()` silently collapses integers above 2^53, so an off-by-one on a 1e18-scale answer would pass. Keeping `Decimal` avoids that. ## 2. `sys.stdout.buffer.write` support `Capturing` replaced `sys.stdout` with a `StringIO`, which has no `.buffer`, so the standard fast-output idiom raised `AttributeError` and was recorded as a Runtime Error. Capture now goes through a `BytesIO` wrapped in a `write_through` `TextIOWrapper`, so text and byte writes share one stream and keep their relative order. This is the output-side counterpart of the `sys.stdin.buffer` fix in #2824. **9 of the 16 Runtime Errors** in the measured run are exactly this `AttributeError`. ## 3. Large integer output The graded environment kept CPython's default 4300-digit cap on int→str conversion, so printing a large answer raised `ValueError` and was scored a Runtime Error. `import_string` now raises the limit, alongside the existing recursion-limit bump. This did not fire in the measured run but will on any problem with a large integer answer. ## 4. Call-based float lists Only scalar predictions were passed to `np.allclose`, so a returned list of floats within tolerance was scored Wrong Answer. Now compared element-wise when both sides are lists. ## Deliberately not changed Two differences from the Cascade harness alter accept/reject semantics rather than fixing a defect, so they are left for a protocol decision rather than folded in here: - **Case-insensitive Yes/No.** The Cascade harness accepts `YES` against `Yes`; this PR does not. Many judges are genuinely case-sensitive, so matching it silently would be a scoring change, not a fix. - **Memory cap.** `reliability_guard` caps at 4 GB here and is uncapped in the Cascade harness. That accounts for the single `MemoryError` in the measured run. ## Test plan - `resources_servers/code_gen/tests/test_float_tolerance.py` (13 tests): tolerance acceptance, per-token enforcement across a line, the large-integer gotcha, small-integer off-by-one, token-count mismatch, scientific notation, non-finite input. - `resources_servers/code_gen/tests/test_grader_environment.py` (13 tests): `stdout.buffer` writes, text/byte write ordering, `close()` as a no-op, stdout restoration, the int→str limit in both directions, call-based float lists including length mismatch and integer lists. - Full code_gen suite green: **33 passed**. - End-to-end through `run_test`: all previously failing idioms now accepted, `YES`/`Yes` still rejected as intended, and the ten float-tolerance cases unregressed in both directions. - Ruff lint, import order and format clean on both changed files (pinned v0.9.9, matching `.pre-commit-config.yaml`). Scores can only move up, and only where the grader was previously wrong. This also removes false negatives from RL code verification, where a wrongly-rejected correct rollout is a bad training signal. ## Checklist - [x] I have read the [contributing guidelines](https://docs.nvidia.com/nemo/gym/latest/contribute/development-setup). - [x] The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs. - [x] Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable). - [x] Pre-commit checks pass locally (`pre-commit run --all-files`) (so CI lint/format/copyright pass). - [x] All commits have DCO sign-off (`git commit -s`) (so the DCO check passes). --------- Signed-off-by: fgalko <[email protected]>
jkyi-nvidia
pushed a commit
that referenced
this pull request
Sep 11, 2026
…2956) ## What does this PR do? Fixes four sources of **false negatives** in LiveCodeBench grading: correct solutions that were scored Wrong Answer or Runtime Error by the grader rather than by any fault of the model. All four were found by diffing against the Nemotron-Cascade evaluation harness and then confirmed against real rollouts from a 1362-rollout DeepSeek-V4-Flash LCB v6 run. | # | Defect | Was scored | Rollouts affected | |---|---|---|---| | 1 | stdout float comparison required exact `Decimal` equality | Wrong Answer | 12 | | 2 | `sys.stdout.buffer.write` crashed (`StringIO` has no `.buffer`) | Runtime Error | 9 | | 3 | int→str limited to CPython's 4300-digit default | Runtime Error | 0 in this run | | 4 | call-based float **lists** never got tolerance | Wrong Answer | 0 in this run | **Measured effect: 93.39% → 94.93%** (1272 → 1293 of 1362). The Cascade harness independently reports **95.05%** on the same generations, so this closes the gap to within roughly one rollout. ## 1. Float tolerance on stdout comparison `grade_stdio` compared answers token-by-token as exact `Decimal`s. Competitive judges accept 1e-6 absolute or relative error, so a correct solution printing `0.333333` against a reference of `0.333333333333` was a false negative. Real examples recovered from the run: | our output | expected | |---|---| | `6.06449510224597965191` | `6.06449510224597979401` | | `0.076923076923077` | `0.076923076923` | | `17.142857142857142` | `17.142857142857142350` | The call-based path already had `np.allclose` (adopted from Nemotron-Cascade's `code_verifier_utils`), so only stdin/stdout problems were affected — which is exactly where float-output problems live (AtCoder `abc374_d`, `abc375_b`, `abc385_f`). **Integers stay exact.** The comment above this comparison explains why the path used `Decimal` rather than `np.isclose`: ``` ## otherwise gotcha: np.isclose(50000000000000000, 50000000000000001) = True ``` That concern is real, so tolerance applies only to tokens that are genuinely floating-point (containing `.` or an exponent). `50000000000000000` vs `50000000000000001` still fails, with a regression test pinning it. Non-finite values are rejected rather than run through the tolerance branch. Worth noting this is stricter than a `float()`-based comparator: parsing with `float()` silently collapses integers above 2^53, so an off-by-one on a 1e18-scale answer would pass. Keeping `Decimal` avoids that. ## 2. `sys.stdout.buffer.write` support `Capturing` replaced `sys.stdout` with a `StringIO`, which has no `.buffer`, so the standard fast-output idiom raised `AttributeError` and was recorded as a Runtime Error. Capture now goes through a `BytesIO` wrapped in a `write_through` `TextIOWrapper`, so text and byte writes share one stream and keep their relative order. This is the output-side counterpart of the `sys.stdin.buffer` fix in #2824. **9 of the 16 Runtime Errors** in the measured run are exactly this `AttributeError`. ## 3. Large integer output The graded environment kept CPython's default 4300-digit cap on int→str conversion, so printing a large answer raised `ValueError` and was scored a Runtime Error. `import_string` now raises the limit, alongside the existing recursion-limit bump. This did not fire in the measured run but will on any problem with a large integer answer. ## 4. Call-based float lists Only scalar predictions were passed to `np.allclose`, so a returned list of floats within tolerance was scored Wrong Answer. Now compared element-wise when both sides are lists. ## Deliberately not changed Two differences from the Cascade harness alter accept/reject semantics rather than fixing a defect, so they are left for a protocol decision rather than folded in here: - **Case-insensitive Yes/No.** The Cascade harness accepts `YES` against `Yes`; this PR does not. Many judges are genuinely case-sensitive, so matching it silently would be a scoring change, not a fix. - **Memory cap.** `reliability_guard` caps at 4 GB here and is uncapped in the Cascade harness. That accounts for the single `MemoryError` in the measured run. ## Test plan - `resources_servers/code_gen/tests/test_float_tolerance.py` (13 tests): tolerance acceptance, per-token enforcement across a line, the large-integer gotcha, small-integer off-by-one, token-count mismatch, scientific notation, non-finite input. - `resources_servers/code_gen/tests/test_grader_environment.py` (13 tests): `stdout.buffer` writes, text/byte write ordering, `close()` as a no-op, stdout restoration, the int→str limit in both directions, call-based float lists including length mismatch and integer lists. - Full code_gen suite green: **33 passed**. - End-to-end through `run_test`: all previously failing idioms now accepted, `YES`/`Yes` still rejected as intended, and the ten float-tolerance cases unregressed in both directions. - Ruff lint, import order and format clean on both changed files (pinned v0.9.9, matching `.pre-commit-config.yaml`). Scores can only move up, and only where the grader was previously wrong. This also removes false negatives from RL code verification, where a wrongly-rejected correct rollout is a bad training signal. ## Checklist - [x] I have read the [contributing guidelines](https://docs.nvidia.com/nemo/gym/latest/contribute/development-setup). - [x] The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs. - [x] Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable). - [x] Pre-commit checks pass locally (`pre-commit run --all-files`) (so CI lint/format/copyright pass). - [x] All commits have DCO sign-off (`git commit -s`) (so the DCO check passes). --------- Signed-off-by: fgalko <[email protected]> Signed-off-by: Junkeun Yi <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The LCB grader's MockBuffer replayed the first input line on every readline() call and exposed no readlines()/iteration, so submitted solutions that read via sys.stdin.buffer were graded against corrupted input. readline()-based solutions silently scored as wrong answers and readlines()-based solutions raised AttributeError and were recorded as runtime errors, in both cases penalizing correct code.
Back MockBuffer with a BytesIO and delegate to it, mirroring how the sibling text mock already delegates to StringIO. This also makes seek() and the rest of the byte-stream API available instead of raising.
Note read() is now positional: read() after readline() returns the remainder rather than the whole payload again, matching real stream semantics. This changes LiveCodeBench scores for models that emit sys.stdin.buffer-based solutions.
What does this PR do?
Checklist
pre-commit run --all-files) (so CI lint/format/copyright pass).git commit -s) (so the DCO check passes).