mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[GH-ISSUE #8] Turing (sm_75): the prompt attention asks for 67584 bytes of shared memory (2048 over the 64 KB cap) and the ignored opt-in kills the engine on every long prompt #5
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dummerjindabin on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/8
Environment
2x Titan RTX (sm_75, 24 GB each), 48 GB DDR4, driver 610.57.04, CUDA 12.9/13.0, Ubuntu, Maya-S.
Reproduced on
cfd2f45(v1.0.4).src/kernels/cuda/glm_batch.cuis byte-identical in2b0f1a3(v1.0.6), sothe current main branch still has this.
Symptom
Short prompts and short chats are fine. Any prompt longer than roughly a thousand tokens kills the
engine: it exits, the server restarts it, and the context resets. Per start the engine log shows:
Root cause
mla_attn_kernel(src/kernels/cuda/glm_batch.cu, the F32 prompt-attention kernel, MB_CH = 32,MB_HG = 16) asks for
2048 bytes over Turing's 65536 ceiling, so
fails with cudaErrorInvalidValue — and its return value is discarded:
Every launch of the kernel then fails with "invalid argument", the context is never written, and the
prefill planner aborts a few layers later. The tensor-core path is unavailable on its own account
(
mla_attn_tc_kernelneeds 91136 bytes, sotc_ok[dev] = -1on sm_75 and the F32 kernel is picked)— the comment above it says exactly that, but it misses that the F32 kernel is over the limit too.
That is why the fallback exists and still crashes.
The decode path has the same request:
mla_split_kernel(src/kernels/cuda/glm_fast.cu) asks for(MLA_CHUNK * kv_lora + MLA_HPB * MLA_CHUNK) * sizeof(float)=(32*512 + 16*32) * 4= the same67584 bytes, fails, and silently falls back to the one-pass attention that re-reads the latents once
per head instead of once per chunk.
Fix
The latents are FP16 in global memory already (
uint16_t, read back throughlat_f()). Staging themin shared memory in their own 16-bit form costs half of the float staging and reads back the same
values, so the arithmetic is unchanged (same order, F32 accumulation):
which Turing takes with room to spare. I also check the opt-in's return value in both files instead
of ignoring it, so this class of failure reports itself.
Result (2x Titan RTX, 48 GB RAM)
22k tokens.
invalid argumentandplanned 0 of N routed rowsno longer appear.Related: the tensor-core kernel fits Turing too
Reworking
mla_attn_tc_kernelso the context O lives in the wmma accumulator registers instead ofshared memory (four 16-wide column tiles a warp; the per-chunk online-softmax rescale multiplies the
fragments in place) brings it to
16384 + 32768 + 8192 + 1024 = 58368 bytes, andtc_okthensucceeds on sm_75. With
STRATA_GLM_PREFILL_ATTN_CHECK=1the two kernels agree to rel L2 1.27e-04 /worst head 9.5e-04 (the comment's target is ~1e-3), and prefill at 18.5k tokens measures ~366 tok/s
against ~350 on the F32 kernel — small, because at that length the attention is a minor part of the
prompt path, but it is free.
Happy to send either change as a PR (both are small; I can include the diffs).
@dummerjindabin commented on GitHub (Oct 8, 2026):
Speed report - 2x Titan RTX 24 GB (sm_75), Maya-S, v1.0.6
maya-bench.txtfrom a Turing machine, with the sm_75 shared-memory fix from this issue appliedlocally (without it the engine dies on the first long prompt):
Field notes that may be worth folding into the README's reference table:
reports x16 capability), so pulling one 7 MB expert over PCIe costs 2.1 ms there against 0.7 ms on
the first card; the engine accordingly routes most of that half's RAM-tier experts to its CPU lane
(0.56 ms per expert on the CPU vs 2.12 ms over PCIe).
moe_wait+moe_fetchare 62-72% of theper-token GPU stream time and the CPU lane holds 43-60 ms per token; the prompt attention (
mla)is 2-4% there.
prompt after the warm-up answer, with the page cache still cold - the engine's own lines agree
(6.6 ms/token then 4.2 ms/token). If the two are meant to be compared across machines, the 2k run
may want a preceding dummy prompt.
at 8k on this box is roughly the HBM2 bandwidth ratio (900 vs 672 GB/s) plus 48 vs 64 GB of RAM.
@mw00 commented on GitHub (Oct 8, 2026):
Thank you for this report, and for testing it on real Turing cards. The diagnosis is right:
mla_attn_kernelasks for 67,584 bytes of shared memory, Turing allows 65,536, and the ignored opt-in turns every launch into "invalid argument". RTX 20-series cards have crashed on long prompts since the first release. The v1.0.4 notes said those cards "keep the previous kernel automatically", which assumed that kernel fit. It doesn't.Yes, please send both as a PR, ideally as two commits:
mla_attn_kernelandmla_split_kernel, plus the opt-in return-value checks (this fixes the crash);mla_attn_tc_kernelrework with O in the accumulator fragments (58,368 bytes).That way the crash fix can ship first if the tensor-core change needs more checking. Before merging, we'll run both on Tesla V100 (sm_70), comparing prefill speed and
STRATA_GLM_PREFILL_ATTN_CHECK=1, and then release.One heads-up: the AMD port (#7) halves this kernel's tile (
MB_CH = 16) on HIP for the same 64 KiB limit. With your FP16 staging, the 32-row tile fits on RDNA too, so whichever PR lands second needs a small rebase.@mw00 commented on GitHub (Oct 8, 2026):
Update: since this blocks every RTX 20-series user on long prompts, the crash fix shipped in v1.0.7, written along the lines you described and credited to you.
mla_attn_kernelandmla_split_kernelnow stage the FP16 latents in shared memory (34,816 bytes, under the 48 KB default, so the F32 kernel needs no opt-in at all), and the ignored opt-in is gone.Checked on a Tesla V100 with Maya-S, a 3,000-token prompt and 200 greedy tokens: the default path gives the same tokens before and after. The F32 prompt kernel matches the tensor-core one on every chunk to a relative L2 of ~7e-5 (worst head ~4e-4). We have no Turing card here, so it would be great to hear that v1.0.7 runs your 18.5k-token prompts on the Titan RTX pair.
The tensor-core rework (O in the accumulator fragments, 58,368 bytes) is still very welcome as a PR. It's the part that brings the faster prefill to Turing, and you've already measured it there.
@mw00 commented on GitHub (Oct 8, 2026):
Thank you for the Titan RTX bench and the field notes, and sorry for missing this comment earlier. Two changes come from it:
--benchwill read a warm-up prompt before the 2K measurement, so a cold disk cache doesn't land in the first figure.maya-bench.txt.@dummerjindabin commented on GitHub (Oct 8, 2026):
Tested v1.0.7/v1.0.8 on the Titan RTX pair (2x24 GB, sm_75, Maya-S IQ2_XXS, 96K context), an 18,476-token prompt - the case that used to kill the engine:
shared memory/invalid argument/illegal memory access/planned 0 of ... routed rowslines in the run, and three codes buried at ~2k / 9k / 17k tokens came back 3/3 - so the prompt attention really computes now (before the fix it never ran at all). The engine's own log line tells the two runs apart:prompt attention on the F32 coresvs... on the tensor cores.STRATA_GLM_PREFILL_ATTN=f32, 58 s with the tensor-core kernel (the engine's own figure: 3.4 vs 3.1 ms/tok). Around +10%, which is inside this box's run-to-run spread - on Turing the long-prompt prefill is bound by fetching experts, not by attention, so your V100 A/B is the one that will show the real difference.STRATA_GLM_PREFILL_ATTN_CHECK=1on the new base, over all 110 chunk checks:rel L2 5.3e-5 .. 1.6e-4(median 1.1e-4),worst head 2.5e-4 .. 1.3e-3(median 6.4e-4) - the V100 figures you quoted (~7e-5 / ~4e-4) sit in the same band.The tensor-core rework is up as #10 - one commit, since the crash-fix half is yours in v1.0.7 - with the raw log lines and the A/B recipe in the PR. Thanks for the fast turn-around on #8, and for folding the
--benchnotes into v1.0.8.@mw00 commented on GitHub (Oct 8, 2026):
Confirmed on your Titan RTX pair for v1.0.7, and the tensor-core prefill for Turing ships in v1.0.10 (#10). Closing - thank you for both, and for the field notes.