Skip to content

Block CUDA graphs: auto mode stays off when decoder blocks span several devices - #15931

Merged
danielhanchen merged 2 commits into
mainfrom
block-cg-auto-single-device
Nov 1, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
block-cg-auto-single-device

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #15768. A recheck found that auto mode could turn block CUDA graphs on for a device_map model split over several GPUs. One reviewer reproduced it with the real policy and mocked timing; a second flagged the same gap.

Problem

The auto decision is process-wide, but it reads timing and free memory on one device: the device of the call that completes the measurement. With decoder blocks split over cuda:0 and cuda:1, the measured calls can all land on cuda:0. Passing cuda:0's headroom check then enables graphs on cuda:1 as well. In the mocked repro, cuda:0 reported 40 GiB free and cuda:1 0.01 GiB, and the result was still graphs for every block on both shards.

Before #15768 this setup got no block CUDA graphs unless UNSLOTH_BLOCK_CUDAGRAPHS=1 was set.

Change

Auto mode records the block device at the first probed call. A call on another device turns auto off with the reason "blocks on several devices". The first forward pass visits every shard before any timing starts, so the decision never reaches the timing or memory reads. Explicit UNSLOTH_BLOCK_CUDAGRAPHS=1 is unchanged.

Tests

  • New test_auto_blocks_on_several_devices_keep_graphs_off: two blocks on two (simulated) devices. On main, graphs turn on; here auto stays off and nothing is timed.
  • tests/test_block_cudagraphs_auto.py: 25 passed.
  • Block compile suites: 135 passed, 19 skipped (CUDA only), 1 failed. The failure is test_sm_count_is_read_outside_the_trace, which needs CUDA and fails on main too. All CPU, torch 2.14.1.

GPU results (Colab A100, single GPU, torch 2.13.0 and 2.14.1)

unsloth/Qwen3-0.6B 16-bit LoRA, fixed length 512, 30 steps; head vs merge base, each with UNSLOTH_BLOCK_CUDAGRAPHS=0 and auto.

  • Auto engaged in every auto run (84 graph recordings, 0 graph breaks).
  • Loss vs =0 is within run-to-run noise: max step diff 1.4e-3 - 3.5e-3, against an A/A spread of 0.8e-3 - 2.4e-3; step-1 loss is bitwise identical.
  • Same result with lora_dropout 0.05.
  • Median step: 0.22 - 0.25 s off vs 0.11 s auto.
  • tests/test_block_cudagraphs_{auto,clone,gpu}.py: 80 passed on both versions.

On one GPU this PR changes nothing against its merge base, as intended. The multi-device case only exists with several GPUs; it is covered by the CPU test.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-01T08:26:06.082744Z 64bf864 Manual request
ℹ️ 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 37353cd9e2

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Oct 29, 2026
…15946)

## Summary

