Repository navigation
fix(inference): let interrupted runs resume instead of restarting from zero - #143
Open
ddaihao2022 wants to merge 1 commit into
Open
ddaihao2022 wants to merge 1 commit into
ddaihao2022 wants to merge 1 commit into
Conversation
…m zero Closes LLMSQL#122 All four backends called `overwrite_jsonl(output_file)` before generating, even though results are appended batch by batch. A run that crashes at 70% (eighty thousand questions, hours of GPU time or API credits) cannot be continued: re-running wipes the partial file and starts over. Worse, a run that keeps dying at the same point never makes any progress at all — measured on main with 5 questions and a callable that dies after 2: after crash : ['q0', 'q1'] after retry LLMSQL#1 : ['q0', 'q1'] after retry LLMSQL#2 : ['q0', 'q1'] after retry LLMSQL#3 : ['q0', 'q1'] What changed ------------ * `llmsql/utils/inference_utils.py` gains `prepare_benchmark()` (resolve workdir, download/cached questions + tables, apply `limit`, build the `table_id -> table` map) plus `prepare_output_file()` / `skip_completed()`. The setup block was copy-pasted across the four backends, so any fix had to be made four times; it now lives in one place. `prepare_benchmark()` is kept separate from `prepare_output_file()` on purpose, so `limit` is still validated *before* vLLM loads a multi-GB model and the output file is still truncated at exactly the point it used to be. * New `resume: bool = False` argument on `inference_transformers`, `inference_vllm`, `inference_api` and `inference_function`. When `True` and the output file already has completions, the file is kept and the questions it contains are skipped. Without it the behaviour is unchanged. * `_completed_question_ids()` tolerates a half-written final line (the usual shape of a file whose writer was killed): unparseable lines are skipped and the corresponding questions are simply generated again. * CLI: `--resume` / `--no-resume` on all three inference subcommands. Tests ----- `tests/inference/test_inference_resume.py` (13 cases) covers the interrupted run followed by `resume=True` ending up with exactly one line per question, the resume run only generating the missing ids, the default still overwriting, the half-written-line tolerance, and `limit` handling in the new helper. Before: 135 passed. After: 148 passed in `tests/utils` + `tests/inference`. `tests/cli` and `tests/inference/test_limit_argument.py` are unchanged (same 5 + 0 failures as on main); they need `transformers`/`vllm`, which are not installable here, so those suites were not exercised.
This branch has not been deployed
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.
Closes #122
Problem
All four backends (
inference_transformers,inference_vllm,inference_api,inference_function) calloverwrite_jsonl(output_file)before generating, even though results are appended to the file batch by batch. A full run (~80k questions, hours of GPU time or a lot of API credits) that dies at 70% cannot be continued: re-running wipes the partial file and starts from zero.A run that keeps dying at the same point never progresses at all. Measured on
mainwith 5 questions and a callable that dies after 2 completions, retrying three times:What changed
llmsql/utils/inference_utils.py— the setup block (resolve workdir, download/cached questions + tables, applylimit, build thetable_id -> tablemap) was copy-pasted across all four backends, so any fix had to be made four times. It now lives in one place:prepare_benchmark()— everything except the output file, returns aBenchmarkRun;prepare_output_file(output_file, resume=...)— truncates by default exactly as before, or keeps the file and returns the ids already answered;skip_completed(questions, done)— drops the questions already present in the file.prepare_benchmark()andprepare_output_file()are deliberately two calls: it keepslimitvalidation before vLLM loads a multi-GB model, and keeps the output file truncation at exactly the point where each backend used to do it.New
resume: bool = Falseon all four backends. Off by default, so nothing changes unless you ask for it. Withresume=Trueand an existing output file, the answered questions are skipped and the rest are appended.Robustness:
_completed_question_ids()tolerates a half-written final line, which is what a file whose writer got killed normally looks like — unparseable lines are skipped and those questions are simply generated again instead of crashing the resume.CLI:
--resume/--no-resumeoninference transformers|vllm|api.Tests
tests/inference/test_inference_resume.py, 13 cases:resume=Trueends up with exactly one line per question, and only the missing questions are regenerated;resume=Trueskips the ids already in the file;resume=False(default) still truncates — existing behaviour is pinned;resume=Trueon a missing output file starts fresh;prepare_benchmark()applieslimit(int and float) and still rejects0,-1,1.5,0.0.Checklist
Closes #122)--resumeis passedruff checkclean on every touched fileWhat I could not run locally (please check on CI)
transformersandvllmare multi-GB wheels that I cannot install here, so these were exercised only indirectly — they import the same helpers I changed:tests/inference/test_limit_argument.py(needstransformers)tests/inference/test_inference_transformers_*(needstransformers)tests/clitransformers cases (5 failures, present identically onmainhere purely because the module is missing)I verified
tests/utils+tests/inferencego from 135 → 148 passing with no change to the pre-existing failures:The two remaining errors in that set (
test_resolve_workdir_path_creates_tempand one transformers import error) are pre-existing onmainon this machine.