livecodebench
genlm.eval.domains.livecodebench
LiveCodeBenchDataset
Bases: Dataset[LiveCodeBenchInstance]
Dataset for LiveCodeBench evaluation (code_generation_lite).
Source code in genlm/eval/domains/livecodebench/livecodebench.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
to_jsonl(path)
Write the (already filtered/split) rows as a snapshot JSONL.
The recommended way to build offline snapshots: load with from_hf,
then to_jsonl — so the snapshot inherits the date window and reloading
it with from_jsonl (which applies no window by default) matches.
Source code in genlm/eval/domains/livecodebench/livecodebench.py
from_hf(release='release_v6', start_date='2024-01-01', end_date=None, difficulties=None, testtypes=None, holdout=None, test_frac=0.3, seed=12345, shuffle=False, max_instances=None, max_tests_per_problem=None, cumulative=True, cache_dir=None)
classmethod
Load+decode livecodebench/code_generation_lite (needs internet / HF cache).
cumulative=True = official version_tag semantics (all problems through
release). Defaults to the full benchmark (holdout=None) with
contest_date >= start_date (2024-01-01 = after the Llama-3.x cutoffs).
holdout='train'/'test' selects a stratified random partition (NOT the
HF split name) — leave it None for leaderboard-comparable numbers.
Source code in genlm/eval/domains/livecodebench/livecodebench.py
from_jsonl(path, start_date=None, end_date=None, difficulties=None, testtypes=None, holdout=None, test_frac=0.3, seed=12345, shuffle=False, max_instances=None)
classmethod
Load a snapshot JSONL written by to_jsonl (offline-friendly).
Unlike from_hf, applies NO date window by default: the snapshot is
taken as-is (it already carries the window it was built with).
Source code in genlm/eval/domains/livecodebench/livecodebench.py
LiveCodeBenchEvaluator
Bases: Evaluator[LiveCodeBenchInstance]
Runs a generation's extracted code against the problem's test cases (strict 0/1).
Results are memoized on (instance_id, extracted code) — under particle-based
inference many responses are byte-identical and the harness is deterministic.
max_total_seconds (optional) caps the per-sample wall-clock budget; see
check_correctness.
Source code in genlm/eval/domains/livecodebench/livecodebench.py
LiveCodeBenchInstance
Bases: Instance
Schema for one LiveCodeBench problem (instance_id is the question_id).
eval_sample is the harness-ready {"input_output": <json str>} payload
(decoded test cases); testtype is stdin or functional.
Source code in genlm/eval/domains/livecodebench/livecodebench.py
default_prompt_formatter(tokenizer, instance, use_chat_format=False, style='generic', enable_thinking=None)
Build the LCB prompt for instance and return token ids.
style="generic" + use_chat_format=True = LLaMa3 lcb_runner style (chat template). style="codeqwen"/"deepseek"/"genericbase" = raw completion strings; genericbase needs the matching evaluator extraction_style. enable_thinking forwards to the chat template (Qwen3 reasoning toggle).
Source code in genlm/eval/domains/livecodebench/livecodebench.py
check_correctness(sample, generation, timeout=6.0, debug=False, max_total_seconds=None)
Run generation against the tests in a forked child.
results is per-test True/False (or sentinel ints -1/-2/-4
on failure). max_total_seconds caps the official per-sample wall-clock budget
of (timeout + 1) * n_tests + 5 — the budget only binds when generated code
hangs in a way signal.alarm can't interrupt, so capping it bounds the stall
from a single pathological generation without affecting normal grading.
Source code in genlm/eval/domains/livecodebench/harness.py
passed_all(sample, generation, timeout=6.0, max_total_seconds=None)
True iff every test passed (> 0), matching official np.all(gen > 0).
Source code in genlm/eval/domains/livecodebench/harness.py
decode_context(context)
Decode a genlm.control context (str/bytes/list of byte tokens or int byte ids) into text.
Source code in genlm/eval/domains/livecodebench/prompts.py
extract_code(model_output, style='generic')
Code between the last two ``` fences (last block if 3+); "" if fewer than two. style="genericbase" = whole stripped output. Matches lcb_runner extract_code.
Source code in genlm/eval/domains/livecodebench/prompts.py
extract_code_prefix(model_output, style='generic')
Code being written, for prefix scoring: text after the last open fence, or
"" when no block is open. Deferring on a closed block (a later block could
supersede it) keeps prefix consistent with extract_code at complete.
style="genericbase" = whole stripped output.
Source code in genlm/eval/domains/livecodebench/prompts.py
format_lcb_prompt(row, tokenizer=None, chat_template=False, style='generic', enable_thinking=None)
Prompt for an lcb_runner LMStyle: "generic" (LLaMa3, via chat template when chat_template=True), "codeqwen" (CodeQwenInstruct, raw <|im_*|> string), or "deepseek" (DeepSeekCodeInstruct, raw ### Instruction/Response string).
enable_thinking forwards to apply_chat_template (Qwen3-style reasoning toggle); left out of the call when None so non-reasoning templates are unaffected.
Source code in genlm/eval/domains/livecodebench/prompts.py
build_row(raw, release, max_tests=None)
Convert a raw HF row into a clean snapshot row with a harness-ready
eval_sample ({"input_output": <json str>}).
Source code in genlm/eval/domains/livecodebench/fetch.py
derive_testtype(metadata, tests)
functional iff a func_name is present (matches run_test's which_type), else fall back to the first test's recorded testtype, else stdin.
Source code in genlm/eval/domains/livecodebench/fetch.py
iter_release_rows(release='release_v6', max_tests=None, cache_dir=None, cumulative=True, raw_filter=None)
Yield clean built rows for a release (needs HF cache).
cumulative=True (official version_tag semantics) loads test.jsonl..testN.jsonl
de-duped by question_id (release_v6 == ~1055); cumulative=False loads only that
window. Dedup keeps the first occurrence, so release = first-seen.
raw_filter is applied to the raw HF row BEFORE the (expensive) private-test
decode, so callers can drop e.g. out-of-window rows cheaply.
Source code in genlm/eval/domains/livecodebench/fetch.py
LCBRuntimeNoErrorPotential
Bases: Potential
0.0 if the extracted code runs without error, -inf otherwise; wrong answers are tolerated. Uses only the public test inputs, never the held-out private ones.
Source code in genlm/eval/domains/livecodebench/runtime_no_error_potential.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
LCBPublicTestPotential
Bases: Potential
Soft public-test verifier. prefix never kills; complete returns
0.0 when all public tests pass, otherwise a finite penalty proportional to
the number of failed tests (floored at min_score, never -inf).
Source code in genlm/eval/domains/livecodebench/public_test_potential.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
run_public_tests(generation)
Run every public test on generation (a full model output; code is
extracted with the configured style) and return structured feedback.
Results are cached per extracted code.
Source code in genlm/eval/domains/livecodebench/public_test_potential.py
PublicTestFeedback
dataclass
Aggregate public-test outcome for a generation, with a repair summary.
Source code in genlm/eval/domains/livecodebench/public_test_potential.py
summary(max_cases=3, max_chars=300)
Human-readable failing-test report for a repair prompt.
Source code in genlm/eval/domains/livecodebench/public_test_potential.py
PublicTestResult
dataclass
Outcome of running a single public test.
Source code in genlm/eval/domains/livecodebench/public_test_potential.py
format_repair_prompt(tokenizer, instance, previous_generation, feedback, use_chat_format=False, style='generic')
Build the next-turn repair prompt for instance and return token ids,
matching the contract of default_prompt_formatter.
Source code in genlm/eval/domains/livecodebench/public_test_potential.py
repair_question_content(question_content, previous_code, feedback)
Augment the original question with the failed attempt and public-test feedback, for a second (repair) generation turn.