Skip to content

DeepNVMe: fix silent I/O failures on misaligned buffers - #8985

Merged
xylian86 merged 6 commits into
deepspeedai:masterfrom
xylian86:xinyu/aio-misaligned-io
Nov 7, 2026
Merged

xylian86 merged 6 commits into
deepspeedai:masterfrom
xylian86:xinyu/aio-misaligned-io

Conversation

@xylian86

@xylian86 xylian86 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

DeepNVMe does not check the result of an I/O request, so a request that the kernel fails is reported as done. ZeRO-Infinity reads and writes views into flat buffers at offsets that are often not 512-byte aligned, and O_DIRECT fails those on md RAID, LVM, and before Linux 6.0 on every block device. Swap-ins then leave stale data, swap-outs write nothing, and training goes on with wrong weights and gradients.

This PR checks every completed request: a failed op makes wait(), sync_pread() and sync_pwrite() raise RuntimeError after the other ops complete. Tensors that are not contiguous, or not aligned as the file needs (statx, else 512), go through the existing bounce buffer. ZeRO-Infinity's fast init reads partitions of unaligned length through a padded staging tensor. Also, io_submit errors no longer abort on an assert, io_pgetevents is retried after EINTR, and a failed io_queue_init raises.

Fixes

Before → after, GH200, ext4 on md RAID 0, base 1a956270f:

  1. I/O on a pinned view 416 bytes past an aligned address: nothing moved, success returned → data moved.
  2. ZeRO-3, NVMe parameter offload, Qwen2.5-0.5B: 60 of 290 parameters wrong after initialize → 0; the first loss now equals CPU offload's (12.206690).
  3. ZeRO-3, NVMe optimizer offload, 2 ranks, Qwen2.5 config: losses leave CPU offload's at step 2 → equal.
  4. A write past the file size limit: success with 2048 of 4096 bytes on disk → RuntimeError: ... File too large.
  5. A write to a read-only file, or a signal to an AIO thread during a read: the process aborts on an assert → RuntimeError: ... Bad file descriptor, or the read completes.

DeepNVMe did not check the result of an I/O request, so a request that
the kernel failed was reported as done. ZeRO-Infinity reads and writes
views into flat buffers at offsets that are often not 512-byte aligned,
and O_DIRECT fails those on md RAID, LVM, and before Linux 6.0 on every
block device: swap-ins left stale data and swap-outs wrote nothing.

Every completed request is now checked against the bytes it asked for.
A failed op makes wait(), sync_pread() and sync_pwrite() raise, after
the other pending ops complete. Tensors that are not contiguous, or not
aligned as the file needs (statx on Linux 6.1+, else 512), go through
the bounce buffer, which now has the tensor's shape. The fast init path
reads partitions whose length is not a whole number of blocks through a
padded staging tensor. An io_submit error no longer aborts on an
assert, io_pgetevents is retried after EINTR, and a failed
io_queue_init raises.

Signed-off-by: Xinyu Lian <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T18:41:28.058449Z 079c668 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 079c6681f5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +74 to +76
throw std::runtime_error("deepspeed_aio: io_queue_init(" + std::to_string(queue_depth) +
") failed: " + std::string(strerror(-ret)) +
" (see /proc/sys/fs/aio-nr and aio-max-nr)");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Close caller file descriptors before propagating init failures

When io_queue_init fails because the AIO limit is exhausted or queue_depth is invalid, this new exception escapes after deepspeed_py_aio_read/deepspeed_py_aio_write have already called open_file and stored the descriptor as a raw int; their later close(fd) is therefore skipped. A caller that catches and retries the new RuntimeError leaks one descriptor per attempt and can eventually hit RLIMIT_NOFILE, so the context should be constructed before opening the file or the descriptor should be guarded with RAII.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

aio_read() and aio_write() opened the file and then created their
aio_context, whose constructor now throws when io_queue_init fails: the
descriptor was left open. The context is now created first.

Signed-off-by: Xinyu Lian <[email protected]>
@xylian86
xylian86 added this pull request to the merge queue Nov 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 4, 2026
@xylian86
xylian86 added this pull request to the merge queue Nov 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 4, 2026
@sfc-gh-truwase
sfc-gh-truwase added this pull request to the merge queue Nov 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 5, 2026
xylian86 pushed a commit to xylian86/DeepSpeed that referenced this pull request Nov 7, 2026
…deepspeedai#9020)

## CI: drop the abandoned deepspeed-kernels from the dev requirements

### Problem

