docs/source/en/model_doc/qwen4_exp.md
This model was contributed to Hugging Face Transformers on 2026-08-26.
Qwen4-Exp builds on Qwen3.5's hybrid text and multimodal architecture with three key components: GatedResidual (GR), Qwen Sparse Attention (QSA), and Per-Layer Embedding (PLE).
GR is a Qwen-developed residual architecture that combines Hyper-Connection with GatedNorm. It mixes multiple residual streams with fine-grained elementwise gating before each attention and Mixture-of-Experts (MoE) block, then controls how much of the block output is injected back into each stream.
QSA uses multiple query heads to score compressed key blocks, selects the most relevant contiguous token blocks, and keeps the incomplete trailing block uncompressed. This block-level selection reduces indexing overhead and improves memory locality for long sequences. Combined with Gated DeltaNet, QSA makes Qwen4-Exp the first hybrid architecture to integrate linear and sparse attention, substantially improving inference efficiency for long-context workloads.
PLE enriches selected decoder layers with layer-specific lexical features derived from hashed token n-grams and a dilated depthwise convolution.
ple_layer_ids uses one-based decoder layer indices. When PLE is enabled and the model receives inputs_embeds, pass the original token ids through ple_input_ids. If input_ids are provided, the model uses them for PLE automatically.DynamicCache] is the recommended default, and [StaticCache] is also supported. Cache cropping is not supported when PLE or QSA is enabled. With cache offloading, GatedDeltaNet, PLE, and QSA indexer states remain on device while attention key/value states are offloaded.split_ngram_parts controls the logical checkpoint shards for each large PLE n-gram embedding table. Transformers concatenates these shards along the vocabulary dimension into one runtime weight. The default save_pretrained(save_original_format=True) writes the configured original sharded layout.hc_count sets the number of residual streams, and hc_lowrank sets the rank of the learned GR input mixer.tp_plan="auto" supports attention, MoE, GatedDeltaNet, QSA, GR, and vocabulary-row sharding of PLE tables. Custom configurations must keep sharded attention heads, QSA and GatedDeltaNet projection dimensions, GR stream width, expert dimensions, and the padded PLE vocabulary divisible by the TP size. The replicated low-rank GR output adds no divisibility constraint.Qwen4ExpForCausalLM] with [Qwen4ExpTextConfig] for text-only generation. Use [Qwen4ExpForConditionalGeneration] with [Qwen4ExpConfig] for multimodal inputs.[[autodoc]] Qwen4ExpConfig
[[autodoc]] Qwen4ExpTextConfig
[[autodoc]] Qwen4ExpVisionConfig
[[autodoc]] Qwen4ExpVisionModel - forward
[[autodoc]] Qwen4ExpTextModel - forward
[[autodoc]] Qwen4ExpModel - forward
[[autodoc]] Qwen4ExpForCausalLM - forward
[[autodoc]] Qwen4ExpForConditionalGeneration - forward