Instructions to use Qwen/Qwen3.8-Flash-Next with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen3.8-Flash-Next with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Qwen/Qwen3.8-Flash-Next") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Qwen/Qwen3.8-Flash-Next") model = AutoModelForMultimodalLM.from_pretrained("Qwen/Qwen3.8-Flash-Next", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen3.8-Flash-Next with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen3.8-Flash-Next" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen3.8-Flash-Next", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Qwen/Qwen3.8-Flash-Next
- SGLang
How to use Qwen/Qwen3.8-Flash-Next with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Qwen/Qwen3.8-Flash-Next" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen3.8-Flash-Next", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Qwen/Qwen3.8-Flash-Next" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen3.8-Flash-Next", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Qwen/Qwen3.8-Flash-Next with Docker Model Runner:
docker model run hf.co/Qwen/Qwen3.8-Flash-Next
Notes from an independent NVFP4 port of Qwen3.8-Flash-Next
We run Qwen3.8-Flash-Next in our own C++/CUDA inference engine (no PyTorch at
runtime) on a single RTX 5090. The 336 GB BF16 release converts in place to a
164 GB tree. Only a 3.6 GiB dense graph is device-resident; the 24 576 routed
experts live in a 63.6 GB pinned host arena and are streamed per token through a
device slot cache, and the 96 GiB n-gram table is memory-mapped and read a page
at a time. Load takes about 50 s (the arena build dominates), and decode runs at
42.8 tokens/s at 2 048 tokens.
What worked well
- Determinism is solid. The control prompt answers "Paris", and three
independent runs produce byte-identical full-vocabulary logits. A second model
instance in the same process answers identically, which matters here because
the expert-residency bookkeeping is process-lifetime state. - All four of our parity gates pass on real weights: a financial-services
formula set (3/3), a compiler-syntactic code set (3/3), a determinism/near-tie
set (3/3), each captured from the source weights rather than from a template. - The tool wire is unambiguous. The template's
<tool_call><function=NAME><parameter=K>V…XML is parsed without heuristics,
and a real-weight round-trip produced theget_weathercall with{"city":"Paris"}. One template delta over the earlier Qwen 3.x checkpoints
(the closed think block on assistant history turns) plus this member's ownpreserve_thinkingand empty-system-turn defaults had to be reproduced
byte-for-byte (see below) — with them, multi-turn and tool turns frame exactly
as the checkpoint's own Jinja template does. - 4-bit is enough for this checkpoint. Unlike some models we have ported, the
body tolerates NVFP4 throughout — with two deliberate exceptions, the LM head
and the n-gram table (below). No residual weight plane was needed.
Checkpoint facts that are easy to get subtly wrong
The LM head must not be quantized. At 4 bits the logit noise is ~0.5,
which exceeds this model's typical top-1/top-2 margin; the argmax flips. We
keeplm_headin BF16 (an extra 1.2 GB) and quantize everything else,
including the embedding table.There are three distinct model-type names. The top level is
qwen4_exp, the text sub-config isqwen4_exp_text, and the architecture isQwen4ExpForConditionalGeneration— withlanguage_model_only: false
because the release still ships a 333-tensor vision tower. A loader that keys
on one name silently skips or misclassifies the other. We strip and count the
vision tower (skipped_visual_tensors: 333).The EOS ids disagree between files.
config.jsonsays248044,generation_config.jsonsays[248046, 248044], andtokenizer_config.json
names<|im_end|>as the EOS token. Reading only the config makes the model
run to the token budget whenever it ends with<|im_end|>— the common
ending. We take both ids. (Suggestion to the authors: makeconfig.json
authoritative and consistent withgeneration_config.json.)pad_token_idisnullin the text config while the tokenizer pads with248044, which is also the secondary EOS. A padded batch therefore looks
like a batch that stopped. We never batch, but an implementer who does will
find this quickly. (Suggestion: ship a pad id that is not a stop id.)rope_parameters.mrope_interleaved: truewithmrope_section [11,11,10]
is the multimodal branch. The text decoder rotates 64 of its 256 head dims
with a plain rotary table (θ = 1e7); applying the M-RoPE sections to text
positions corrupts them. If you only run text, ignore that block. (Suggestion:
document which sub-block the text path consumes.)ple_layer_ids: [2]but the tensors arelayers.1.ple.*. One is
1-based and the other 0-based. Getting it wrong either fails to find the
table or injects it into the wrong layer; the model still produces fluent
text, which is the worst failure mode. We gate the converter onple_layer_ids == [layer_idx + 1].The n-gram (PLE) table is 96 GiB of BF16 in 128 shards — larger than every
other weight in the model combined. It must be memory-mapped and gathered
per token, not loaded. (Suggestion: a quantized or int16 copy would cut the
tree by ~40 %.)generation_config.jsonsamples by default (do_sample: true,temperature 1.0,top_k 20,top_p 0.95). Any parity work has to pin
greedy explicitly, exactly as we do.MTP is declared but inert:
mtp_num_hidden_layers: 1,mtp.hybrid,mtp_use_hidden_state_from_layer: null. We convert and count it underdeferredand never apply it.The decode working set is the whole expert set. 512 experts at
intermediate 640 per layer × 48 layers means each expert is only ~2.7 MB,
but a token touches ten of them per layer, and the union over a decode run
is effectively all 24 576. A bounded LRU over file-backed mmaps measured
9.2 tokens/s against the pinned arena's 32 on the same card; pinning the
whole set is the only thing that pays here. Budget host RAM for it.
Measured
| result | |
|---|---|
| SelfCheck ("Paris") | PASS ×3, bit-identical logits, logits_hash 2e3bcd090441ad65, top-1 id 11751 |
| Financial-services formula set | 3/3 |
| Compiler-syntactic code set | 3/3 |
| Determinism / near-tie set | 3/3, byte-identical token streams |
| Native tool round-trip | get_weather {"city":"Paris"} in 26 tokens |
| Decode throughput, 2 048 tokens | 42.98 t/s (auto), 33.88 t/s (strict); TTFT 193 / 198 ms |
| Residency | 3 615 MiB device-resident; 63.6 GB pinned host arena; ~50 s load |
| Expert cache | 5 350 / 4 319 slots, hit rate 0.86, ~300 MB streamed per token |
What we did not run
- The 262 144-token window. We verified short/medium prompts and the
2 048-token protocol; the full window's KV and recurrent state exceed this
card, and the expert-cache capacity is already the limiting factor. - MTP / speculative decoding — the layer is stored (counted) but never runs.
- Any multimodal path — the vision tower is stripped; this is a text-only
port. - Sampling quality. All parity numbers are greedy; the sampler is wired but
the checkpoint's owndo_sampledefaults were not benchmarked.
Overall a well-specified checkpoint once the three traps above are known
(LM-head precision, EOS id disagreement, and the PLE index base). The one thing
that cost real time was the capacity behaviour: throughput moves 10-30 % with
expert-cache size, so a "regression" here is usually less VRAM, not slower code.