Module qwen3_attention

Module qwen3_attention 

Source
Expand description

Qwen3 full attention layer.

Q/K/V projection -> Q/K norms -> RoPE -> KV cache write -> paged decode attention -> O projection, then MoE FFN.

Split into submodules:

  • types: MlaWeights + Qwen3AttentionLayer struct definitions
  • init: new, new_ungated, new_with_gating (kernel loading)
  • helpers: setters + apply_layer_scalar + effective_attn_scale
  • prefill_weights: prefill weight setup + W4A16 M128 dispatcher
  • decode: single-token attention forward + KV cache helpers
  • prefill: batched prefill with paged attention
  • trait_impl: TransformerLayer trait implementation

Re-exports§

pub use innerq_driver::InnerQDriver;

Modules§

innerq_driver
Host-side driver for TurboQuant+ InnerQ per-channel K equalization.

Structs§

CompressorWeights
DeepSeek-V4 compressed-attention compressor weights (one per compressed layer). Produces n_win = usable/ratio compressed KV entries that are concatenated to the raw sliding-window KV before core attention. CSA (ratio 4) uses a 2×ratio overlap window (Ca/Cb); HCA (ratio 128) uses a single non-overlapping window.
HcHeadWeights
Both HC sites for a DeepSeek-V4 block: the attention site runs before/after attention, the FFN site before/after the MoE FFN. Model-level HC head parameters (final collapse before LM head). Loaded once, attached to every layer, but only used by the last layer.
HcLowRank
Qwen3.8-Flash-Next’s LOW-RANK hyper-connection parameters for one site.
HcSiteWeights
Per-block Manifold-Constrained Hyper-Connection (mHC) parameters for one site (attention or FFN). All buffers are float32 device pointers, matching the checkpoint dtype. See ops::hc_pre / ops::hc_post.
HcWeights
MlaWeights
MLA (Multi-head Latent Attention) weight components for 2-step decode.
Qwen3AttentionLayer
Qwen3-Next full attention layer (12 of 48 layers).

Statics§

ATTN_PHASE_US
Per-phase host-time accumulators for the prefill ATTENTION path (ATLAS_PREFILL_HOST_TIMING=1). Index: 0=qkv projections, 1=everything between qkv and the attention call (deinterleave + per-head norms + RoPE + KV write), 2=the attention kernel call itself, 3=o_proj + head gate. Summed across layers; read and reset once per prefill.
FFN_HOST_US
Host-time accumulator for the FFN/MoE half of prefill layers (ATLAS_PREFILL_HOST_TIMING=1). Summed across layers and read+reset once per prefill by the layer loop, so the attention half can be derived as loop_wall - ffn.

Functions§

add_attn_phase_us
add_ffn_host_us
take_attn_phase_us
take_ffn_host_us
validate_required_kv_kernels
Startup fail-fast for --kv-cache-dtype: resolve every kernel handle the dtype’s dispatch arms require (chunked-prefill kernel, WHT bookends) and error with the full missing list — BEFORE the multi-minute weight load, instead of at first dispatch. See kernel_requirements.rs.