Skip to content

[Engine] --layer-split on one GPU: PcieAuto gives the second stage CUDA0's share instead of reading an empty stage list - #7612

Open
JayOfTheKeyboard wants to merge 1 commit into
Niko1221:mainfrom
JayOfTheKeyboard:fix/layer-split-one-gpu-pcie-auto
Open

JayOfTheKeyboard wants to merge 1 commit into
Niko1221:mainfrom
JayOfTheKeyboard:fix/layer-split-one-gpu-pcie-auto

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown

Problem and result

Fixes #7611.

--layer-split K on a machine with one GPU sets split_same. The split has two stages, but stages stays empty because no stage gets its own GPU. When PcieAuto refines the share after a decode window, pcie_auto_step reads stages[st - 1] for every stage after the first. On a same-GPU split that is stages[0] of an empty vector, and the engine dies with a NULL read on the first long, varied prompt. The core dump and the trigger are in the issue.

After this change a stage with no GpuStage of its own takes CUDA0's share. That is the rule the per-request path already uses (generate.cpp:21445, st == 0 || split_same). Multi-GPU splits behave as before.

Related discussion

#7611. This is a focused crash fix, so no scope agreement was needed.

Approach

The rule "which stages entry does stage st use, if any" goes into split_rules.hpp as stage_gpu_index(st, split_same, n_gpu_stages). It returns -1 for stage 0, for a same-GPU split, and for an index past the list. pcie_auto_step calls it and gives CUDA0's share to any stage that gets -1. I put the rule in split_rules.hpp because that file already holds the GPU-free split rules and split_rules_test (already in ctest) tests them without a card.

I checked the other stages[st - 1] reads in generate.cpp. The ones I found sit behind multi_gpu, pipe (which needs !split_same) or an explicit split_same branch. pcie_auto_step was the only unguarded one I found, so the PR touches only that loop.

Validation

Passed:

  • split_rules_test at b38acc8, built with g++ -std=c++20 -Iengine/include on Fedora 44 (x86-64): split_rules_test: ok. It has 7 new checks, including the crashing case (split_same, stage 1, empty list).
  • The test catches the bug. With || split_same removed from the rule it fails at split_rules_test.cpp:281. With the bounds check removed it fails at lines 282 and 283.
  • cmake --preset cpu-check, then a build and ctest (Fedora 44, GCC). At b38acc8: 183 tests, 0 failed, including split_rules_test. At the parent 8db8753: the same result. Both runs skipped the same 4 tests (io_priority_test, expert_multi_test, expert_parity, pool_test).
  • Backend compile checks (backends.yml) at b38acc8, run on my fork: CUDA 12.9, CUDA 13.0, HIP ROCm 7.2 and SYCL oneAPI 2026.1 all compiled (https://github.com/JayOfTheKeyboard/Strata/actions/runs/46649742458).
  • Hardware: RTX 2080 Ti 22 GB (sm_75), one GPU, with --layer-split 24 in the 0.2.23-cuda13 Docker image. The log confirms the same-GPU split: layer split: layers 0-23 (CUDA0), 24-47 (CUDA0). The patched engine is tag v0.2.23 plus this same diff, built for sm_75 (-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=75, Release, CUDA 13.0 toolkit) and added with strata components add-build. It is not built from main, but the diff applies to both unchanged.
    • Control, stock 0.2.23 engine, same config and split: SIGSEGV on the first code prompt (3,253 tokens), then HTTP 503.
    • Patched: code prompts of 3,253, 3,390 and 9,097 tokens, plus prompts of 121, 1,017 and 4,013 tokens. All were answered, with 0 segfaults.
    • The fixed loop did run. PcieAuto produced a new share twice in that run (PCIe share: the CPU pool takes 207 us per missed expert ... -> pcie_frac 0.65, then -> 0.60).
    • split_rules_test also passes in that CUDA build tree (ninja target split_rules_test).

Failed:

None observed.

Not run:

  • The Metal compile. I have no Mac. On the fork the job was cancelled twice before it started ("not acquired by Runner … capacity constraints" for macos-26), so this PR's own CI run is the first Metal build of the change. The change is plain host C++ with no Metal-specific code.
  • Before/after timing. This is a crash fix and changes no default, so I made no performance claim.

Limits

split_rules_test covers the rule, not the call site. If someone later stops calling stage_gpu_index in pcie_auto_step, the test still passes. I found no GPU-free way to drive pcie_auto_step itself.

The rule also returns -1 for a stage past the end of stages on a real multi-GPU split. That stage then gets CUDA0's share instead of crashing. I know of no path that reaches this today.

The per-request reset at generate.cpp:21445 keeps its own inline split_same check. I left it alone to keep this PR to the crash. It could use stage_gpu_index too if you want the rule in one place.

Only PcieAuto's per-stage refinement changes. Whether a same-GPU layer split is a useful setup at all on one card is a separate question. This PR only stops it from crashing.

…are instead of reading an empty stage list (Niko1221#7611)

--layer-split K on a machine with one card sets split_same: the split has two
stages but `stages` stays empty. pcie_auto_step read stages[0] for stage 1 as
soon as a decode window produced a new share, a NULL read (SIGSEGV on the first
long prompt, RTX 2080 Ti). A stage without a GpuStage now takes CUDA0's share,
the rule the per-request path already uses. split_rules::stage_gpu_index holds
the rule; split_rules_test checks it.
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.

[Engine] --layer-split on one GPU: SIGSEGV in pcie_auto_step on the first long prompt (stages[0] of an empty list)

1 participant