fix(core): validate scales and biases rows in QuantizedEmbedding loading

Aperta Adatta ai principianti
#3,568 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Inizia in src/lib/mlxcel-core/src/layers.rs, in corrispondenza di QuantizedEmbedding::from_weights_with_mode, e confronta la sua validazione con quella di UnifiedLinear::from_weights_with_mode. Aggiungi i casi di Scales e Biases troppo corti a src/lib/mlxcel-core/src/layers_scales_axes_tests.rs, includendo il percorso UnifiedEmbedding::from_weights e il caso valido affine_plane(64). Aggiorna il commento di documentazione «Used by», poi esegui i tre comandi di verifica elencati nell’issue.

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

Descrizione

area:core priority:high status:ready type:security

Problem

QuantizedEmbedding::from_weights_with_mode (src/lib/mlxcel-core/src/layers.rs:375-436) accepts a scales or biases plane with fewer rows than weight. Safetensors files are untrusted input, and with a short plane the lookup reads past the buffer: quantized_embedding (src/lib/mlxcel-core/cpp/mlx_cxx_bridge.cpp:4023-4028) runs take(scales, ids, 0) and take(biases, ids, 0) with token ids bounded only by the weight's row count, and the tied head (as_linear) indexes scales by output row in qmv. The loader only calls reconcile_quantization_layout_logged, which looks at the last axis alone.

Current Behavior

UnifiedLinear::from_weights_with_mode (layers.rs:2912) already calls check_scales_leading_axes (issue #3457), so quantized linears are covered. The embedding loader was missed. PR #3542 patched this only for Lille, in src/models/lille_130m_shapes.rs:109-116 (check_packing). Other families get the check only if they call validate_embedding_table (BailingMoe, Gpt2, GptBigCode, GptNeoX, Mamba, Mamba2, Florence2). Every other UnifiedEmbedding::from_weights caller is unprotected.

Proposed Solution

In QuantizedEmbedding::from_weights_with_mode, call check_scales_leading_axes(prefix, &w_shape, &s_shape, b_shape.as_deref())? before reconciliation, the same way UnifiedLinear does. That covers from_weights and UnifiedEmbedding::from_weights too. Keep Lille's check_packing, which also validates the column count.

Out of scope: QuantizedWeight::new (layers.rs:106) is infallible and its callers build planes by hand; file a follow-up if an audit finds an unchecked caller.

Acceptance Criteria

  • New failing test in src/lib/mlxcel-core/src/layers_scales_axes_tests.rs: QuantizedEmbedding::from_weights_with_mode(&affine_plane(32), "p", 64, 4, "affine") returns an Err that names p.scales, [32, 1] and [64, 8]. Add the same check through UnifiedEmbedding::from_weights, plus a case where only biases is short. affine_plane(64) still loads
  • The existing Lille and validate_embedding_table tests still pass
  • Doc comment on check_scales_leading_axes lists QuantizedEmbedding::from_weights_with_mode under "Used by"

Verification

cargo test -p mlxcel-core --lib layers::scales_axes_tests
cargo test --lib lille_130m
cargo clippy --all-targets -- -D warnings
Lingua principale
Rust
Stelle
505
Fork
81
Merge medio
14h 2m
PR unite (30g)
448

Preparare l'ambiente

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 lablup/mlxcel

Tutte le issue di lablup/mlxcel

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.