`Repo tests (CPU, studio)` is red on main since #15919, and on every PR
based after it (seen on staging for #15928, #15931 and #15934). Three
tests in `tests/studio/test_desktop_reliability_frontend_contract.py`
fail:

- `test_audio_page_matches_the_image_rail_header_and_action_footer`
- `test_images_header_tracks_preview_and_preserves_titlebar_controls`
- `test_media_page_headers_out_stack_the_mac_drag_region`

#15919 rebuilt the Images, Video and Audio headers on purpose: Create /
Train is centred in a `minmax(0,1fr)_auto_minmax(max-content,1fr)` row,
and the API / Library / sibling links moved into the new
`MediaHeaderActions` component, which steps down (pill off centre,
compact, then hidden) as space runs short. The product is right and the
tests pinned the old class strings, so the tests are what changes here.

## What changed

- A shared `_assert_media_header_row` check for the Images and Audio
headers: the new row columns, the pill centred in column 2
(`data-media-header-centre ... col-start-2 justify-self-center`), and
the links rendered inside `<MediaHeaderActions>` (the Library and
sibling links are now asserted to sit inside it, not just somewhere in
the header).
- `MediaHeaderActions` itself is pinned to what the old inline markup
guaranteed: its slot stays `pointer-events-none col-start-3 row-start-1`
(so gaps in the band still drag the macOS window) and only the links'
group is `pointer-events-auto`.
- The macOS drag-region test counts the clickable group drawn by
`MediaHeaderActions` when a page renders it, since that group no longer
appears in the page source.

## Verification

- Base (main at `862098ed4a`): 3 failed, 41 passed. Bisected to #15919:
its parent passes all 44.
- Head: 44 passed.
- Each guard still fails when the property it protects breaks (source
edited, test run, reverted):
  - slot made `pointer-events-auto`: Images and Audio header tests fail
  - links group no longer `pointer-events-auto`: all three fail
- Images sibling link moved out of `MediaHeaderActions`: Images header
test fails
  - Audio pill set to `justify-self-end`: Audio header test fails

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 29, 2026
…eir 2100 s cap (#15951)

## Summary

`Repo tests (CPU, rest)` is close enough to its 2100 s step cap that
slow runners now hit it. On #15931 (staging) it finished `15282 passed
... in 2092.47s` and was then killed with exit 124, so the job went red
after every test had passed. Across 16 staging runs on 2026-10-29 its
pytest step took 1213 s to 2092 s; on the slower runners it sits at 1700
to 1820 s, 81 to 87% of the cap. This is the same thing #15851 did for
the fsdp2 shard.

## What changed

- `rest` is split into `rest` and a new `rest-2`. `rest-2` takes
`tests/diffusion`, `tests/kaggle`, `tests/security` and the top-level
`tests/test_[dimsu]*.py` files, and `rest` ignores the same paths.
`rest` stays the catch-all, so a new folder or file still lands there
without a workflow edit.
- The cut is from a per-file `--durations` run of the old shard (4
workers, 8 cores): those paths are about 1890 of its 3763 test-seconds,
so each half carries about 50%.
- No `*gloo*` or `test_fsdp2*` file starts with d, i, m, s or u, so the
glob root (which `--ignore` cannot filter) never names a file the gloo
or fsdp2 shards also run.
- The two `test_model_registry.py` deselects move with their file into
`rest-2`.
  - The CLI and Docker feature steps stay on `rest`.
- `gloo` is split the same way. It ran 1331 to 2058 s of the same 2100 s
cap across 17 staging runs on 2026-10-29 (#15930's run took 1953 s), so
it is next. Measured per file (4 workers, 8 cores; 4049 test-seconds),
native tensor parallel plus pipeline parallel are about 51% and move to
a new `gloo-tp-pp` shard (`tests/test_tp_n*gloo*.py`,
`tests/test_pp*gloo*.py`); `gloo` keeps everything else through four
globs that exclude those two. A `*gloo*` file matching neither (a new
`test_t[!p]*` or `test_tp[!_]*` name) is reported as dropped by
`test_no_file_is_dropped_or_run_twice`.
- `tests/test_cli_export_unpacking.py` restores `sys.path`. The first
staging run of the split failed 7 tests and errored 4 in the new `rest`
(`test_tiled_mlp_ddp`, `test_reap_prune`,
`test_gc_skip_auto_dist_cells`), each `spawn` child dying with `No
module named 'tests.<file>'`. A per-test `sys.path` watcher over the
full new `rest` shard named the cause: the CLI export run puts
`studio/backend` first on `sys.path`, `studio/backend/tests` is a
package, and the test never took it back out, so every later `spawn`
child in that xdist worker imported the wrong `tests`. It was
order-dependent on main too; the new file distribution just put a spawn
test after it on the same worker. A new
`test_an_export_run_leaves_sys_path_as_it_found_it` checks the run does
change `sys.path` and that it is restored afterwards.
- `tests/test_ci_repo_cpu_shards.py`: the hub-test deselect check now
asserts the deselect sits in the shard that actually collects
`tests/test_model_registry.py`. Before, it only checked the text
appeared anywhere in the matrix, which would still pass with the
deselect left behind on `rest` after the file moved.
- `tests/studio/test_backend_ci_parallel_isolation.py`: expects 11
parallel runs / 8 repo-root shards, and its path reader expands glob
roots the way bash does (it previously treated
`tests/test_fsdp2_*.py`-style roots as literal paths, so no glob shard
could ever be found collecting a file).

## Verification

- `pytest --collect-only` with the old `rest` selection: 18418 tests.
With the new `rest` plus `rest-2`: 9711 + 8707 = 18418, no test in both,
and the union is identical to the old set. The two deselected registry
tests are not collected.
- Same check for gloo: old selection 173 tests, new `gloo` +
`gloo-tp-pp` 89 + 84, no overlap, identical set.
- `tests/test_ci_repo_cpu_shards.py`,
`tests/studio/test_backend_ci_parallel_isolation.py`,
`tests/studio/test_cache_budget_discipline.py`: all pass.
- A probe file `tests/test_tz_probe_gloo.py` (a name neither gloo shard
globs) makes `test_no_file_is_dropped_or_run_twice` fail with that path.
- `pytest tests/test_cli_export_unpacking.py
tests/test_gc_skip_auto_dist_cells.py` in one process: 24 passed with
the restore. Without it the new guard fails (`1 failed, 9 passed`).
- Moving the two deselects back onto `rest` makes
`test_the_deselected_hub_tests_stay_deselected` fail.
- This PR's own CI run is the timing check: each half of both splits
should land near half of its old shard.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 64bf86498a

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit e039edb into main Nov 1, 2026
@danielhanchen
danielhanchen deleted the block-cg-auto-single-device branch November 1, 2026 10: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.

1 participant