Hugging Face adds Alibaba’s Qwen4 model with a 1M-token context
Hugging Face has published Qwen4-35B-A3B, a model developed by Alibaba’s Qwen team that can process text, images and video and has a context window of up to 1 million tokens. The release pairs a mixture-of-experts design with software support for running the model across a range of inference tools, while Hugging Face’s post also outlines ways to fine-tune it for specific tasks.
A hybrid architecture
The model has about 35 billion main parameters, of which roughly 3.8 billion are active for each token, according to Hugging Face. It also contains around 20.5 billion parameters in per-layer n-gram embeddings, bringing the stated total to about 56 billion. In a mixture-of-experts, or MoE, model, a routing system directs each input to selected specialist components rather than activating every parameter for every token.
The text decoder contains ten cycles, each made up of four layers. In every cycle, Gated DeltaNet handles three layers by updating a fixed-capacity memory as tokens arrive; the fourth uses Qwen Sparse Attention to retrieve selected tokens from throughout the context. An indexer averages keys for tokens grouped in fours and chooses up to 512 groups for each query. Attention then processes the tokens in those groups—up to 2,048 in all—plus as many as three tokens from a group that is not yet complete.
Hugging Face says the model can use up to eight selected experts plus a shared expert for processing. Its layers also maintain four parallel residual streams, each starting from a copy of the token’s 2,048-dimensional embedding. Learned gates combine those streams before processing and control how the shared output is added back to each one.
A large embedding table sits in the decoder’s second layer. The table has 20.5 billion parameters, but each token accesses only 16 rows: eight representing the preceding two tokens and eight representing the current token together with the two before it. The layer combines those retrieved embeddings, controls their contribution to the residual streams and applies a short convolution to capture nearby patterns.
Images, video and model formats
For visual input, a vision transformer converts images into patches measuring 16 by 16 pixels, then combines neighboring patches before passing them to the text decoder. Video processing samples two frames per second and groups adjacent sampled frames in pairs. Within each pair, the vision transformer allows patches to attend to one another.
The blog lists BF16 and FP8 checkpoints, as well as OMLX and quantized GGUF versions. For GGUF, Hugging Face says three quantization options are available: Q4_K_M at 4-bit, Q6_K at 6-bit and Q8_0 at 8-bit. Quantization reduces the precision used to represent model values, a method commonly used to make models more practical to run on supported hardware.
The release supports Multi-Token Prediction, a speculative decoding method that uses draft tokens to help speed up text generation. In Hugging Face’s test, using three draft tokens with the Q4 quantized model increased generation speed by 22% on an Apple Silicon M5. The model also offers four reasoning-effort settings—“xhigh,” “high,” “low” and “off”—with “high” as the default when no setting is specified.
Software support and local use
Hugging Face worked with the Qwen team to provide release-day support in Transformers, llama.cpp, Llama App, vLLM, SGLang, Inference Providers and Inference Endpoints. The post also names TRL, a library used in its fine-tuning example. Hugging Face describes Qwen4 as a mid-sized model for local setups, and says it runs on Apple Silicon through oMLX and mlx-lm.
The oMLX implementation uses custom Metal kernels for Qwen Sparse Attention and the gated residual design, according to the post. It also supports image input, speculative decoding and moving the per-layer embedding table to an SSD. Hugging Face says support for the language model in mlx-lm was still making its way into that project’s official repository.
Hugging Face points users to the vLLM and SGLang documentation for instructions on operating the model with those inference engines. Its post describes loading the model and processor through automatic classes, and passing image or video content through a chat template. Video use requires torchcodec and ffmpeg, it says.
Fine-tuning example and evaluations
The post demonstrates adapting Qwen4 for cyber defense with TRL. In the example, a model receives a sanitized security alert and related evidence, then learns to assign a triage label and cite relevant records. Several proposed responses are sampled with vLLM; each receives a score of one if its label and citations meet the analyst’s criteria, and zero otherwise.
An asynchronous GRPO trainer uses the relative scores to update a LoRA adapter, a small set of additional model parameters. Hugging Face’s example runs training and vLLM on separate GPUs, then compares the original model with saved adapters on held-out incidents. It assesses label accuracy, citation accuracy and missed escalations; the reward verifier also gives a small bonus for using fewer tool calls.
On 12 held-out CyberDefense Bench tasks, the base model passed four, the adapter from update 50 passed six, and the update-100 adapter passed three, according to Hugging Face. The earlier checkpoint did best in that sample even though the overall training reward had risen. The post advises using the held-out results to select a checkpoint and invites people who train adapters to share them on Hugging Face.
Hugging Face also reports using Qwen4 with the Pi coding agent and selected skills in zero-shot demonstrations. Examples included producing an introduction video for a speculative-decoding benchmark tool, preparing a developer-focused slide deck about Llama App and llama.cpp, and generating a cinematic mountain-and-cloud scene. The company says Qwen4-35B-A3B is licensed under Apache-2.0; it points readers to the model card for benchmark results, without reproducing detailed scores in the post.
Source
- Welcome Qwen 4: Cutting-edge intelligence on-device — huggingface.co