Repository navigation
fix(code_gen): apply 1e-6 float tolerance to LCB stdout comparison - #2956
Conversation
The stdout grading path compared answers as exact Decimals, so any floating-point output that did not match the reference digit for digit was scored Wrong Answer. Competitive-programming judges accept an absolute or relative error of 1e-6, so a correct solution printing 0.333333 against a reference of 0.333333333333 was a false negative. The call-based path already handles this via np.allclose (adopted from Nemotron-Cascade's code_verifier_utils), so only stdin/stdout problems were affected. AtCoder-style float-output problems are exactly that case. Tolerance is applied only to tokens that are actually floating-point, i.e. containing a decimal point or an exponent. Integers keep exact comparison, which preserves the reason this path used Decimal in the first place: the np.isclose(50000000000000000, 50000000000000001) == True gotcha called out in the comment above the comparison. Non-finite values are rejected rather than compared, so inf/nan cannot pass through the tolerance branch. Adds tests covering tolerance acceptance, per-token enforcement across a line, the large-integer gotcha, token-count mismatch and non-finite input. Signed-off-by: fgalko <[email protected]>
…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]>
|
/ok to test a68488a |
|
/claude review |
|
SHIP WITH CARE Solid, well-tested change to the LiveCodeBench grader. The stdout One RISK (inline, testing_util.py:356): the new call-based float-list branch uses raw Everything else looks correct — no async/API/dependency concerns. |
| if not tmp_result and isinstance(prediction, list) and isinstance(gt_out, list): | ||
| try: | ||
| tmp_result = len(prediction) == len(gt_out) and all( | ||
| np.allclose(float(predicted_item), float(expected_item)) | ||
| for predicted_item, expected_item in zip(prediction, gt_out) | ||
| ) | ||
| except Exception: | ||
| pass |
There was a problem hiding this comment.
RISK — reintroduces the large-integer false positive the rest of this PR guards against.
WHAT BREAKS: this new call-based branch runs np.allclose(float(p), float(e)) element-wise on any list, with no floating-point guard. float(50000000000000001) == float(50000000000000000) == 5e16 (same IEEE-754 double), and np.allclose's default rtol=1e-5 yields a ~5e11 tolerance at that magnitude — so an off-by-one list of large integers is scored correct (tmp_result = True). This is exactly the np.isclose(50000000000000000, 50000000000000001) == True gotcha called out in the stdio path (line ~499) and asserted against in TestIntegersStayExact. The stdio side gates tolerance behind token_is_floating_point; this branch does not.
BLAST RADIUS: call-based LiveCodeBench tasks returning integer lists where the model is numerically close but wrong → silent Wrong-Answer→Correct flips. Corrupts eval scores and any training reward derived from this verifier.
FIX: gate the tolerance on the values actually being floating-point, mirroring decimal_tokens_match — e.g. only fall through to np.allclose when isinstance(predicted_item, float) or isinstance(expected_item, float), and require exact equality for int/int pairs. Or reuse the Decimal-based decimal_tokens_match logic here so both grading paths share one tolerance policy.
Review catch: the new call-based float-list branch ran np.allclose on every element with no type gate, which reintroduced exactly the large-integer false positive the stdio path and this PR's own token_is_floating_point guard defend against. float(50000000000000001) and float(50000000000000000) are the same IEEE-754 double, and np.allclose's default rtol allows ~5e11 at that magnitude, so an off-by-one list of large integers was scored correct. Confirmed against the grader before the fix. The same flaw already existed for scalars: the pre-existing np.allclose(float(prediction), float(gt_out)) line accepted a scalar 50000000000000001 against 50000000000000000. Both now route through one values_are_close helper that only applies tolerance when at least one side is genuinely a float, mirroring the stdio policy, and requires exact equality for integer pairs. Booleans never reach the tolerance branch. Fixing the scalar case tightens behaviour beyond the reported list case: it can only turn silently-accepted wrong answers into correct rejections, never the reverse. Tests pin the reported case (large-int list), the scalar case, a small-int list off by one, the helper's float gate, and boolean handling. Signed-off-by: fgalko <[email protected]>
|
/ok to test 6a7673a |
…son (#3051) ## What does this PR do? Accepts any capitalisation of a `Yes`/`No` verdict in the LiveCodeBench stdout comparison, and only for those two words. Codeforces-style statements print a Yes/No verdict and explicitly accept any capitalisation, so a solution answering `YES` against a reference of `Yes` is correct on the platform but was scored Wrong Answer here. ## Scope Deliberately narrow. Tolerance for capitalisation applies only when the predicted line is exactly `yes` or `no` (in any case) and both sides agree case-insensitively. Every other answer stays case-sensitive, so problems whose answer is a name or a word are unaffected, and a line with more than one token is not treated as a verdict at all. Verified end-to-end through the grader: | submitted | expected | verdict | |---|---|---| | `YES` | `Yes` | accepted | | `no` | `No` | accepted | | `NO` | `Yes` | rejected | | `SNUKE` | `Snuke` | rejected (stays case-sensitive) | | `FIRST` | `First` | rejected (stays case-sensitive) | | `alice` | `Alice` | rejected (stays case-sensitive) | | `YES 1` | `Yes 1` | rejected (multi-token, not a verdict) | ## Why this is separate from #2956 The four changes in #2956 fixed grader faults: correct solutions being scored wrong because of a defect (exact float equality, `StringIO` having no `.buffer`, the int→str digit cap, missing list tolerance). This one is different in kind — it changes accept/reject semantics to match a platform convention, so it deserves its own review rather than riding along. ## Effect on LiveCodeBench scores **None measured on v6.** Across a 1362-rollout DeepSeek-V4-Flash LCB v6 run, none of the 66 wrong-answer failures differ from their reference by capitalisation alone, so the score is unchanged (the run's projected accuracy stays at 94.93%). The behaviour matters for Codeforces-sourced problems rather than the AtCoder/LeetCode mix in v6. ## Test plan - New `resources_servers/code_gen/tests/test_case_insensitive_verdict.py` (14 tests): all capitalisation variants of Yes and No, `yes` not matching `no`, verdicts not matching unrelated answers, other words staying case-sensitive, and multi-token lines rejected. - Full code_gen suite green: 52 passed. - End-to-end through `run_test` on the 7 cases in the table above, all behaving as intended in both directions. - Ruff lint, import order and format clean on both changed files (pinned v0.9.9, matching `.pre-commit-config.yaml`). ## 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]>
…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]>
…son (#3051) ## What does this PR do? Accepts any capitalisation of a `Yes`/`No` verdict in the LiveCodeBench stdout comparison, and only for those two words. Codeforces-style statements print a Yes/No verdict and explicitly accept any capitalisation, so a solution answering `YES` against a reference of `Yes` is correct on the platform but was scored Wrong Answer here. ## Scope Deliberately narrow. Tolerance for capitalisation applies only when the predicted line is exactly `yes` or `no` (in any case) and both sides agree case-insensitively. Every other answer stays case-sensitive, so problems whose answer is a name or a word are unaffected, and a line with more than one token is not treated as a verdict at all. Verified end-to-end through the grader: | submitted | expected | verdict | |---|---|---| | `YES` | `Yes` | accepted | | `no` | `No` | accepted | | `NO` | `Yes` | rejected | | `SNUKE` | `Snuke` | rejected (stays case-sensitive) | | `FIRST` | `First` | rejected (stays case-sensitive) | | `alice` | `Alice` | rejected (stays case-sensitive) | | `YES 1` | `Yes 1` | rejected (multi-token, not a verdict) | ## Why this is separate from #2956 The four changes in #2956 fixed grader faults: correct solutions being scored wrong because of a defect (exact float equality, `StringIO` having no `.buffer`, the int→str digit cap, missing list tolerance). This one is different in kind — it changes accept/reject semantics to match a platform convention, so it deserves its own review rather than riding along. ## Effect on LiveCodeBench scores **None measured on v6.** Across a 1362-rollout DeepSeek-V4-Flash LCB v6 run, none of the 66 wrong-answer failures differ from their reference by capitalisation alone, so the score is unchanged (the run's projected accuracy stays at 94.93%). The behaviour matters for Codeforces-sourced problems rather than the AtCoder/LeetCode mix in v6. ## Test plan - New `resources_servers/code_gen/tests/test_case_insensitive_verdict.py` (14 tests): all capitalisation variants of Yes and No, `yes` not matching `no`, verdicts not matching unrelated answers, other words staying case-sensitive, and multi-token lines rejected. - Full code_gen suite green: 52 passed. - End-to-end through `run_test` on the 7 cases in the table above, all behaving as intended in both directions. - Ruff lint, import order and format clean on both changed files (pinned v0.9.9, matching `.pre-commit-config.yaml`). ## 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]>
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.
Decimalequalitysys.stdout.buffer.writecrashed (StringIOhas no.buffer)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_stdiocompared answers token-by-token as exactDecimals. Competitive judges accept 1e-6 absolute or relative error, so a correct solution printing0.333333against a reference of0.333333333333was a false negative. Real examples recovered from the run:6.064495102245979651916.064495102245979794010.0769230769230770.07692307692317.14285714285714217.142857142857142350The call-based path already had
np.allclose(adopted from Nemotron-Cascade'scode_verifier_utils), so only stdin/stdout problems were affected — which is exactly where float-output problems live (AtCoderabc374_d,abc375_b,abc385_f).Integers stay exact. The comment above this comparison explains why the path used
Decimalrather thannp.isclose:That concern is real, so tolerance applies only to tokens that are genuinely floating-point (containing
.or an exponent).50000000000000000vs50000000000000001still 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 withfloat()silently collapses integers above 2^53, so an off-by-one on a 1e18-scale answer would pass. KeepingDecimalavoids that.2.
sys.stdout.buffer.writesupportCapturingreplacedsys.stdoutwith aStringIO, which has no.buffer, so the standard fast-output idiom raisedAttributeErrorand was recorded as a Runtime Error. Capture now goes through aBytesIOwrapped in awrite_throughTextIOWrapper, so text and byte writes share one stream and keep their relative order.This is the output-side counterpart of the
sys.stdin.bufferfix in #2824. 9 of the 16 Runtime Errors in the measured run are exactly thisAttributeError.3. Large integer output
The graded environment kept CPython's default 4300-digit cap on int→str conversion, so printing a large answer raised
ValueErrorand was scored a Runtime Error.import_stringnow 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:
YESagainstYes; this PR does not. Many judges are genuinely case-sensitive, so matching it silently would be a scoring change, not a fix.reliability_guardcaps at 4 GB here and is uncapped in the Cascade harness. That accounts for the singleMemoryErrorin 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.bufferwrites, 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.run_test: all previously failing idioms now accepted,YES/Yesstill rejected as intended, and the ten float-tolerance cases unregressed in both directions..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
pre-commit run --all-files) (so CI lint/format/copyright pass).git commit -s) (so the DCO check passes).