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

Abierto Apto para principiantes
#3,568 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Empieza en src/lib/mlxcel-core/src/layers.rs, en QuantizedEmbedding::from_weights_with_mode, y compara su validación con la de UnifiedLinear::from_weights_with_mode. Añade los casos de Scales y Biases demasiado cortos a src/lib/mlxcel-core/src/layers_scales_axes_tests.rs, incluido el recorrido UnifiedEmbedding::from_weights y el caso válido affine_plane(64). Actualiza el comentario de documentación «Used by» y, después, ejecuta los tres comandos de verificación indicados en el issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Rust
Estrellas
505
Forks
81
Merge medio
14 h 2 min
PR fusionados (30 d)
448

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de lablup/mlxcel

Todos los issues de lablup/mlxcel

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.