fix(candle): always apply attention masks for Qwen3 and Gemma3 batches - #883
fix(candle): always apply attention masks for Qwen3 and Gemma3 batches#883malaiwah wants to merge 1 commit into
Conversation
|
CUDA validation added on an RTX 5090 host. Environment: I used a validation-only Synthetic no-download regression tests, which are the CI-friendly coverage for the exact equal-length/no-padding mask bug: cargo test -p text-embeddings-backend-candle \
--features cuda \
--test test_qwen3_equal_length_batch \
--test test_gemma3_equal_length_batch \
-- --nocaptureResult: I also ran real-weight CUDA checks through the router, comparing a single-item request against an equal-length batch made from the same text repeated twice.
The synthetic tests remain the upstream regression tests because they are deterministic and require no model download or gated access. The real Qwen3 and Gemma3 checks confirm the same fixed behavior with actual model weights on CUDA. |
What does this PR do?
Fixes #882.
Fixes equal-length batched inference for Qwen3 and Gemma3 on the candle backend.
Why
The previous code only created an attention bias for multi-sequence batches when padding was required. Equal-length batches need no padding, so
attention_biasstayedNone.For Qwen3, that meant the causal mask was skipped.
For Gemma3, the per-layer causal/sliding-window mask is created only when an attention bias tensor is present, so equal-length batches skipped those masks as well.
Single-sequence inference already creates a zero bias and therefore remains correctly masked. As a result, the same text could embed differently alone vs in an equal-length backend batch.
No new runtime dependencies are required. The only manifest change adds
candleas a dev-dependency for synthetic safetensors generation in the new tests.Validation
Using the repository-pinned Rust toolchain from
rust-toolchain.toml:Positive synthetic-weight tests on the fixed branch, CPU, no model download:
cargo test -p text-embeddings-backend-candle --test test_qwen3_equal_length_batch --test test_gemma3_equal_length_batchResult:
Negative evidence, restoring only the old Qwen3 mask gate:
Negative evidence, restoring only the old Gemma3 no-bias behavior:
Formatting:
Before submitting
instasnapshots? Added synthetic-weight Qwen3 and Gemma3 regression tests; noinstasnapshots are needed.Notes
The original Qwen3 issue was also reproduced with real
Qwen/Qwen3-Embedding-0.6Bon CPU in fp32 and fp16, and without MKL. These tests keep the upstream regression coverage small and deterministic enough for CI by using tiny random synthetic weights.