Skip to content

fix(inference): let interrupted runs resume instead of restarting from zero - #143

Open
ddaihao2022 wants to merge 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-122-resume-interrupted-inference
Open

ddaihao2022 wants to merge 1 commit into
LLMSQL:mainfrom
ddaihao2022:fix-122-resume-interrupted-inference

Conversation

@ddaihao2022

Copy link
Copy Markdown
Contributor

Closes #122

Problem

All four backends (inference_transformers, inference_vllm, inference_api, inference_function) call overwrite_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 main with 5 questions and a callable that dies after 2 completions, retrying three times:

after crash     : ['q0', 'q1']
after retry #1  : ['q0', 'q1']
after retry #2  : ['q0', 'q1']
after retry #3  : ['q0', 'q1']

What changed

llmsql/utils/inference_utils.py — the setup block (resolve workdir, download/cached questions + tables, apply limit, build the table_id -> table map) 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 a BenchmarkRun;
  • 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() and prepare_output_file() are deliberately two calls: it keeps limit validation 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 = False on all four backends. Off by default, so nothing changes unless you ask for it. With resume=True and 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-resume on inference transformers|vllm|api.

Tests

tests/inference/test_inference_resume.py, 13 cases:

  • interrupted run + resume=True ends up with exactly one line per question, and only the missing questions are regenerated;
  • resume=True skips the ids already in the file;
  • resume=False (default) still truncates — existing behaviour is pinned;
  • a truncated final JSON line does not break resume;
  • resume=True on a missing output file starts fresh;
  • prepare_benchmark() applies limit (int and float) and still rejects 0, -1, 1.5, 0.0.

Checklist

  • Copied / readable PR description, referenced issue (Closes #122)
  • Root cause fixed in one shared helper instead of patching each call site
  • Existing behaviour preserved unless --resume is passed
  • Tests added for the new behaviour
  • ruff check clean on every touched file
  • No unrelated files touched

What I could not run locally (please check on CI)

transformers and vllm are 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 (needs transformers)
  • tests/inference/test_inference_transformers_* (needs transformers)
  • tests/cli transformers cases (5 failures, present identically on main here purely because the module is missing)

I verified tests/utils + tests/inference go from 135 → 148 passing with no change to the pre-existing failures:

PYTHONPATH=. pytest tests/utils tests/inference        # 148 passed, 2 skipped

The two remaining errors in that set (test_resolve_workdir_path_creates_temp and one transformers import error) are pre-existing on main on this machine.

…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

No deployments
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.

[Inference] Interrupted runs cannot be resumed — output file is overwritten on every start

1 participant