[Bug] Qwen2-VL M-RoPE kernel overflows the int32 cos/sin section offset (`bs * sl * hd`) at 2^31 elements
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend, performance
Direzione di ricerca
Inizia leggendo src/liger_kernel/ops/qwen2vl_mrope.py, in particolare _triton_qwen2vl_mrope e i wrapper di forward e backward. Verifica come viene calcolato l’offset della sezione e confrontalo con il calcolo int64 fornito nell’issue; gli script di riproduzione e i casi limite segnalati mostrano come verificare l’overflow. Il lavoro è completato quando entrambi i wrapper evitano l’accesso illegale alla dimensione segnalata e le riproduzioni corrispondono al riferimento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🐛 Describe the bug
🐛 Describe the bug
_triton_qwen2vl_mrope in qwen2vl_mrope.py finds the height and width sections of cos and sin, shape (3, bs, sl, hd), at t_cos + bs * sl * hd and h_cos + bs * sl * hd. bs and hd are constexprs and sl is passed as an i32, so the product is int32 (a 32-bit shl/mul.lo of sl in the PTX, then sign-extended). pid is already widened to int64, so the per-token offsets pid * hd and pid * (n_qh * hd) are fine; the section offset is not. Once one section reaches 2^31 elements (bs * sl * hd >= 2**31), the offset wraps to a negative value and every program loads the height and width entries of cos and sin from before the tensors. In practice this is an illegal memory access.
LigerQwen2VLMRopeFunction reaches the kernel in both forward (qwen2vl_mrope_forward) and backward (qwen2vl_mrope_backward), and neither wrapper checks the shape. At hd = 128 it takes bs * sl >= 2**24 tokens in one call (for example bs = 1 and a 16,777,216-token sequence, or bs = 64 at 262,144 tokens). This is unlikely to happen in practice: cos and sin alone are then 12 GiB each in bf16. Still, when it does happen the result is an out-of-bounds access rather than an error. It is the same class of 32-bit offset arithmetic as #1570, #1573 and #1659, and it is still the same on current main (85a9c40):
Reproduce
Reproduce
bs = 1, hd = 128, mrope_section = [16, 24, 24], fp32: sl = 2**24 - 1 puts the height section at 2**31 - 128 elements and sl = 2**24 at 2**31. cos and sin are then 24 GiB each, more than the 8 GB GPU, so the reproduction maps each onto one 1 GiB block of device memory over and over with CUDA's virtual memory API (element j reads element j mod 2**28), with 16 GiB of unmapped address space before it, so a load before the tensor faults (vmm_alias.cpp, repro.py). Two checks, each case in its own process:
- the module's wrapper,
qwen2vl_mrope_forward(q, k, cos, sin, [16, 24, 24]), onq(1, 2, sl, 128)andk(1, 1, sl, 128)mapped the same way (their values not checked); - the kernel launched as the wrapper launches it but on its first 16 programs (each program is one token and reads only its own row), on 16 tokens of
qandkin their own memory, checked againstq1 * cos - q2 * sin,q2 * cos + q1 * sinwith thecosandsinentries each token should read.
| check | sl = 2**24 - 1 |
sl = 2**24 |
sl = 2**24, section offset int64 |
|---|---|---|---|
qwen2vl_mrope_forward |
✅ completes | ❌ illegal memory access | ✅ completes |
| first 16 tokens vs. reference | ✅ 0 of 16 tokens wrong | ❌ illegal memory access | ✅ 0 of 16 tokens wrong |
The fix is to compute the section offset in int64 once:
+ # one section of cos / sin: bs * sl * hd elements, past 2^31 for long sequences
+ section = bs * tl.cast(sl, tl.int64) * hd
t_cos = cos + pid * hd
- h_cos = t_cos + bs * sl * hd
- w_cos = h_cos + bs * sl * hd
+ h_cos = t_cos + section
+ w_cos = h_cos + section
t_sin = sin + pid * hd
- h_sin = t_sin + bs * sl * hd
- w_sin = h_sin + bs * sl * hd
+ h_sin = t_sin + section
+ w_sin = h_sin + section
The patch is attached. tl.cast rather than sl.to(...) because Triton specializes an sl of 1 into a constexpr.
Versions
Versions
torch 2.9.1+cu128, triton 3.5.1, CUDA 12.8, NVIDIA GeForce RTX 4060 Ti (8 GB), driver 595.91.07. Liger-Kernel main @ 85a9c40.
- Lingua principale
- Python
- Stelle
- 6.7k
- Fork
- 673
- Merge medio
- 4g 20h
- PR unite (30g)
- 19
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di linkedin/Liger-Kernel
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
linkedin/Liger-Kernel#1692 ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug] LigerGroupNormFunction.backward crashes on any 4D (N, C, H, W) tensor (H > 1) and hardcodes tl.bfloat16 for float16 inputsForse già presa @shotsan l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
linkedin/Liger-Kernel#1676 · 2 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug] LigerFusedGateUpSiLUMulFunction.backward crashes with shape mismatch on any 3D (B, T, 2*H) input tensorForse già presa @shotsan l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
linkedin/Liger-Kernel#1675 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
[Bug] Silent backward gradient corruption in LigerCrossEntropy on non-contiguous logits (returns raw input logits as dL/dlogits)Forse già presa @shotsan l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
linkedin/Liger-Kernel#1674 ·
I maintainer di solito rispondono entro 3 giorni
-
GroupNorm: int32 batch offset overflows once a sample starts past 2**31 elementsForse già presa @0z5a l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
linkedin/Liger-Kernel#1667 ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di linkedin/Liger-Kernel
Issue simili
-
day_or=True union silently becomes the ISC cron AND bug when a day field expands to its full range (e.g. '0 0 */1 * */2' fires only Sun/Tue/Thu/Sat)Forse già presa @rahul05ranjan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
pallets-eco/croniter#309 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: MLX text downloads omit the requested Hub token and cache directoryForse già presa @abhijithneilabraham l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vllm-project/vllm-metal#1423 ·
I maintainer di solito rispondono entro 1 giorno
-
Growl: a server-rejected notification is reported as a successForse già presa @rahul05ranjan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
gke-labs/kube-agents#7441 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100