Skip to content

Assert offload-state removal only when offload leaves the accelerator - #8738

Merged
delock merged 1 commit into
deepspeedai:masterfrom
delock:pr-q-offload-state-removal-tier
Oct 9, 2026
Merged

delock merged 1 commit into
deepspeedai:masterfrom
delock:pr-q-offload-state-removal-tier

Conversation

@delock

@delock delock commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Description

validate_device in tests/unit/v1/zero/test_offload_states.py requires the contiguous grad buffer to be gone once it is reported on cpu, because a cpu device means offload_states() moved it to the host tier:

if state == OffloadStateTypeEnum.contiguous_grad_buffer and state_device[state] == torch.device("cpu"):
    assert len(get_state_devices(model, state)) == 0, f"State {state} must be removed after offload_states()"

On the cpu accelerator the offload target is the accelerator, so state_device[state] == torch.device("cpu") holds for everything, yet the buffer was never moved anywhere — the assertion fails for every parametrization that includes it.

This is the device-state counterpart of #8409, which gated the memory-delta assertions on allocator_backed_memory_stats for the same reason. Add a sibling offload_leaves_accelerator flag (next to that one) and require it for the removal check.

Behavior

Accelerator offload_leaves_accelerator Effect
CUDA / XPU True assertion unchanged, bit for bit
cpu False state falls through to the device comparison instead, which holds

Validation (executed on real hardware)

20-core x86_64 CPU without AVX512-FP16, gloo backend, 2 ranks (LOCAL_SIZE=2), -n 4:

  • Without this change on master: 16 failed, 112 passed — and all 16 failures are this single assertion (State OffloadStateTypeEnum.contiguous_grad_buffer must be removed after offload_states()).
  • With this change: 128 passed, 0 failed.

So the cpu accelerator keeps the coverage of the other 112 parametrizations instead of losing them to a blanket skip.

The enclosing cpu CI run is #8381, which exercises this file at multi-rank and reports the same result (128 PASSED).

validate_device requires the contiguous grad buffer to be gone once it is
reported on cpu, since a cpu device means offload_states() moved it to
the host tier. On the cpu accelerator the offload target is the
accelerator itself, so the buffer is never moved and the assertion fails
for the parametrizations that include it.

Gate the check on the offload actually crossing memory tiers. The new
flag sits next to allocator_backed_memory_stats, which gates the
memory-delta assertions for the same reason (deepspeedai#8409). On CUDA it is
always true, so the assertion behaves exactly as before; on cpu the
state falls through to the device comparison, which holds.

Measured on cpu/gloo with 2 ranks: 112 of the 128 parametrizations pass
without this change and the 16 failures are all this one assertion; with
the guard the whole file passes. Reported in deepspeedai#8381, where the cpu run
exercises these tests.

Signed-off-by: Guokai Ma <guokai.ma@intel.com>
@sfc-gh-truwase
sfc-gh-truwase added this pull request to the merge queue Oct 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 6, 2026
@delock
delock added this pull request to the merge queue Oct 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 9, 2026
@delock
delock added this pull request to the merge queue Oct 9, 2026
Merged via the queue into deepspeedai:master with commit 1707800 Oct 9, 2026
13 of 15 checks passed
@delock
delock deleted the pr-q-offload-state-removal-tier branch October 9, 2026 07:58
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.

2 participants