feat(xla): RecurrentGemma (RG-LRU + local sliding attention)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 5/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- backend, machine-learning, performance
Direzione di ricerca
Start from src/lib/mlxcel-xla/src/emitter/config.rs at from_json_str (line 561), where recurrent_gemma is rejected, and the layer-mixer helpers is_sliding_layer and sliding_pattern. Then read emitter/model.rs emit_transformer_layer and the reference src/models/recurrent_gemma.rs. Done means the RG-LRU block and hybrid state tensors emit correctly and the synthetic tiny RecurrentGemma matches its HF fp32 oracle token-for-token on hip. This depends on #3348 and #3344, which must land first.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Part of #564
Problem / Background
Epic #564 brings SSM / hybrid / recurrent architectures to the OpenXLA/IREE backend. Design record: spike/openxla/SSM_HYBRID_DESIGN.md (written 2026-07-01; most symbol locations it cites have moved, use the ones in this issue, which were re-located on main at 56bfb92a, and re-verify them before editing). The Stage 2a spike-first pattern this follows is in spike/openxla/STAGE2_DESIGN.md and spike/openxla/FINDINGS_phase2a.md.
RecurrentGemma (Griffin) interleaves RG-LRU recurrent blocks with local sliding-window attention (pattern recurrent, recurrent, attention). from_json_str (src/lib/mlxcel-xla/src/emitter/config.rs:561) rejects recurrent_gemma. MLX reference: src/models/recurrent_gemma.rs.
Goal
RecurrentGemma generates and serves on hip, token-exact and reference-exact.
Scope
- Config
recurrent_gemma:block_typesgiveslayer_mixers(MixerKind::RgLruorAttention);attention_window_sizedrives the sliding mask throughis_sliding_layer(config.rs:1799) /sliding_pattern(config.rs:362); Gemma RMSNorm(1 + w)and embedding scalesqrt(hidden)reuse the existing Gemma paths. - RG-LRU block:
y_branch = gelu(linear_y(x));x_branch = conv1d(linear_x(x))(widthconv1d_width, reusingssm.rsconv1d); gatesr = sigmoid(W_a x + b_a),i = sigmoid(W_x x + b_x)(block-diagonal per head);log_a = -8 * r * softplus(-a_param);h_t = exp(log_a) * h_{t-1} + sqrt(1 - exp(2 log_a)) * (i * x_t)(the multiplier is 1 at position 0, as HF does);out = linear_out(h * y_branch). The recurrence uses #3348's diagonal scan withN = 1:
pub(crate) fn diag_scan_step(b: &mut Builder, log_a: &Val /*[B,D,N]*/, bx: &Val /*[B,D,N]*/, h: &Val /*[B,D,N] f32*/) -> Val;
pub(crate) fn diag_scan_prefill(b: &mut Builder, log_a: &Val /*[T,D,N]*/, bx: &Val /*[T,D,N]*/, readout: Option<&Val> /*[T,N]*/,
h0: &Val /*[D,N] f32*/, chunk: usize) -> (Val /*y [T,D]*/, Val /*h_T [D,N]*/); // readout None requires N == 1
- State tensors, in order:
rglru_h [L_rec, lru_width, 1]F32,rglru_conv [L_rec, K-1, lru_width]F32. Padded rows getlog_a = 0and a zero input term. - Weight names and
weight_specs_qin lock-step; goldens; synthetic tiny RecurrentGemma for an ignored test.
Hybrid contract from #3344 (restated so this issue stands alone): Config::layer_mixers: Vec<MixerKind> (Attention, Mamba2, None for an FFN-only layer, plus variants added by later units) selects the mixer per layer in emit_transformer_layer (src/lib/mlxcel-xla/src/emitter/model.rs:2938); Config::layer_has_ffn(li) selects whether the dense / MoE FFN runs; the KV cache is sized [B, L_attn, S, nkv, d] over attention layers only, and Config::attn_layer_index(li) -> Option<usize> maps a layer to its KV row (used by AttnLayout::write_read_kv and the shim's rg_dims); Config::state_layer_index(li) maps a recurrent layer to its row in each state tensor. The threaded-state ABI is the generic list from Config::state_tensors() (StateTensorSpec { name, dims, elem }), appended after the KV inputs/results in every graph flavor, with the KV region omitted when Config::has_kv_cache() is false.
Acceptance Criteria
- Checkpoint
google/recurrentgemma-2b(gated licence; confirm the id). If the licence is not already accepted on this account, skip the real-checkpoint gates, say so in the PR, and pass the synthetic gates only. - With the checkpoint:
scripts/xla/validate_arch.sh --model models/hf/recurrentgemma-2b --device hip --batch 4 --requests 8 --maxcap 24exits 0; CLI and server gates as in the other hybrids. - Synthetic tiny RecurrentGemma token-exact via CLI vs its HF fp32 oracle and reference-exact via
xla_batch_benchonhip. - Goldens registered; previous goldens byte-identical; fmt, clippy, lib tests clean.
Host and environment
Host: ROCm gfx1151 (Strix Halo, 31 GiB unified memory), IREE hip and llvm-cpu / local-task. Every build and every GPU command runs under scripts/rocm_gpu_guard.sh --hold -- <cmd>.
eval "$(scripts/iree/setup-rocm.sh --env)"
export MLXCEL_XLA_DEVICE=hip MLXCEL_XLA_ROCM_TARGET=gfx1151
export OPENSSL_INCLUDE_DIR=/usr/include OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu CARGO_BUILD_JOBS=6
PY=spike/openxla/.venv/bin/python # or $MLXCEL_ORACLE_PYTHON
scripts/rocm_gpu_guard.sh --hold -- cargo build --release --features xla-iree --bin mlxcel --bin mlxcel-server
Dependencies
Blocked by #3348 (diagonal scan above) and #3344 (hybrid contract above). Blocks #3357, #3358.
Risks
- The sliding window must apply only to the attention layers' KV; with KV over attention layers only,
is_sliding_layermust be evaluated on the original layer index.
User decisions that apply
- Downloads are allowed. If
spike/openxla/.venvis missing, create it withuv venv --python 3.12 spike/openxla/.venvand install CPU torch and transformers as pinned inspike/openxla/requirements.lock(torch==2.12.1+cpu from the PyTorch CPU wheel index, transformers==5.12.1). Small HF-format checkpoints go intomodels/hf/<name>; confirm the exact HF repo id on the model page before downloading. Gated-licence models are skipped and reported unless the licence is already accepted on this account. - Prefix-hash sharing: the recurrent state cannot be rebuilt from a token-prefix hash, so no recurrent model may use the prompt cache or APC on the XLA path. The guard and its test land in #3341; do not attach the prompt-cache store for a config whose
Config::has_recurrent_state()is true.
- Lingua principale
- Rust
- Stelle
- 505
- Fork
- 81
- Merge medio
- 14h 2m
- PR unite (30g)
- 448
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 lablup/mlxcel
-
area:core priority:high status:ready type:security
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
priority:medium status:ready type:security
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
area:models modeltype:text priority:medium status:in-progress type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 57/100
I maintainer di solito rispondono entro 1 giorno
-
area:models priority:low status:ready type:test
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
area:models modeltype:omni priority:medium status:ready type:bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di lablup/mlxcel
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Read a requested CodeRabbit PR review's findings with `coderabbit pullrequest --show-threads`Apertadocumentation priority: low tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
nledford/Ladderback#1823 ·
I maintainer di solito rispondono entro 1 giorno
-
psmux-resurrect: restoring a session with a numeric name puts its windows into the wrong session (`new-window -t 4` is read as window 4)Forse già presa @ealwanlee l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
psmux/psmux-plugins#47 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
I maintainer di solito rispondono entro 1 giorno