FlashAttention Triton Kernel Exceeds Shared Memory Limit on RTX 5090 (SM120)

Aperta
#9 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Read lmdeploy/pytorch/kernels/cuda/flashattention.py, especially flash_attn_varlen_func() and _kernel_meta_sm12x; compare the SM120 configuration with the proposed _kernel_meta_sm86 settings. First reproduce the prefill warmup on an RTX 5090 with the reported model and versions. Done means initialization succeeds and the Triton shared memory error is gone; the report says long-context behavior, concurrency, correctness, and performance still need validation.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

[Bug] FlashAttention Triton Kernel Exceeds Shared Memory Limit on RTX 5090 (SM120)

1. Environment

  • GPU: NVIDIA GeForce RTX 5090
  • GPU Architecture: Blackwell
  • Compute Capability: 12.0 (SM120)
  • LMDeploy: 0.18.0
  • PyTorch: 2.11.0a0+eb65b36914.nv26.02
  • Triton: 3.7.1
  • Model: Intern-Decision-4B
  • Backend: PyTorch Engine

2. Issue Description

When deploying Intern-Decision-4B with LMDeploy 0.18.0 on an NVIDIA RTX 5090, the PyTorch Engine fails during initialization.

The error occurs during the Prefill Warmup stage when executing the Triton FlashAttention kernel.

Error Log
triton.runtime.errors.OutOfResources:
out of resource: shared memory,
Required: 172032,
Hardware limit: 101376.
Reducing block sizes or `num_stages` may help.

This is a secondary error caused by the PyTorch Engine subprocess terminating after the Triton kernel failure.

2.1 Root Cause

The issue originates from the FlashAttention Triton kernel configuration selected for the SM120 architecture.

Relevant source file:

lmdeploy/pytorch/kernels/cuda/flashattention.py

The failure occurs when launching:

_flash_prefill_fwd_kernel[grid](...)

The RTX 5090 has a maximum opt-in shared memory limit of 101376 bytes per thread block, while the selected kernel configuration requires 172032 bytes.

  • Required Shared Memory: 172032 Bytes (168 KiB)
  • Hardware Limit: 101376 Bytes (99 KiB)
  • Excess: 70656 Bytes (69 KiB)

This is a GPU shared memory limitation, not a GPU VRAM or system RAM exhaustion issue.

2.2 Original Kernel Configuration

The RTX 5090 (SM120) enters the following configuration function:

_kernel_meta_sm12x(BLOCK_DK, shared_kv)

For the affected configuration (BLOCK_DK=256), the selected parameters are:

  • BLOCK_M = 64
  • BLOCK_N = 64
  • num_warps = 8
  • num_stages = 3

This configuration exceeds the available shared memory on the RTX 5090.

3. Proposed Workaround

A conservative kernel configuration can be used specifically for SM120 GPUs.

Modify the architecture dispatch logic in flash_attn_varlen_func().

Original code:

elif nv_cap[0] < 10:
    BLOCK_M, BLOCK_N, num_warps, num_stages = _kernel_meta_sm9x(
        BLOCK_DK, shared_kv
    )
else:
    BLOCK_M, BLOCK_N, num_warps, num_stages = _kernel_meta_sm12x(
        BLOCK_DK, shared_kv
    )

Modified code:

elif nv_cap[0] < 10:
    BLOCK_M, BLOCK_N, num_warps, num_stages = _kernel_meta_sm9x(
        BLOCK_DK, shared_kv
    )

elif nv_cap[0] == 12 and nv_cap[1] == 0:
    # RTX 5090 (SM120): conservative shared-memory configuration
    BLOCK_M, BLOCK_N, num_warps, num_stages = _kernel_meta_sm86(
        BLOCK_DK, shared_kv
    )

else:
    BLOCK_M, BLOCK_N, num_warps, num_stages = _kernel_meta_sm12x(
        BLOCK_DK, shared_kv
    )

For BLOCK_DK=256, the resulting configuration is:

  • BLOCK_M = 64
  • BLOCK_N = 32
  • num_warps = 4
  • num_stages = 2

This reduces the tile size, number of warps, and pipeline stages, thereby reducing shared memory consumption.

4. Verification Results

After applying the modification:

  • The Triton shared memory allocation error no longer prevents engine initialization.
  • The PyTorch Engine starts successfully.
  • The Intern-Decision-4B service can be launched on the RTX 5090.

Status: Startup issue resolved with the proposed workaround.

Notes

This workaround has been verified for the following setup:

  • RTX 5090 (SM120)
  • Intern-Decision-4B
  • LMDeploy 0.18.0
  • PyTorch Engine

Further validation is required for long-context inference, concurrent requests, numerical correctness, and performance.

The proposed configuration should be considered a compatibility workaround rather than a universally optimal SM120 configuration.

Lingua principale
Python
Stelle
824
Fork
31
Merge medio
1h 56m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di InternLM/Intern-Decision

Tutte le issue di InternLM/Intern-Decision

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.