Instructions to use tiny-random/qwen3-vl with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/qwen3-vl with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/qwen3-vl") 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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("tiny-random/qwen3-vl") model = AutoModelForMultimodalLM.from_pretrained("tiny-random/qwen3-vl", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/qwen3-vl with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/qwen3-vl" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/qwen3-vl", "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/tiny-random/qwen3-vl
- SGLang
How to use tiny-random/qwen3-vl 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 "tiny-random/qwen3-vl" \ --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": "tiny-random/qwen3-vl", "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 "tiny-random/qwen3-vl" \ --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": "tiny-random/qwen3-vl", "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 tiny-random/qwen3-vl with Docker Model Runner:
docker model run hf.co/tiny-random/qwen3-vl
| library_name: transformers | |
| pipeline_tag: image-text-to-text | |
| inference: true | |
| widget: | |
| - text: Hello! | |
| example_title: Hello world | |
| group: Python | |
| base_model: | |
| - Qwen/Qwen3-VL-8B-Thinking | |
| This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [Qwen/Qwen3-VL-8B-Thinking](https://huggingface.co/Qwen/Qwen3-VL-8B-Thinking). | |
| ### Example usage: | |
| ```python | |
| import numpy as np | |
| import torch | |
| import transformers | |
| from PIL import Image | |
| from transformers import ( | |
| AutoModel, | |
| AutoModelForCausalLM, | |
| AutoProcessor, | |
| AutoTokenizer, | |
| Qwen3VLForConditionalGeneration, | |
| ) | |
| model_id = "tiny-random/qwen3-vl" | |
| model = Qwen3VLForConditionalGeneration.from_pretrained( | |
| model_id, dtype=torch.bfloat16, device_map="cuda", | |
| attn_implementation="flash_attention_2", | |
| ) | |
| processor = AutoProcessor.from_pretrained(model_id) | |
| messages = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| { | |
| "type": "image", | |
| "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg", | |
| }, | |
| {"type": "text", "text": "Describe this image."}, | |
| ], | |
| } | |
| ] | |
| # Preparation for inference | |
| inputs = processor.apply_chat_template( | |
| messages, | |
| tokenize=True, | |
| add_generation_prompt=True, | |
| return_dict=True, | |
| return_tensors="pt" | |
| ).to(model.device) | |
| # Inference: Generation of the output | |
| generated_ids = model.generate(**inputs, max_new_tokens=32) | |
| generated_ids_trimmed = [ | |
| out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids) | |
| ] | |
| output_text = processor.batch_decode( | |
| generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False | |
| ) | |
| print(output_text) | |
| ``` | |
| ### Codes to create this repo: | |
| ```python | |
| import json | |
| from pathlib import Path | |
| import accelerate | |
| import torch | |
| from huggingface_hub import file_exists, hf_hub_download | |
| from transformers import ( | |
| AutoConfig, | |
| AutoModelForCausalLM, | |
| AutoProcessor, | |
| GenerationConfig, | |
| # Qwen3VLMoeForConditionalGeneration, | |
| Qwen3VLForConditionalGeneration, | |
| set_seed, | |
| ) | |
| source_model_id = "Qwen/Qwen3-VL-8B-Thinking" | |
| save_folder = "/tmp/tiny-random/qwen3-vl" | |
| processor = AutoProcessor.from_pretrained(source_model_id, trust_remote_code=True) | |
| processor.save_pretrained(save_folder) | |
| with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f: | |
| config_json = json.load(f) | |
| config_json['text_config'].update({ | |
| 'head_dim': 32, | |
| 'hidden_size': 8, | |
| 'intermediate_size': 64, | |
| 'moe_intermediate_size': 64, | |
| 'num_hidden_layers': 2, | |
| 'num_attention_heads': 8, | |
| 'num_key_value_heads': 4, | |
| }) | |
| config_json['text_config']['rope_scaling']['mrope_section'] = [8, 4, 4] | |
| config_json['vision_config'].update( | |
| { | |
| 'hidden_size': 32 * 4, | |
| 'intermediate_size': 64, | |
| 'num_heads': 4, | |
| 'out_hidden_size': 8, | |
| 'depth': 6, | |
| 'deepstack_visual_indexes': [1, 3, 5], | |
| } | |
| ) | |
| with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f: | |
| json.dump(config_json, f, indent=2) | |
| config = AutoConfig.from_pretrained( | |
| save_folder, | |
| trust_remote_code=True, | |
| ) | |
| print(config) | |
| torch.set_default_dtype(torch.bfloat16) | |
| model = Qwen3VLForConditionalGeneration(config) | |
| torch.set_default_dtype(torch.float32) | |
| if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'): | |
| model.generation_config = GenerationConfig.from_pretrained( | |
| source_model_id, trust_remote_code=True, | |
| ) | |
| model.generation_config.do_sample = True | |
| print(model.generation_config) | |
| model = model.cpu() | |
| with torch.no_grad(): | |
| for name, p in sorted(model.named_parameters()): | |
| torch.nn.init.normal_(p, 0, 0.1) | |
| print(name, p.shape) | |
| model.save_pretrained(save_folder) | |
| ``` | |
| ### Printing the model: | |
| ```text | |
| Qwen3VLForConditionalGeneration( | |
| (model): Qwen3VLModel( | |
| (visual): Qwen3VLVisionModel( | |
| (patch_embed): Qwen3VLVisionPatchEmbed( | |
| (proj): Conv3d(3, 128, kernel_size=(2, 16, 16), stride=(2, 16, 16)) | |
| ) | |
| (pos_embed): Embedding(2304, 128) | |
| (rotary_pos_emb): Qwen3VLVisionRotaryEmbedding() | |
| (blocks): ModuleList( | |
| (0-5): 6 x Qwen3VLVisionBlock( | |
| (norm1): LayerNorm((128,), eps=1e-06, elementwise_affine=True) | |
| (norm2): LayerNorm((128,), eps=1e-06, elementwise_affine=True) | |
| (attn): Qwen3VLVisionAttention( | |
| (qkv): Linear(in_features=128, out_features=384, bias=True) | |
| (proj): Linear(in_features=128, out_features=128, bias=True) | |
| ) | |
| (mlp): Qwen3VLVisionMLP( | |
| (linear_fc1): Linear(in_features=128, out_features=64, bias=True) | |
| (linear_fc2): Linear(in_features=64, out_features=128, bias=True) | |
| (act_fn): PytorchGELUTanh() | |
| ) | |
| ) | |
| ) | |
| (merger): Qwen3VLVisionPatchMerger( | |
| (norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True) | |
| (linear_fc1): Linear(in_features=512, out_features=512, bias=True) | |
| (act_fn): GELU(approximate='none') | |
| (linear_fc2): Linear(in_features=512, out_features=8, bias=True) | |
| ) | |
| (deepstack_merger_list): ModuleList( | |
| (0-2): 3 x Qwen3VLVisionPatchMerger( | |
| (norm): LayerNorm((512,), eps=1e-06, elementwise_affine=True) | |
| (linear_fc1): Linear(in_features=512, out_features=512, bias=True) | |
| (act_fn): GELU(approximate='none') | |
| (linear_fc2): Linear(in_features=512, out_features=8, bias=True) | |
| ) | |
| ) | |
| ) | |
| (language_model): Qwen3VLTextModel( | |
| (embed_tokens): Embedding(151936, 8) | |
| (layers): ModuleList( | |
| (0-1): 2 x Qwen3VLTextDecoderLayer( | |
| (self_attn): Qwen3VLTextAttention( | |
| (q_proj): Linear(in_features=8, out_features=256, bias=False) | |
| (k_proj): Linear(in_features=8, out_features=128, bias=False) | |
| (v_proj): Linear(in_features=8, out_features=128, bias=False) | |
| (o_proj): Linear(in_features=256, out_features=8, bias=False) | |
| (q_norm): Qwen3VLTextRMSNorm((32,), eps=1e-06) | |
| (k_norm): Qwen3VLTextRMSNorm((32,), eps=1e-06) | |
| ) | |
| (mlp): Qwen3VLTextMLP( | |
| (gate_proj): Linear(in_features=8, out_features=64, bias=False) | |
| (up_proj): Linear(in_features=8, out_features=64, bias=False) | |
| (down_proj): Linear(in_features=64, out_features=8, bias=False) | |
| (act_fn): SiLU() | |
| ) | |
| (input_layernorm): Qwen3VLTextRMSNorm((8,), eps=1e-06) | |
| (post_attention_layernorm): Qwen3VLTextRMSNorm((8,), eps=1e-06) | |
| ) | |
| ) | |
| (norm): Qwen3VLTextRMSNorm((8,), eps=1e-06) | |
| (rotary_emb): Qwen3VLTextRotaryEmbedding() | |
| ) | |
| ) | |
| (lm_head): Linear(in_features=8, out_features=151936, bias=False) | |
| ) | |
| ``` |