Commit 71564da
authored
fix(code_gen): apply 1e-6 float tolerance to LCB stdout comparison (#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 <fgalko@nvidia.com>1 parent ba4d686 commit 71564da
3 files changed
Lines changed: 303 additions & 12 deletions
File tree
- resources_servers/code_gen
- lcb_integration
- tests
Lines changed: 80 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
86 | | - | |
87 | | - | |
| 93 | + | |
| 94 | + | |
88 | 95 | | |
| 96 | + | |
| 97 | + | |
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
| |||
253 | 262 | | |
254 | 263 | | |
255 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
256 | 300 | | |
257 | 301 | | |
258 | 302 | | |
259 | 303 | | |
260 | 304 | | |
261 | 305 | | |
262 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
263 | 322 | | |
264 | 323 | | |
265 | 324 | | |
| |||
304 | 363 | | |
305 | 364 | | |
306 | 365 | | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
311 | 374 | | |
312 | 375 | | |
313 | 376 | | |
| |||
455 | 518 | | |
456 | 519 | | |
457 | 520 | | |
458 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
459 | 527 | | |
460 | 528 | | |
461 | 529 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
Lines changed: 155 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
0 commit comments