*This model was contributed to Hugging Face Transformers on 2026-12-03.* # Qwen4 Qwen4 uses Gated DeltaNet and Qwen Sparse Attention with GatedResidual connections and a dense SwiGLU feed-forward network. Use [`Qwen4ForCausalLM`] for text generation and [`Qwen4ForConditionalGeneration`] for image and video inputs. ## Usage ```py from transformers import AutoModelForCausalLM, AutoTokenizer checkpoint = "Qwen/Qwen4-27B" tokenizer = AutoTokenizer.from_pretrained(checkpoint) model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto") inputs = tokenizer("The largest ocean on Earth is", return_tensors="pt").to(model.device) output_ids = model.generate(**inputs, max_new_tokens=32) new_ids = output_ids[:, inputs["input_ids"].shape[1]:] print(tokenizer.batch_decode(new_ids, skip_special_tokens=True)[0]) ``` ```py from transformers import AutoModelForImageTextToText, AutoProcessor checkpoint = "Qwen/Qwen4-27B" processor = AutoProcessor.from_pretrained(checkpoint) model = AutoModelForImageTextToText.from_pretrained(checkpoint, device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "path": "/path/to/image.jpg"}, {"type": "text", "text": "Describe this scene."}, ], } ] inputs = processor.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt" ).to(model.device) output_ids = model.generate(**inputs, max_new_tokens=64) new_ids = output_ids[:, inputs["input_ids"].shape[1]:] print(processor.batch_decode(new_ids, skip_special_tokens=True)[0]) ``` For a video, replace the image entry with `{"type": "video", "path": "/path/to/video.mp4"}`. The processor reads the media and prepares the visual inputs alongside the prompt tokens. ## Qwen4Config [[autodoc]] Qwen4Config ## Qwen4TextConfig [[autodoc]] Qwen4TextConfig ## Qwen4VisionConfig [[autodoc]] Qwen4VisionConfig ## Qwen4VisionModel [[autodoc]] Qwen4VisionModel - forward ## Qwen4TextModel [[autodoc]] Qwen4TextModel - forward ## Qwen4Model [[autodoc]] Qwen4Model - forward ## Qwen4ForCausalLM [[autodoc]] Qwen4ForCausalLM - forward ## Qwen4ForConditionalGeneration [[autodoc]] Qwen4ForConditionalGeneration - forward ## Qwen4ForSequenceClassification [[autodoc]] Qwen4ForSequenceClassification - forward ## Qwen4TextForSequenceClassification [[autodoc]] Qwen4TextForSequenceClassification - forward