When Modal has no GPU within 600 s, `modal-torch-latest` falls back to
AWS. Since deepspeedai#8950 (merged 2026-11-04) that fallback has failed 6 times
out of 6 with `AwsControllerError: AWS prepare failed with exit code 1`,
and no tests ran. Five were merge-queue entries whose PRs were not at
fault (deepspeedai#8985 twice, deepspeedai#8728, deepspeedai#8612, deepspeedai#8842); one was the scheduled run on
master. Examples:
-
https://github.com/deepspeedai/DeepSpeed/actions/runs/41940811586/job/126960989358
-
https://github.com/deepspeedai/DeepSpeed/actions/runs/42061411246/job/127364012408

### Cause

deepspeedai#8950 added `python -m pip check` after "install candidate DeepSpeed" in
`build_remote_commands`. On the AWS environment (uv venv, CPython
3.12.14) it exits 1 with:

```
deepspeed-kernels 0.0.1.dev1698255861 is not supported on this platform
```

`deepspeed-kernels` comes from `requirements/requirements-dev.txt`. Its
only file on PyPI (last release 2023-10-25) is named
`deepspeed_kernels-0.0.1.dev1698255861-py3-none-manylinux1_x86_64.whl`,
but the `WHEEL` file inside it says `Tag: cp38-cp38-linux_x86_64`. pip
installs by the file name (any Python 3) and `pip check` checks the
internal tag (Python 3.8 only). To see the tag:

```
pip download deepspeed-kernels==0.0.1.dev1698255861 --no-deps -d /tmp/dk && unzip -p /tmp/dk/*.whl '*.dist-info/WHEEL'
```

The job logs never show this line: the prepare output is cut at 24,000
characters of stdout (`SSM_INLINE_STDOUT_CHARS`), and the complete
output is fetched only when the test phase fails. I found it by running
the same prepare commands outside CI.

(The Modal sandbox runs the same `pip check` and prints `No broken
requirements found.` with the same package; I could not find out why it
passes there.)

### Change

| Where | What |
|---|---|
| `requirements/requirements-dev.txt` | Remove `deepspeed-kernels`,
which is no longer maintained. |
| `ci/torch_latest.py`: `_emit_ssm_output` | Fetch the complete output
tail for a failed `prepare` phase too, not only `test`, so the next
prepare failure shows its error in the job log. |
| `ci/test_torch_latest.py` | One test for the prepare tail; the fake
AWS CLI returns the prepare output for prepare-phase S3 keys. |

`pip check` itself is unchanged (as deepspeedai#8950 wrote it). The first version
of this PR exempted the `deepspeed-kernels` line instead; following
review, the package is removed rather than exempted.

No active CI job uses `deepspeed-kernels`:
- the inference-v2 kernel tests are deselected by `tests/pytest.ini`
(`not inference_v2_ops`); the only workflow that selected them
(`nv-a6000.yml`) is disabled;
- `nv-pre-compile-ops` builds with `DS_BUILD_CUTLASS_OPS=0
DS_BUILD_RAGGED_DEVICE_OPS=0`;
- it was the only reason `cmake` was installed, and nothing else in
`ci/`, `tests/` or the workflows uses `cmake`.

Not removed: `op_builder/ragged_ops.py` and
`op_builder/inference_cutlass_builder.py` link prebuilt libraries from
the package (`-lblockedflash`, `-ldeepspeedft`) to build the
inference-v2 ragged kernels and CUTLASS MoE / mixed GEMM. Inference v2
is not deprecated (deepspeedai#8489), and DeepSpeed-MII (0.3.3) still installs
`deepspeed-kernels` as a dependency, so those builders keep working for
its users.

The AWS prepare installs the requirements of the candidate commit, so
this change also applies to its own merge-queue run.

### Duplicate check

Searched open PRs and issues on 2026-11-05 for "deepspeed-kernels", "pip
check", "AWS prepare failed" and "capacity fallback": none addresses
this. deepspeedai#8950 added the check; deepspeedai#8921 moved the AWS fallback to Python
3.12.

### Tests

Hardware: CPU only (CI controller code and requirements; no GPU path
changed). Intel Xeon Platinum 8375C, Ubuntu 22.04.5, CPython 3.12.14,
pip 26.3, pytest 8.3.5.

| Command | Result |
|---|---|
| `python ci/test_torch_latest.py` | 50/50 passed (49 existing + 1 new)
|
| `python ci/test_tests_fetcher.py` | 27/27 passed |
| `pre-commit run --files ci/torch_latest.py ci/test_torch_latest.py
requirements/requirements-dev.txt` | all hooks pass |
| the new test against the master version of `ci/` | fails (the prepare
log ends at "AWS prepare failed with exit code 1" without the late line)
|
| the AWS prepare commands rerun from scratch outside CI with this
`requirements-dev.txt` (uv 0.12.7, CPython 3.12.14, the three
requirements files, torch 2.10.0 cu128 pin, Transformers `main`,
DeepSpeed master) | RERUN_RESULT |

`test_aws_prepare_failure_emits_bounded_s3_tail`: a failed prepare whose
output exceeds the inline limit prints the tail, including the last
line, read from the prepare-phase S3 key.

Not run: the real AWS fallback (needs the CI's AWS credentials) and the
Modal sandbox. No workflow runs `ci/test_torch_latest.py`; I ran it by
hand.

### Compatibility

CI and development requirements only. No DeepSpeed runtime code changes,
so no ZeRO stage, offload, precision or parallelism cell is affected.
Users who build the inference-v2 ragged or CUTLASS ops from a source
checkout now install `deepspeed-kernels` themselves (DeepSpeed-MII does
this).

### AI assistance

This change, its tests and this description were prepared with AI
assistance (Claude), which also ran the tests above.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: pengdurice <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@xylian86
xylian86 enabled auto-merge November 7, 2026 08:12
@xylian86
xylian86 added this pull request to the merge queue Nov 7, 2026
Merged via the queue into deepspeedai:master with commit 1b022dc Nov 7, 2026
18 checks passed
@xylian86
xylian86 deleted the xinyu/aio-misaligned-io branch November 7, 2026 09:42
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants