Repository navigation
Limit the memory a generated LiveCodeBench solution can add - #1460
Open
williamcaban wants to merge 1 commit into
Open
williamcaban wants to merge 1 commit into
williamcaban wants to merge 1 commit into
Conversation
run_test calls reliability_guard() without a limit (the comment above the call says 4GB), so a generated solution that allocates in a loop grows until the machine runs out of memory and the operating system kills the whole evaluation, after every answer has been generated. Set RLIMIT_AS in the forked child to the address space it already has plus LIGHTEVAL_LCB_MEMORY_LIMIT_MIB (default 4096, 0 disables). A solution over the limit raises MemoryError and fails that problem. RLIMIT_STACK is not touched, so threads keep their default stack size. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: William Caban <william.caban@gmail.com>
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.
Fixes #1459.
run_testcallsreliability_guard()without a limit although the comment above it says 4GB, so a generated solution that allocates in a loop grows until the machine runs out of memory and the operating system kills the whole evaluation.This sets
RLIMIT_ASin the forked child to the address space it already has (read from/proc/self/status) plusLIGHTEVAL_LCB_MEMORY_LIMIT_MIB(default 4096,0disables). A solution over the limit raisesMemoryErrorand fails that problem; the run continues. The limit is relative to the inherited size because the child is forked from a process that already maps several GiB, so an absolute limit would break correct solutions.RLIMIT_STACKis not changed, so threads keep their default stack size. Where/proc/self/statusorRLIMIT_ASare unavailable (macOS, Windows) it does nothing, as before.Tests (
tests/unit/tasks/test_lcb_solution_memory.py, Linux only) go throughcodegen_metricsand its process pool: an answer that allocates 512 MiB fails with a 128 MiB limit, one that allocates 32 MiB and one that uses a thread pass, and the limit can be turned off. With thelimit_solution_memory()call removed, the first test fails and the others pass. On Linux (Python 3.12, 1.8 GB of RAM) they pass alone, intests/unit/tasksorder, and 6 of 6 times together withtest_lighteval_task.py. The only failures intests/unit/tasksthere are the 8test_registry.pytests, which need Pillow.ruffcheck and format pass.Does not overlap with #1401 (
check_correctnesstarget) or #1257 (grade_stdio).Limits. This bounds the address space, not resident memory. Pages the child inherits and then writes to are copied by the kernel and are not covered (a child that ran
gc.collect()in a ~1.5 GiB parent added about 280 MiB), so memory in use can exceed the limit by a few hundred MiB. The docstring says so. The 4096 MiB default lets a solution add up to 4 GiB to what the process already uses; on a smaller machine, setLIGHTEVAL_LCB_MEMORY_LIMIT_MIBlower.Not covered: a full LiveCodeBench run with this patch against a real model. A 175-problem run in a containerized environment finished without any solution reaching a limit, so it does not exercise this code path; the runaway behaviour was tested with a deliberately greedy solution.
Prepared with Claude Code (Anthropic's AI coding assistant), which helped write the patch, the tests and this text. I reviewed it and am responsible for it. Signed-off-by: William Caban