Skip to content

fix(looper): keep a post-loop tail failure inside the failed-run cleanup (#5023) - #5039

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:fix/5023-weight-only-tail-cleanup
Nov 18, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:fix/5023-weight-only-tail-cleanup

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

WeightOnlyLooper.loop() and ModuleLooper.loop() guarded only _loop_impl(...) with the best-effort failure cleanup. The tail that turns the lazy offloaded shell back into an in-session model ran after that guard:

try:
    result = self._loop_impl(**kwargs)
except BaseException:
    ...cleanup...
    raise
self._restore_offloaded_base_modules(strict=True)   # unguarded
self._restore_disk_offloaded_modules()              # unguarded: reads every quantized layer back from disk
self._materialize_meta_base_modules(strict=True)    # unguarded: embed_tokens / norm / rotary_emb
self._materialize_remaining_meta_modules()          # unguarded

A Ctrl-C, an OOM or an I/O error landing there skipped the cleanup entirely: model.embed_tokens, model.norm and rotary_emb stayed on meta and every later in-session forward failed with a meta-tensor error. For RTN the window is about 15% of the run.

Closes #5023.

Fix

looper change
WeightOnlyLooper.loop() the tail moved inside the same try, so a failure there runs the existing recovery (non-strict base-module restore, materialize unreached layers, kernel rehome, version-counter repair, keep the offload root while modules still read from it)
ModuleLooper.loop() the tail is wrapped in its own guard that calls the new _recover_post_loop_tail_failure() before re-raising

_loop_impl has already returned when the GPTQ tail fails, so the in-flight layer and the processors need no work: the recovery restores the base modules, materializes the remaining meta modules, repairs the version counters and keeps the offload root. Every step is best effort so it can never mask the failure that got us there.

Tests

New tests/test_post_loop_tail_failure_5023.py injects one failure at the first call of a tail helper (what an interrupt delivered at that point does; the recovery's later call runs the real helper), then asserts the in-session forward returns finite logits.

python -m pytest tests/test_post_loop_tail_failure_5023.py -q
# 6 passed
# parent commit: 4 of 6 fail --
#   weight_only[restore_disk_offloaded_modules]      NotImplementedError: Cannot copy out of meta tensor
#   weight_only[replace_inference_parameters]        same
#   weight_only[materialize_remaining_meta_modules]  same
#   gptq[restore_offloaded_modules-RuntimeError]     base modules stay on meta
# The two remaining GPTQ nodes (a failure in restore_disk_offloaded_modules /
# materialize_remaining_meta_modules) already left a runnable model on the parent,
# because its layers keep their offload hooks; they are kept as invariants that
# the new recovery must not break.

Related suites (CPU, this host):

python -m pytest tests/test_weight_only_looper.py tests/test_weight_only.py '"\
    tests/test_weight_only_processor_error.py tests/test_cancelled_quantize_default_offload_4860.py '"\
    tests/test_cancelled_quantize_disk_offload_4807.py tests/test_cancelled_quantize_kernel_rehome_4947.py '"\
    tests/test_cancelled_quantize_layer_cleanup_4546.py -q
# 68 passed, 58 skipped, 2 failed
#   the 2 (test_weight_only_looper_respects_dense_and_moe_vram_strategy_devices,
#   test_gguf_forward_requests_dequantized_weight_in_input_dtype) fail identically
#   on the unmodified parent commit in this environment

ruff check on both loopers and the new test: All checks passed.

Logic Flow Documentation

Not applicable: the existing cleanup path is reused; GPTQ gains one best-effort recovery helper.

Model Support / Module Plan

Not applicable: no definition or plan change.

…nup (ModelCloud#5023)

`WeightOnlyLooper.loop()` and `ModuleLooper.loop()` guarded only
`_loop_impl(...)` with the best-effort failure cleanup. The tail that turns the
lazy offloaded shell back into an in-session model ran *after* that guard, so a
Ctrl-C, an OOM or an I/O error landing there skipped the cleanup entirely:
`model.embed_tokens`, `model.norm` and `rotary_emb` stayed on meta and every
later in-session forward failed with a meta-tensor error. For RTN the window is
about 15% of the run, and `_restore_disk_offloaded_modules` reads every
quantized layer back from disk.

Weight-only: the tail now runs inside the same `try`, so a failure there goes
through the existing recovery (non-strict base-module restore, materialize the
unreached layers, kernel rehome, version-counter repair, keep the offload root
while modules still read from it).

GPTQ: the tail is wrapped in its own guard that calls the new
`_recover_post_loop_tail_failure()` before re-raising. `_loop_impl` already
returned, so the in-flight layer and the processors need no work; the recovery
restores the base modules, materializes the remaining meta modules, repairs the
version counters and keeps the offload root, all best effort so it can never
mask the failure.

Regression tests (4 of 6 nodes red on the parent commit):
`tests/test_post_loop_tail_failure_5023.py` injects one failure at the first
call of `restore_disk_offloaded_modules`, `replace_inference_parameters`,
`materialize_remaining_meta_modules` (RTN) and `restore_offloaded_modules` /
`materialize_remaining_meta_modules` (GPTQ), then asserts the in-session
forward returns finite logits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant