Skip to content

Fix LCB grader failing solutions that read sys.stdin.buffer#1257

Open
vineethsaivs wants to merge 1 commit into
huggingface:mainfrom
vineethsaivs:fix/lcb-grader-stdin-buffer
Open

Fix LCB grader failing solutions that read sys.stdin.buffer#1257
vineethsaivs wants to merge 1 commit into
huggingface:mainfrom
vineethsaivs:fix/lcb-grader-stdin-buffer

Conversation

@vineethsaivs

Copy link
Copy Markdown

What does this PR do?

Fixes #1255.

The LiveCodeBench (LCB) grader's call_method patches sys.stdin with a StringIO:

@patch("sys.stdin", StringIO(inputs))

StringIO has no buffer attribute, so a correct solution that reads binary stdin via sys.stdin.buffer.read() raises AttributeError and is graded as incorrect.

Fix

Expose a binary buffer on the patched stdin, mirroring how LiveCodeBench does it:

mock_stdin = StringIO(inputs)
mock_stdin.buffer = BytesIO(inputs.encode())

Test

Added tests/unit/tasks/test_lcb_codegen_metrics.py::test_call_method_supports_stdin_buffer, which runs a method reading sys.stdin.buffer.read() through call_method and asserts it receives the encoded inputs. The test fails on main (AttributeError) and passes with this change.


Disclosure: prepared with AI assistance; reviewed by me and I can explain every line.

call_method patched sys.stdin with a StringIO, which has no `buffer` attribute,
so solutions doing `sys.stdin.buffer.read()` failed with AttributeError and were
graded as incorrect. Expose a binary buffer on the patched stdin (mirroring
LiveCodeBench). Adds a regression test.

Fixes huggingface#1255

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lighteval's LCB grader fails correct solutions that read sys.stdin.buffer

1 participant