Skip to content

[Engine] strata-inkling CUDA: read free VRAM on the GPU asked for, not the current one - #6985

Open
GautamtmD wants to merge 1 commit into
Niko1221:mainfrom
GautamtmD:inkling-mem-info-dev
Open

GautamtmD wants to merge 1 commit into
Niko1221:mainfrom
GautamtmD:inkling-mem-info-dev

Conversation

@GautamtmD

@GautamtmD GautamtmD commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem and result

ink_cuda_mem_info(vfree, vtot, dev) (engine/src/inkling2/cuda/ink_cuda.cuh) takes a device but calls cudaMemGetInfo, 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 == 0 in run_visit), so on the later stage launch_ink_moe skips 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:

Experts in host RAM Mean KLD vs all-VRAM run Top-1 PPL
main (6a6db7f) 279 (second GPU) 0.215465 87.05% 5.085
this PR 0 0.000000 100.00% 4.040

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.

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)dev path 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:

  • Windows 11, RTX 5070 Ti 16 GB (runs the desktop) + RTX 5060 Ti 16 GB, no P2P, driver 621.01.
  • CUDA 13.0, MSVC 14.44.
  • strata-inkling built from engine/src/inkling2 with -DSTRATA_ENABLE_CUDA=ON -DSTRATA_INK_CUDA_ARCHS=120.
  • Model: Inkling-2-Mini SQ-20 (.strata v1.1).
  • main is 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:

  • KLD against an all-VRAM reference.
    • Reference: 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 of docs/DETAILS.md.
    • Evaluation: strata-inkling --kld-eval ref.bin with the same flags.
      • main: experts=768+2025 GPU / 279 host (hyb=1), Mean KLD=0.215465 | Top-1=87.05% | PPL=5.085.
      • This PR: experts=768+2304 GPU / 0 host (hyb=0), Mean KLD=0.000000 | Top-1=100.00% | PPL=4.040.
    • For scale: on one build and split, changing only --chunk (256 / 512 / 1024) moves the mean KLD by about 0.013. That is ordinary rounding between equivalent settings; 0.215 is not.
  • Default path unchanged. strata-inkling --native ... --draft off --max-context 8192 --gen 64 gives the same greedy token ids (md5 of the output) for main and 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 on main in the same environment (see Failed).

Failed:

  • python tools/check --only py-tools: terminal.tools.test_exit_with_parent test_a_packer_ends_with_the_process_that_started_it and test_the_control_cli_ends_with_the_host_that_started_it.
    • They fail identically on unmodified main (6a6db7f) on this machine (fresh venv with terminal/requirements.txt and requirements-dev.txt, Python 3.12, Windows 11).
    • They test process lifetime in terminal/tools, not the engine.
  • Nothing else observed.

Not run:

  • Linux build and run. The changed function also had the (void)dev path there; the effect on Linux is unconfirmed static analysis.
  • CUDA 12.x builds and architectures other than sm_120. The change is host-side C++ inside the header and uses only cudaGetDevice / cudaSetDevice / cudaMemGetInfo.
  • HIP, SYCL, Metal: not applicable. Their Inkling backends use their own sources and do not include cuda/ink_cuda.cuh.
  • 3 or more GPUs.

Limits

🤖 Generated with Claude Code

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>
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