Repository navigation
Conversation
cudaMemGetInfo reports the current device. ink_cuda_mem_info took a device argument but ignored it, so on a layer split the later stages' expert budgets (and the per-stage checks of elastic global KV growth) were sized from the first GPU's free VRAM. When the first GPU had less room, experts of a later GPU went to host RAM, where they are skipped, and the output was wrong. Switch to the requested device for the query and switch back. Callers that pass no device, or the current one, are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
ink_cuda_mem_info(vfree, vtot, dev)(engine/src/inkling2/cuda/ink_cuda.cuh) takes a device but callscudaMemGetInfo, which always reports the current device. The layer-split code calls it for each stage without switching first, so it gets the first GPU's free VRAM for every stage:InkCudaModel::load_from_model_file, the per-stage expert budget (stage_bud[s]);InkCudaRunner::ensure_global_kv_cap, the per-stage check before growing the global KV.When the first GPU has less free VRAM than a later one, the later GPU's budget is too small. Its overflow experts go to host RAM (tier 2). Host experts only run on stage 0 (
cur_stage == 0inrun_visit), so on the later stagelaunch_ink_moeskips them. The engine runs and the output is wrong, with no error.Measured on two 16 GB cards with
--layer-split 6,18, which puts 18 layers on the second card:main(6a6db7f)With this PR the budget comes from the second GPU's own free VRAM and every expert fits.
Related discussion
None needed: this is a focused fix. I found no existing issue or PR about it.
ink_runner.cuhbut not this function.Approach
When a device is given and it is not the current one, switch to it, query, and switch back. Callers that pass no device, or the current one, get exactly what they got before. That covers every single-GPU path and the EP2 path, which already calls
cudaSetDevice(peer_gpu)before querying.The same
(void)devpath existed on Linux non-UMA builds, so I expect the same effect there. That is unconfirmed static analysis; I have not run Linux.Validation
Environment:
strata-inklingbuilt fromengine/src/inkling2with-DSTRATA_ENABLE_CUDA=ON -DSTRATA_INK_CUDA_ARCHS=120..stratav1.1).mainis 6a6db7f and this PR is 6a6db7f plus this commit, built the same way.CUDA_DEVICE_ORDER=PCI_BUS_ID, so CUDA device 1 is the 5060 Ti and device 0 the 5070 Ti.Passed:
strata-inkling --dump-ref ref.bin --native Inkling-2-Mini-SQ-20.strata --gpus 1,0 --layer-split 6,18 --draft off --max-context 4096 --kv fp16 --prompt-ids <2048 ids>, with this PR. The ids are the first 2048 tokens ofdocs/DETAILS.md.strata-inkling --kld-eval ref.binwith the same flags.main:experts=768+2025 GPU / 279 host (hyb=1),Mean KLD=0.215465 | Top-1=87.05% | PPL=5.085.experts=768+2304 GPU / 0 host (hyb=0),Mean KLD=0.000000 | Top-1=100.00% | PPL=4.040.--chunk(256 / 512 / 1024) moves the mean KLD by about 0.013. That is ordinary rounding between equivalent settings; 0.215 is not.strata-inkling --native ... --draft off --max-context 8192 --gen 64gives the same greedy token ids (md5 of the output) formainand this PR in all three modes:--gpus 1,0 --layer-split auto--gpus 1,0 --layer-split ep2--gpu 1 --gpus 1(one GPU)strata-inkling --selfcheck --native ... --gpus 1,0 --layer-split auto: PASS for both builds.python tools/check --only cmake-cpu,docs: passed (146 passed, 4 skipped; docs 6 passed).python tools/check --only py-tools: 1839 passed, 94 skipped, 2 failed. The same 2 fail onmainin the same environment (see Failed).Failed:
python tools/check --only py-tools:terminal.tools.test_exit_with_parenttest_a_packer_ends_with_the_process_that_started_itandtest_the_control_cli_ends_with_the_host_that_started_it.main(6a6db7f) on this machine (fresh venv withterminal/requirements.txtandrequirements-dev.txt, Python 3.12, Windows 11).terminal/tools, not the engine.Not run:
(void)devpath there; the effect on Linux is unconfirmed static analysis.cudaGetDevice/cudaSetDevice/cudaMemGetInfo.cuda/ink_cuda.cuh.Limits
--layer-split auto --max-context 131072and a ~118K-token prompt on these cards, elastic KV growth still fails at about 66K tokens. That is the growth-step problem in [Engine] strata-inkling CUDA: elastic global KV stops growing at about half of max_ctx, then the request fails (503) #6770 / [Engine] strata-inkling CUDA: budget elastic global KV growth by its real peak #6771, not this one.🤖 Generated with Claude Code