File size: 3,495 Bytes
4ed1628 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # OpenEmbed: fast linear-attention kernels
OpenEmbed (UCSC-VLAA, Qwen3.5 base) mixes full-attention layers with **gated DeltaNet linear-attention** layers. Transformers runs those layers with fast Triton/CUDA kernels only when two optional packages can be imported; otherwise it falls back to a reference PyTorch loop that is correct but slow.
## Findings
- **The published OpenEmbed speeds first came from the slow path.** None of the benchmark environments had the kernel packages, so the linear-attention layers ran in plain PyTorch.
- **Two packages are needed:** `flash-linear-attention` (Triton kernels for the gated delta rule) and `causal-conv1d` (CUDA kernel for the short convolution). Transformers 5.25.1 picks both up automatically for Qwen3.5 models.
- **Gotcha: `flash-linear-attention` β₯ 0.3 ships its kernels in a separate package, `fla-core`.** Installed without its dependencies, `import fla` works but `fla.ops` is missing, and Transformers silently stays on the slow path (identical embeddings, identical speed). Check with `python -c "from fla.ops.gated_delta_rule import chunk_gated_delta_rule"`.
- **`causal-conv1d` has no prebuilt wheel for PyTorch 2.15 + CUDA 13**; it compiles from source (version 1.7.0, about 8 minutes with 24 parallel jobs, `TORCH_CUDA_ARCH_LIST=8.9`).
- **Warm up with queries too.** Triton compiles kernels for each new input shape. Without a query warm-up, the first timed query pass included that compilation and OpenEmbed-0.8B looked slower on queries than the PyTorch path (520 vs 645 queries/s); with 128 warm-up queries it is 835. The OpenEmbed rows below and in the main speed table use a document and a query warm-up.
- **Results are unchanged:** embeddings from the fast kernels match the PyTorch path (mean cosine β₯ 0.9999, worst single vector 0.9998), so the published accuracy scores stay valid without a re-run.
- **Speed:** openembed-0.8b 1.87Γ, openembed-2b 1.50Γ, openembed-4b 1.64Γ, openembed-9b 1.38Γ documents/s.
## Throughput (main speed table protocol)
Measured on an NVIDIA GeForce RTX 4090 (24 GB), one model at a time, batch 32, 512-token window, bf16, 2,048 Zalo Legal documents + 818 queries.
| Model | Docs/s (before β after) | Queries/s (before β after) | Speed-up (docs) | Peak memory, GiB (before β after) |
|---|---:|---:|---:|---:|
| openembed-0.8b | 88 β 165 | 645 β 835 | 1.87Γ | 3.5 β 2.7 |
| openembed-2b | 63 β 95 | 485 β 752 | 1.50Γ | 6.2 β 5.4 |
| openembed-4b | 26 β 42 | 199 β 280 | 1.64Γ | 12.2 β 10.4 |
| openembed-9b | 19 β 26 | 146 β 211 | 1.38Γ | 19.6 β 17.8 |
## Embedding check (fast kernels vs PyTorch path)
256 Zalo Legal documents + 256 queries per model, encoded both ways; cosine between the two embeddings of each text, and agreement of the top-10 documents per query.
| Model | Mean cosine | Min cosine | Top-1 same | Top-10 overlap |
|---|---:|---:|---:|---:|
| openembed-0.8b | 0.99992 | 0.99983 | 98.8% | 98.9% |
| openembed-2b | 0.99994 | 0.99985 | 98.0% | 98.8% |
| openembed-4b | 0.99994 | 0.99989 | 98.8% | 99.3% |
| openembed-9b | 0.99994 | 0.99986 | 98.8% | 98.9% |
Top-1 differences are bf16-level ties between near-identical documents, not a change in the model.
## Setup used
- PyTorch 2.15.0 (CUDA 13.2 build), Transformers 5.25.1, Triton 3.9.0
- `flash-linear-attention` 0.6.1 + `fla-core` 0.6.1, `causal-conv1d` 1.7.0 (built with CUDA 13.3)
- Raw data: [results/speed/speed_unified.csv](../results/speed/speed_unified.csv)
|