Run this model with HF Jobs
Run SceneWorks/bernini-mlx on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/SceneWorks/bernini-mlx. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/SceneWorks/bernini-mlx on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use SceneWorks/bernini-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use SceneWorks/bernini-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download SceneWorks/bernini-mlx --local-dir bernini-mlx
- Wan2.2
How to use SceneWorks/bernini-mlx with Wan2.2:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Add q4/q8/bf16 quant-matrix tier subdirs (sc-9945, epic 8506)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- bf16/.gitattributesAdded+36
- bf16/README.mdAdded+44
- bf16/bernini_planner.jsonAdded+31
- bf16/bernini_renderer.jsonAdded+9
- bf16/config.jsonAdded+51
- bf16/connector.safetensorsAdded+3
- bf16/high_noise_model.safetensorsAdded+3
- bf16/low_noise_model.safetensorsAdded+3
- bf16/mask_tokens.safetensorsAdded+3
- bf16/mllm/.gitattributesAdded+35
- bf16/mllm/README.mdAdded+528
- bf16/mllm/chat_template.jsonAdded+3
- bf16/mllm/config.jsonAdded+62
- bf16/mllm/generation_config.jsonAdded+12
- bf16/mllm/merges.txtAdded
- bf16/mllm/preprocessor_config.jsonAdded+19
- bf16/mllm/tokenizer.jsonAdded+3
- bf16/mllm/tokenizer_config.jsonAdded+207
- bf16/mllm/vocab.jsonAdded
- bf16/qwen2_5_vl.safetensorsAdded+3
- bf16/qwen2_5_vl_config.jsonAdded+62
- bf16/t5_encoder.safetensorsAdded+3
- bf16/tokenizer.jsonAdded+3
- bf16/transformer_2_config.jsonAdded+24
- bf16/transformer_config.jsonAdded+24
- bf16/vae.safetensorsAdded+3
- bf16/vit_decoder.safetensorsAdded+3
- q4/.gitattributesAdded+36
- q4/README.mdAdded+44
- q4/bernini_planner.jsonAdded+31
- q4/bernini_renderer.jsonAdded+9
- q4/config.jsonAdded+55
- q4/connector.safetensorsAdded+3
- q4/high_noise_model.safetensorsAdded+3
- q4/low_noise_model.safetensorsAdded+3
- q4/mask_tokens.safetensorsAdded+3
- q4/mllm/.gitattributesAdded+35
- q4/mllm/README.mdAdded+528
- q4/mllm/chat_template.jsonAdded+3
- q4/mllm/config.jsonAdded+62
- q4/mllm/generation_config.jsonAdded+12
- q4/mllm/merges.txtAdded
- q4/mllm/preprocessor_config.jsonAdded+19
- q4/mllm/tokenizer.jsonAdded+3
- q4/mllm/tokenizer_config.jsonAdded+207
- q4/mllm/vocab.jsonAdded
- q4/qwen2_5_vl.safetensorsAdded+3
- q4/qwen2_5_vl_config.jsonAdded+66
- q4/t5_encoder.safetensorsAdded+3
- q4/tokenizer.jsonAdded+3
123456789101112131415161718192021222324252627282930313233343536*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text1234567891011121314151617181920212223242526272829303132333435363738394041424344---license: apache-2.0library_name: mlxpipeline_tag: text-to-videotags: - mlx - apple-silicon - text-to-video - text-to-image - bernini - wan2.2 - qwen2.5-vlbase_model: - ByteDance/Bernini-Diffusers - Wan-AI/Wan2.2-T2V-A14B---
# Bernini — MLX (full planner + renderer)
Native **Apple Silicon / MLX** conversion of ByteDance **Bernini** (the full pipeline), packaged forin-process generation in [SceneWorks](https://github.com/michaeltrefry). Bernini is a**Latent Semantic Planning** model: a Qwen2.5-VL-7B semantic planner (MAR loop) drives a**Wan2.2-T2V-A14B** dual-expert renderer.
This is a turnkey, self-contained snapshot — no diffusers source or separate Wan base is needed atruntime. It loads directly via `mlx_gen::load("bernini")` (mlx-gen-bernini) and is quantized to**Q4 (default) / Q8 (opt-in)** at load time.
## Contents- `qwen2_5_vl.safetensors` + `qwen2_5_vl_config.json` — Qwen2.5-VL-7B planner backbone + vision tower- `connector.safetensors`, `vit_decoder.safetensors`, `mask_tokens.safetensors` — MLP connector, ViT decoder (clip-diff flow head), MAR mask token- `high_noise_model.safetensors` + `low_noise_model.safetensors` — the Wan2.2 dual-expert renderer DiTs- `t5_encoder.safetensors` + `tokenizer.json` — UMT5-XXL text encoder + tokenizer- `vae.safetensors` — z16 AutoencoderKLWan- `mllm/` — Qwen ChatML tokenizer/config; `*.json` sidecars — config + planner/renderer knobs
`dtype`: bf16. Validated on a 128 GB Apple Silicon Mac for **text-to-image** and **text-to-video**(~44 GB peak at Q4).
## Credits & licenseDerived from [ByteDance/Bernini-Diffusers](https://huggingface.co/ByteDance/Bernini-Diffusers) and[Wan-AI/Wan2.2-T2V-A14B](https://huggingface.co/Wan-AI/Wan2.2-T2V-A14B) (the renderer's stock UMT5/VAE),both Apache-2.0. Conversion/packaging by SceneWorks; released under Apache-2.0.12345678910111213141516171819202122232425262728293031{ "boundary_ratio": 0.417, "clip_diff_cfg": { "diffusion_batch_mul": 16, "model_type": "flow_match", "shift": 2.0, "target_channels": 3584, "width": 4096, "z_channels": 3584 }, "connector_cfg": { "enable_gen_branch": true, "enable_vit_branch": true, "gen_head_type": "zerolinear", "model_type": "MLPConnector", "out_dim_for_gen": 4096, "out_dim_for_vit": 3584, "zero_init_proj_gen_last": true }, "feature_type_from_stage_one": "masked_tgt_embed_with_qwen_txt_vit_tokens", "interpolate_src_id": true, "max_sequence_length": 512, "max_trained_src_id": 5, "num_mask_token": 4096, "shift": 3.0, "switch_dit_boundary": 0.875, "t5_combine_type": "concat_with_zero_init", "t5_max_sequence_length": 512, "target_fps": 16, "use_src_id_rotary_emb": true}123456789{ "flow_shift": 5.0, "interpolate_src_id": true, "max_sequence_length": 512, "max_trained_src_id": 5, "shift": 3.0, "switch_dit_boundary": 0.875, "use_src_id_rotary_emb": true}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051{ "boundary": 0.875, "cross_attn_norm": true, "dim": 5120, "dual_model": true, "eps": 1e-6, "ffn_dim": 13824, "frame_num": 81, "freq_dim": 256, "in_dim": 16, "max_area": 0, "model_type": "t2v", "model_version": "2.2", "num_heads": 40, "num_layers": 40, "num_train_timesteps": 1000, "out_dim": 16, "patch_size": [ 1, 2, 2 ], "qk_norm": true, "sample_fps": 16, "sample_guide_scale": [ 3.0, 4.0 ], "sample_neg_prompt": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走", "sample_shift": 12.0, "sample_steps": 40, "t5_dim": 4096, "t5_dim_attn": 4096, "t5_dim_ffn": 10240, "t5_num_buckets": 32, "t5_num_heads": 64, "t5_num_layers": 24, "t5_vocab_size": 256384, "text_dim": 4096, "text_len": 512, "vae_stride": [ 4, 8, 8 ], "vae_z_dim": 16, "window_size": [ -1, -1 ]}123version https://git-lfs.github.com/spec/v1oid sha256:0b1d7adbc3489c3ab280e49a9359bdcc21b271106ed883a051ca79e3fcbb74eesize 140039232123version https://git-lfs.github.com/spec/v1oid sha256:47189a7d65d10b11b17a31fe8b7a81df01a12dc7aaf1273723402f1c7f442088size 28577096958123version https://git-lfs.github.com/spec/v1oid sha256:0561541cc07e7ac6de8d70ba2b830ce0266a01534854cd9dcca19fd14a2d9dbdsize 28577097058123version https://git-lfs.github.com/spec/v1oid sha256:00d9dcbc12a9ba798f06518d6afe4773796a5390e0d37c9ed92d0114a7cdd2a3size 293602381234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
---license: apache-2.0language:- enpipeline_tag: image-text-to-texttags:- multimodallibrary_name: transformers---
# Qwen2.5-VL-7B-Instruct<a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;"> <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/></a>
## Introduction
In the past five months since Qwen2-VL’s release, numerous developers have built new models on the Qwen2-VL vision-language models, providing us with valuable feedback. During this period, we focused on building more useful vision-language models. Today, we are excited to introduce the latest addition to the Qwen family: Qwen2.5-VL.
#### Key Enhancements:* **Understand things visually**: Qwen2.5-VL is not only proficient in recognizing common objects such as flowers, birds, fish, and insects, but it is highly capable of analyzing texts, charts, icons, graphics, and layouts within images.
* **Being agentic**: Qwen2.5-VL directly plays as a visual agent that can reason and dynamically direct tools, which is capable of computer use and phone use.
* **Understanding long videos and capturing events**: Qwen2.5-VL can comprehend videos of over 1 hour, and this time it has a new ability of cpaturing event by pinpointing the relevant video segments.
* **Capable of visual localization in different formats**: Qwen2.5-VL can accurately localize objects in an image by generating bounding boxes or points, and it can provide stable JSON outputs for coordinates and attributes.
* **Generating structured outputs**: for data like scans of invoices, forms, tables, etc. Qwen2.5-VL supports structured outputs of their contents, benefiting usages in finance, commerce, etc.
#### Model Architecture Updates:
* **Dynamic Resolution and Frame Rate Training for Video Understanding**:
We extend dynamic resolution to the temporal dimension by adopting dynamic FPS sampling, enabling the model to comprehend videos at various sampling rates. Accordingly, we update mRoPE in the time dimension with IDs and absolute time alignment, enabling the model to learn temporal sequence and speed, and ultimately acquire the ability to pinpoint specific moments.
<p align="center"> <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-VL/qwen2.5vl_arc.jpeg" width="80%"/><p>
* **Streamlined and Efficient Vision Encoder**
We enhance both training and inference speeds by strategically implementing window attention into the ViT. The ViT architecture is further optimized with SwiGLU and RMSNorm, aligning it with the structure of the Qwen2.5 LLM.
We have three models with 3, 7 and 72 billion parameters. This repo contains the instruction-tuned 7B Qwen2.5-VL model. For more information, visit our [Blog](https://qwenlm.github.io/blog/qwen2.5-vl/) and [GitHub](https://github.com/QwenLM/Qwen2.5-VL).
## Evaluation
### Image benchmark
| Benchmark | InternVL2.5-8B | MiniCPM-o 2.6 | GPT-4o-mini | Qwen2-VL-7B |**Qwen2.5-VL-7B** || :--- | :---: | :---: | :---: | :---: | :---: || MMMU<sub>val</sub> | 56 | 50.4 | **60**| 54.1 | 58.6|| MMMU-Pro<sub>val</sub> | 34.3 | - | 37.6| 30.5 | 41.0|| DocVQA<sub>test</sub> | 93 | 93 | - | 94.5 | **95.7** || InfoVQA<sub>test</sub> | 77.6 | - | - |76.5 | **82.6** || ChartQA<sub>test</sub> | 84.8 | - |- | 83.0 |**87.3** || TextVQA<sub>val</sub> | 79.1 | 80.1 | -| 84.3 | **84.9**|| OCRBench | 822 | 852 | 785 | 845 | **864** || CC_OCR | 57.7 | | | 61.6 | **77.8**|| MMStar | 62.8| | |60.7| **63.9**|| MMBench-V1.1-En<sub>test</sub> | 79.4 | 78.0 | 76.0| 80.7 | **82.6** || MMT-Bench<sub>test</sub> | - | - | - |**63.7** |63.6 || MMStar | **61.5** | 57.5 | 54.8 | 60.7 |63.9 || MMVet<sub>GPT-4-Turbo</sub> | 54.2 | 60.0 | 66.9 | 62.0 | **67.1**|| HallBench<sub>avg</sub> | 45.2 | 48.1 | 46.1| 50.6 | **52.9**|| MathVista<sub>testmini</sub> | 58.3 | 60.6 | 52.4 | 58.2 | **68.2**|| MathVision | - | - | - | 16.3 | **25.07** |
### Video Benchmarks
| Benchmark | Qwen2-VL-7B | **Qwen2.5-VL-7B** || :--- | :---: | :---: || MVBench | 67.0 | **69.6** || PerceptionTest<sub>test</sub> | 66.9 | **70.5** || Video-MME<sub>wo/w subs</sub> | 63.3/69.0 | **65.1**/**71.6** || LVBench | | 45.3 || LongVideoBench | | 54.7 || MMBench-Video | 1.44 | 1.79 || TempCompass | | 71.7 || MLVU | | 70.2 || CharadesSTA/mIoU | 43.6|
### Agent benchmark| Benchmarks | Qwen2.5-VL-7B ||-------------------------|---------------|| ScreenSpot | 84.7 || ScreenSpot Pro | 29.0 || AITZ_EM | 81.9 || Android Control High_EM | 60.1 || Android Control Low_EM | 93.7 || AndroidWorld_SR | 25.5 || MobileMiniWob++_SR | 91.4 |
## RequirementsThe code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:```pip install git+https://github.com/huggingface/transformers accelerate```or you might encounter the following error:```KeyError: 'qwen2_5_vl'```
## Quickstart
Below, we provide simple examples to show how to use Qwen2.5-VL with 🤖 ModelScope and 🤗 Transformers.
The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:```pip install git+https://github.com/huggingface/transformers accelerate```or you might encounter the following error:```KeyError: 'qwen2_5_vl'```
We offer a toolkit to help you handle various types of visual input more conveniently, as if you were using an API. This includes base64, URLs, and interleaved images and videos. You can install it using the following command:
```bash# It's highly recommanded to use `[decord]` feature for faster video loading.pip install qwen-vl-utils[decord]==0.0.8```
If you are not using Linux, you might not be able to install `decord` from PyPI. In that case, you can use `pip install qwen-vl-utils` which will fall back to using torchvision for video processing. However, you can still [install decord from source](https://github.com/dmlc/decord?tab=readme-ov-file#install-from-source) to get decord used when loading video.
### Using 🤗 Transformers to Chat
Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
```pythonfrom transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessorfrom qwen_vl_utils import process_vision_info
# default: Load the model on the available device(s)model = Qwen2_5_VLForConditionalGeneration.from_pretrained( "Qwen/Qwen2.5-VL-7B-Instruct", torch_dtype="auto", device_map="auto")
# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(# "Qwen/Qwen2.5-VL-7B-Instruct",# torch_dtype=torch.bfloat16,# attn_implementation="flash_attention_2",# device_map="auto",# )
# default processerprocessor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
# The default range for the number of visual tokens per image in the model is 4-16384.# You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.# min_pixels = 256*28*28# max_pixels = 1280*28*28# processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
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 inferencetext = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs = process_vision_info(messages)inputs = processor( text=[text], images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt",)inputs = inputs.to("cuda")
# Inference: Generation of the outputgenerated_ids = model.generate(**inputs, max_new_tokens=128)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)```<details><summary>Multi image inference</summary>
```python# Messages containing multiple images and a text querymessages = [ { "role": "user", "content": [ {"type": "image", "image": "file:///path/to/image1.jpg"}, {"type": "image", "image": "file:///path/to/image2.jpg"}, {"type": "text", "text": "Identify the similarities between these images."}, ], }]
# Preparation for inferencetext = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs = process_vision_info(messages)inputs = processor( text=[text], images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt",)inputs = inputs.to("cuda")
# Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=128)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)```</details>
<details><summary>Video inference</summary>
```python# Messages containing a images list as a video and a text querymessages = [ { "role": "user", "content": [ { "type": "video", "video": [ "file:///path/to/frame1.jpg", "file:///path/to/frame2.jpg", "file:///path/to/frame3.jpg", "file:///path/to/frame4.jpg", ], }, {"type": "text", "text": "Describe this video."}, ], }]
# Messages containing a local video path and a text querymessages = [ { "role": "user", "content": [ { "type": "video", "video": "file:///path/to/video1.mp4", "max_pixels": 360 * 420, "fps": 1.0, }, {"type": "text", "text": "Describe this video."}, ], }]
# Messages containing a video url and a text querymessages = [ { "role": "user", "content": [ { "type": "video", "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4", }, {"type": "text", "text": "Describe this video."}, ], }]
#In Qwen 2.5 VL, frame rate information is also input into the model to align with absolute time.# Preparation for inferencetext = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)inputs = processor( text=[text], images=image_inputs, videos=video_inputs, fps=fps, padding=True, return_tensors="pt", **video_kwargs,)inputs = inputs.to("cuda")
# Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=128)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)```
Video URL compatibility largely depends on the third-party library version. The details are in the table below. change the backend by `FORCE_QWENVL_VIDEO_READER=torchvision` or `FORCE_QWENVL_VIDEO_READER=decord` if you prefer not to use the default one.
| Backend | HTTP | HTTPS ||-------------|------|-------|| torchvision >= 0.19.0 | ✅ | ✅ || torchvision < 0.19.0 | ❌ | ❌ || decord | ✅ | ❌ |</details>
<details><summary>Batch inference</summary>
```python# Sample messages for batch inferencemessages1 = [ { "role": "user", "content": [ {"type": "image", "image": "file:///path/to/image1.jpg"}, {"type": "image", "image": "file:///path/to/image2.jpg"}, {"type": "text", "text": "What are the common elements in these pictures?"}, ], }]messages2 = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Who are you?"},]# Combine messages for batch processingmessages = [messages1, messages2]
# Preparation for batch inferencetexts = [ processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True) for msg in messages]image_inputs, video_inputs = process_vision_info(messages)inputs = processor( text=texts, images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt",)inputs = inputs.to("cuda")
# Batch Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=128)generated_ids_trimmed = [ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]output_texts = processor.batch_decode( generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)print(output_texts)```</details>
### 🤖 ModelScopeWe strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
### More Usage Tips
For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
```python# You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.## Local file pathmessages = [ { "role": "user", "content": [ {"type": "image", "image": "file:///path/to/your/image.jpg"}, {"type": "text", "text": "Describe this image."}, ], }]## Image URLmessages = [ { "role": "user", "content": [ {"type": "image", "image": "http://path/to/your/image.jpg"}, {"type": "text", "text": "Describe this image."}, ], }]## Base64 encoded imagemessages = [ { "role": "user", "content": [ {"type": "image", "image": "data:image;base64,/9j/..."}, {"type": "text", "text": "Describe this image."}, ], }]```#### Image Resolution for performance boost
The model supports a wide range of resolution inputs. By default, it uses the native resolution for input, but higher resolutions can enhance performance at the cost of more computation. Users can set the minimum and maximum number of pixels to achieve an optimal configuration for their needs, such as a token count range of 256-1280, to balance speed and memory usage.
```pythonmin_pixels = 256 * 28 * 28max_pixels = 1280 * 28 * 28processor = AutoProcessor.from_pretrained( "Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)```
Besides, We provide two methods for fine-grained control over the image size input to the model:
1. Define min_pixels and max_pixels: Images will be resized to maintain their aspect ratio within the range of min_pixels and max_pixels. 2. Specify exact dimensions: Directly set `resized_height` and `resized_width`. These values will be rounded to the nearest multiple of 28.
```python# min_pixels and max_pixelsmessages = [ { "role": "user", "content": [ { "type": "image", "image": "file:///path/to/your/image.jpg", "resized_height": 280, "resized_width": 420, }, {"type": "text", "text": "Describe this image."}, ], }]# resized_height and resized_widthmessages = [ { "role": "user", "content": [ { "type": "image", "image": "file:///path/to/your/image.jpg", "min_pixels": 50176, "max_pixels": 50176, }, {"type": "text", "text": "Describe this image."}, ], }]```
### Processing Long Texts
The current `config.json` is set for context length up to 32,768 tokens.To handle extensive inputs exceeding 32,768 tokens, we utilize [YaRN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
For supported frameworks, you could add the following to `config.json` to enable YaRN:
{ ..., "type": "yarn", "mrope_section": [ 16, 24, 24 ], "factor": 4, "original_max_position_embeddings": 32768}
However, it should be noted that this method has a significant impact on the performance of temporal and spatial localization tasks, and is therefore not recommended for use.
At the same time, for long video inputs, since MRoPE itself is more economical with ids, the max_position_embeddings can be directly modified to a larger value, such as 64k.
## Citation
If you find our work helpful, feel free to give us a cite.
```@misc{qwen2.5-VL, title = {Qwen2.5-VL}, url = {https://qwenlm.github.io/blog/qwen2.5-vl/}, author = {Qwen Team}, month = {January}, year = {2025}}
@article{Qwen2VL, title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution}, author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang}, journal={arXiv preprint arXiv:2409.12191}, year={2024}}
@article{Qwen-VL, title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond}, author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren}, journal={arXiv preprint arXiv:2308.12966}, year={2023}}```123{ "chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "architectures": [ "Qwen2_5_VLForConditionalGeneration" ], "attention_dropout": 0.0, "bos_token_id": 151643, "eos_token_id": 151645, "vision_start_token_id": 151652, "vision_end_token_id": 151653, "vision_token_id": 151654, "image_token_id": 151655, "video_token_id": 151656, "hidden_act": "silu", "hidden_size": 3584, "initializer_range": 0.02, "intermediate_size": 18944, "max_position_embeddings": 128000, "max_window_layers": 28, "model_type": "qwen2_5_vl", "num_attention_heads": 28, "num_hidden_layers": 28, "num_key_value_heads": 4, "rms_norm_eps": 1e-06, "rope_theta": 1000000.0, "sliding_window": 32768, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.41.2", "use_cache": true, "use_sliding_window": false, "vision_config": { "depth": 32, "hidden_act": "silu", "hidden_size": 1280, "intermediate_size": 3420, "num_heads": 16, "in_chans": 3, "out_hidden_size": 3584, "patch_size": 14, "spatial_merge_size": 2, "spatial_patch_size": 14, "window_size": 112, "fullatt_block_indexes": [ 7, 15, 23, 31 ], "tokens_per_second": 2, "temporal_patch_size": 2, "_attn_implementation": "flash_attention_2" }, "rope_scaling": { "type": "mrope", "mrope_section": [ 16, 24, 24 ] }, "vocab_size": 152064}123456789101112{ "bos_token_id": 151643, "pad_token_id": 151643, "do_sample": true, "eos_token_id": [ 151645, 151643 ], "repetition_penalty": 1.05, "temperature": 0.000001, "transformers_version": "4.37.0"}12345678910111213141516171819{ "min_pixels": 3136, "max_pixels": 12845056, "patch_size": 14, "temporal_patch_size": 2, "merge_size": 2, "image_mean": [ 0.48145466, 0.4578275, 0.40821073 ], "image_std": [ 0.26862954, 0.26130258, 0.27577711 ], "image_processor_type": "Qwen2VLImageProcessor", "processor_class": "Qwen2_5_VLProcessor"}123version https://git-lfs.github.com/spec/v1oid sha256:c0382117ea329cdf097041132f6d735924b697924d6f6fc3945713e96ce87539size 7031645123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207{ "add_prefix_space": false, "added_tokens_decoder": { "151643": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151644": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151645": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151646": { "content": "<|object_ref_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151647": { "content": "<|object_ref_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151648": { "content": "<|box_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151649": { "content": "<|box_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151650": { "content": "<|quad_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151651": { "content": "<|quad_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151652": { "content": "<|vision_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151653": { "content": "<|vision_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151654": { "content": "<|vision_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151655": { "content": "<|image_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151656": { "content": "<|video_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151657": { "content": "<tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151658": { "content": "</tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151659": { "content": "<|fim_prefix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151660": { "content": "<|fim_middle|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151661": { "content": "<|fim_suffix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151662": { "content": "<|fim_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151663": { "content": "<|repo_name|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151664": { "content": "<|file_sep|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false } }, "additional_special_tokens": [ "<|im_start|>", "<|im_end|>", "<|object_ref_start|>", "<|object_ref_end|>", "<|box_start|>", "<|box_end|>", "<|quad_start|>", "<|quad_end|>", "<|vision_start|>", "<|vision_end|>", "<|vision_pad|>", "<|image_pad|>", "<|video_pad|>" ], "bos_token": null, "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "model_max_length": 131072, "pad_token": "<|endoftext|>", "split_special_tokens": false, "tokenizer_class": "Qwen2Tokenizer", "unk_token": null, "add_bos_token": false}123version https://git-lfs.github.com/spec/v1oid sha256:be42dc8dbf87c4ce54d470647725d106eb9491628b4f19662c784176310ed3dcsize 154944200891234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "architectures": [ "Qwen2_5_VLForConditionalGeneration" ], "attention_dropout": 0.0, "bos_token_id": 151643, "eos_token_id": 151645, "vision_start_token_id": 151652, "vision_end_token_id": 151653, "vision_token_id": 151654, "image_token_id": 151655, "video_token_id": 151656, "hidden_act": "silu", "hidden_size": 3584, "initializer_range": 0.02, "intermediate_size": 18944, "max_position_embeddings": 128000, "max_window_layers": 28, "model_type": "qwen2_5_vl", "num_attention_heads": 28, "num_hidden_layers": 28, "num_key_value_heads": 4, "rms_norm_eps": 1e-06, "rope_theta": 1000000.0, "sliding_window": 32768, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.41.2", "use_cache": true, "use_sliding_window": false, "vision_config": { "depth": 32, "hidden_act": "silu", "hidden_size": 1280, "intermediate_size": 3420, "num_heads": 16, "in_chans": 3, "out_hidden_size": 3584, "patch_size": 14, "spatial_merge_size": 2, "spatial_patch_size": 14, "window_size": 112, "fullatt_block_indexes": [ 7, 15, 23, 31 ], "tokens_per_second": 2, "temporal_patch_size": 2, "_attn_implementation": "flash_attention_2" }, "rope_scaling": { "type": "mrope", "mrope_section": [ 16, 24, 24 ] }, "vocab_size": 152064}123version https://git-lfs.github.com/spec/v1oid sha256:e86ee4199903e00a88dcd43583a43a6eb898cef600e38670f222d7e37d163787size 11361845505123version https://git-lfs.github.com/spec/v1oid sha256:6e197b4d3dbd71da14b4eb255f4fa91c9c1f2068b20a2de2472967ca3d22602bsize 16837417123456789101112131415161718192021222324{ "_class_name": "WanTransformer3DModel", "_diffusers_version": "0.35.0.dev0", "added_kv_proj_dim": null, "attention_head_dim": 128, "cross_attn_norm": true, "eps": 1e-06, "ffn_dim": 13824, "freq_dim": 256, "image_dim": null, "in_channels": 16, "num_attention_heads": 40, "num_layers": 40, "out_channels": 16, "patch_size": [ 1, 2, 2 ], "pos_embed_seq_len": null, "qk_norm": "rms_norm_across_heads", "rope_max_seq_len": 1024, "text_dim": 4096}123456789101112131415161718192021222324{ "_class_name": "WanTransformer3DModel", "_diffusers_version": "0.35.0.dev0", "added_kv_proj_dim": null, "attention_head_dim": 128, "cross_attn_norm": true, "eps": 1e-06, "ffn_dim": 13824, "freq_dim": 256, "image_dim": null, "in_channels": 16, "num_attention_heads": 40, "num_layers": 40, "out_channels": 16, "patch_size": [ 1, 2, 2 ], "pos_embed_seq_len": null, "qk_norm": "rms_norm_across_heads", "rope_max_seq_len": 1024, "text_dim": 4096}123version https://git-lfs.github.com/spec/v1oid sha256:977530e453dbfabbab31e2972e1577d8d7e2840ba7410c81aa3fd421c0cd7414size 507591226123version https://git-lfs.github.com/spec/v1oid sha256:e66bb23fcbbfa0686fad68c70ef3fcd758440a6e118e12e980fcce263e27cb0esize 2876184157123456789101112131415161718192021222324252627282930313233343536*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text1234567891011121314151617181920212223242526272829303132333435363738394041424344---license: apache-2.0library_name: mlxpipeline_tag: text-to-videotags: - mlx - apple-silicon - text-to-video - text-to-image - bernini - wan2.2 - qwen2.5-vlbase_model: - ByteDance/Bernini-Diffusers - Wan-AI/Wan2.2-T2V-A14B---
# Bernini — MLX (full planner + renderer)
Native **Apple Silicon / MLX** conversion of ByteDance **Bernini** (the full pipeline), packaged forin-process generation in [SceneWorks](https://github.com/michaeltrefry). Bernini is a**Latent Semantic Planning** model: a Qwen2.5-VL-7B semantic planner (MAR loop) drives a**Wan2.2-T2V-A14B** dual-expert renderer.
This is a turnkey, self-contained snapshot — no diffusers source or separate Wan base is needed atruntime. It loads directly via `mlx_gen::load("bernini")` (mlx-gen-bernini) and is quantized to**Q4 (default) / Q8 (opt-in)** at load time.
## Contents- `qwen2_5_vl.safetensors` + `qwen2_5_vl_config.json` — Qwen2.5-VL-7B planner backbone + vision tower- `connector.safetensors`, `vit_decoder.safetensors`, `mask_tokens.safetensors` — MLP connector, ViT decoder (clip-diff flow head), MAR mask token- `high_noise_model.safetensors` + `low_noise_model.safetensors` — the Wan2.2 dual-expert renderer DiTs- `t5_encoder.safetensors` + `tokenizer.json` — UMT5-XXL text encoder + tokenizer- `vae.safetensors` — z16 AutoencoderKLWan- `mllm/` — Qwen ChatML tokenizer/config; `*.json` sidecars — config + planner/renderer knobs
`dtype`: bf16. Validated on a 128 GB Apple Silicon Mac for **text-to-image** and **text-to-video**(~44 GB peak at Q4).
## Credits & licenseDerived from [ByteDance/Bernini-Diffusers](https://huggingface.co/ByteDance/Bernini-Diffusers) and[Wan-AI/Wan2.2-T2V-A14B](https://huggingface.co/Wan-AI/Wan2.2-T2V-A14B) (the renderer's stock UMT5/VAE),both Apache-2.0. Conversion/packaging by SceneWorks; released under Apache-2.0.12345678910111213141516171819202122232425262728293031{ "boundary_ratio": 0.417, "clip_diff_cfg": { "diffusion_batch_mul": 16, "model_type": "flow_match", "shift": 2.0, "target_channels": 3584, "width": 4096, "z_channels": 3584 }, "connector_cfg": { "enable_gen_branch": true, "enable_vit_branch": true, "gen_head_type": "zerolinear", "model_type": "MLPConnector", "out_dim_for_gen": 4096, "out_dim_for_vit": 3584, "zero_init_proj_gen_last": true }, "feature_type_from_stage_one": "masked_tgt_embed_with_qwen_txt_vit_tokens", "interpolate_src_id": true, "max_sequence_length": 512, "max_trained_src_id": 5, "num_mask_token": 4096, "shift": 3.0, "switch_dit_boundary": 0.875, "t5_combine_type": "concat_with_zero_init", "t5_max_sequence_length": 512, "target_fps": 16, "use_src_id_rotary_emb": true}123456789{ "flow_shift": 5.0, "interpolate_src_id": true, "max_sequence_length": 512, "max_trained_src_id": 5, "shift": 3.0, "switch_dit_boundary": 0.875, "use_src_id_rotary_emb": true}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455{ "boundary": 0.875, "cross_attn_norm": true, "dim": 5120, "dual_model": true, "eps": 1e-6, "ffn_dim": 13824, "frame_num": 81, "freq_dim": 256, "in_dim": 16, "max_area": 0, "model_type": "t2v", "model_version": "2.2", "num_heads": 40, "num_layers": 40, "num_train_timesteps": 1000, "out_dim": 16, "patch_size": [ 1, 2, 2 ], "qk_norm": true, "sample_fps": 16, "sample_guide_scale": [ 3.0, 4.0 ], "sample_neg_prompt": "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走", "sample_shift": 12.0, "sample_steps": 40, "t5_dim": 4096, "t5_dim_attn": 4096, "t5_dim_ffn": 10240, "t5_num_buckets": 32, "t5_num_heads": 64, "t5_num_layers": 24, "t5_vocab_size": 256384, "text_dim": 4096, "text_len": 512, "vae_stride": [ 4, 8, 8 ], "vae_z_dim": 16, "window_size": [ -1, -1 ], "quantization": { "bits": 4, "group_size": 64 }}123version https://git-lfs.github.com/spec/v1oid sha256:0b1d7adbc3489c3ab280e49a9359bdcc21b271106ed883a051ca79e3fcbb74eesize 140039232123version https://git-lfs.github.com/spec/v1oid sha256:2df1654d17aa80b78654e4f6ca10a6230f8a54ad4148317b7cc05f35f3baf688size 8378982803123version https://git-lfs.github.com/spec/v1oid sha256:651e8020d83a03c8d3f32da35a5b062e950c2c824ca2a4dec4d34a390b3770aesize 8378982823123version https://git-lfs.github.com/spec/v1oid sha256:00d9dcbc12a9ba798f06518d6afe4773796a5390e0d37c9ed92d0114a7cdd2a3size 293602381234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
---license: apache-2.0language:- enpipeline_tag: image-text-to-texttags:- multimodallibrary_name: transformers---
# Qwen2.5-VL-7B-Instruct<a href="https://chat.qwenlm.ai/" target="_blank" style="margin: 2px;"> <img alt="Chat" src="https://img.shields.io/badge/%F0%9F%92%9C%EF%B8%8F%20Qwen%20Chat%20-536af5" style="display: inline-block; vertical-align: middle;"/></a>
## Introduction
In the past five months since Qwen2-VL’s release, numerous developers have built new models on the Qwen2-VL vision-language models, providing us with valuable feedback. During this period, we focused on building more useful vision-language models. Today, we are excited to introduce the latest addition to the Qwen family: Qwen2.5-VL.
#### Key Enhancements:* **Understand things visually**: Qwen2.5-VL is not only proficient in recognizing common objects such as flowers, birds, fish, and insects, but it is highly capable of analyzing texts, charts, icons, graphics, and layouts within images.
* **Being agentic**: Qwen2.5-VL directly plays as a visual agent that can reason and dynamically direct tools, which is capable of computer use and phone use.
* **Understanding long videos and capturing events**: Qwen2.5-VL can comprehend videos of over 1 hour, and this time it has a new ability of cpaturing event by pinpointing the relevant video segments.
* **Capable of visual localization in different formats**: Qwen2.5-VL can accurately localize objects in an image by generating bounding boxes or points, and it can provide stable JSON outputs for coordinates and attributes.
* **Generating structured outputs**: for data like scans of invoices, forms, tables, etc. Qwen2.5-VL supports structured outputs of their contents, benefiting usages in finance, commerce, etc.
#### Model Architecture Updates:
* **Dynamic Resolution and Frame Rate Training for Video Understanding**:
We extend dynamic resolution to the temporal dimension by adopting dynamic FPS sampling, enabling the model to comprehend videos at various sampling rates. Accordingly, we update mRoPE in the time dimension with IDs and absolute time alignment, enabling the model to learn temporal sequence and speed, and ultimately acquire the ability to pinpoint specific moments.
<p align="center"> <img src="https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-VL/qwen2.5vl_arc.jpeg" width="80%"/><p>
* **Streamlined and Efficient Vision Encoder**
We enhance both training and inference speeds by strategically implementing window attention into the ViT. The ViT architecture is further optimized with SwiGLU and RMSNorm, aligning it with the structure of the Qwen2.5 LLM.
We have three models with 3, 7 and 72 billion parameters. This repo contains the instruction-tuned 7B Qwen2.5-VL model. For more information, visit our [Blog](https://qwenlm.github.io/blog/qwen2.5-vl/) and [GitHub](https://github.com/QwenLM/Qwen2.5-VL).
## Evaluation
### Image benchmark
| Benchmark | InternVL2.5-8B | MiniCPM-o 2.6 | GPT-4o-mini | Qwen2-VL-7B |**Qwen2.5-VL-7B** || :--- | :---: | :---: | :---: | :---: | :---: || MMMU<sub>val</sub> | 56 | 50.4 | **60**| 54.1 | 58.6|| MMMU-Pro<sub>val</sub> | 34.3 | - | 37.6| 30.5 | 41.0|| DocVQA<sub>test</sub> | 93 | 93 | - | 94.5 | **95.7** || InfoVQA<sub>test</sub> | 77.6 | - | - |76.5 | **82.6** || ChartQA<sub>test</sub> | 84.8 | - |- | 83.0 |**87.3** || TextVQA<sub>val</sub> | 79.1 | 80.1 | -| 84.3 | **84.9**|| OCRBench | 822 | 852 | 785 | 845 | **864** || CC_OCR | 57.7 | | | 61.6 | **77.8**|| MMStar | 62.8| | |60.7| **63.9**|| MMBench-V1.1-En<sub>test</sub> | 79.4 | 78.0 | 76.0| 80.7 | **82.6** || MMT-Bench<sub>test</sub> | - | - | - |**63.7** |63.6 || MMStar | **61.5** | 57.5 | 54.8 | 60.7 |63.9 || MMVet<sub>GPT-4-Turbo</sub> | 54.2 | 60.0 | 66.9 | 62.0 | **67.1**|| HallBench<sub>avg</sub> | 45.2 | 48.1 | 46.1| 50.6 | **52.9**|| MathVista<sub>testmini</sub> | 58.3 | 60.6 | 52.4 | 58.2 | **68.2**|| MathVision | - | - | - | 16.3 | **25.07** |
### Video Benchmarks
| Benchmark | Qwen2-VL-7B | **Qwen2.5-VL-7B** || :--- | :---: | :---: || MVBench | 67.0 | **69.6** || PerceptionTest<sub>test</sub> | 66.9 | **70.5** || Video-MME<sub>wo/w subs</sub> | 63.3/69.0 | **65.1**/**71.6** || LVBench | | 45.3 || LongVideoBench | | 54.7 || MMBench-Video | 1.44 | 1.79 || TempCompass | | 71.7 || MLVU | | 70.2 || CharadesSTA/mIoU | 43.6|
### Agent benchmark| Benchmarks | Qwen2.5-VL-7B ||-------------------------|---------------|| ScreenSpot | 84.7 || ScreenSpot Pro | 29.0 || AITZ_EM | 81.9 || Android Control High_EM | 60.1 || Android Control Low_EM | 93.7 || AndroidWorld_SR | 25.5 || MobileMiniWob++_SR | 91.4 |
## RequirementsThe code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:```pip install git+https://github.com/huggingface/transformers accelerate```or you might encounter the following error:```KeyError: 'qwen2_5_vl'```
## Quickstart
Below, we provide simple examples to show how to use Qwen2.5-VL with 🤖 ModelScope and 🤗 Transformers.
The code of Qwen2.5-VL has been in the latest Hugging face transformers and we advise you to build from source with command:```pip install git+https://github.com/huggingface/transformers accelerate```or you might encounter the following error:```KeyError: 'qwen2_5_vl'```
We offer a toolkit to help you handle various types of visual input more conveniently, as if you were using an API. This includes base64, URLs, and interleaved images and videos. You can install it using the following command:
```bash# It's highly recommanded to use `[decord]` feature for faster video loading.pip install qwen-vl-utils[decord]==0.0.8```
If you are not using Linux, you might not be able to install `decord` from PyPI. In that case, you can use `pip install qwen-vl-utils` which will fall back to using torchvision for video processing. However, you can still [install decord from source](https://github.com/dmlc/decord?tab=readme-ov-file#install-from-source) to get decord used when loading video.
### Using 🤗 Transformers to Chat
Here we show a code snippet to show you how to use the chat model with `transformers` and `qwen_vl_utils`:
```pythonfrom transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessorfrom qwen_vl_utils import process_vision_info
# default: Load the model on the available device(s)model = Qwen2_5_VLForConditionalGeneration.from_pretrained( "Qwen/Qwen2.5-VL-7B-Instruct", torch_dtype="auto", device_map="auto")
# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.# model = Qwen2_5_VLForConditionalGeneration.from_pretrained(# "Qwen/Qwen2.5-VL-7B-Instruct",# torch_dtype=torch.bfloat16,# attn_implementation="flash_attention_2",# device_map="auto",# )
# default processerprocessor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct")
# The default range for the number of visual tokens per image in the model is 4-16384.# You can set min_pixels and max_pixels according to your needs, such as a token range of 256-1280, to balance performance and cost.# min_pixels = 256*28*28# max_pixels = 1280*28*28# processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
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 inferencetext = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs = process_vision_info(messages)inputs = processor( text=[text], images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt",)inputs = inputs.to("cuda")
# Inference: Generation of the outputgenerated_ids = model.generate(**inputs, max_new_tokens=128)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)```<details><summary>Multi image inference</summary>
```python# Messages containing multiple images and a text querymessages = [ { "role": "user", "content": [ {"type": "image", "image": "file:///path/to/image1.jpg"}, {"type": "image", "image": "file:///path/to/image2.jpg"}, {"type": "text", "text": "Identify the similarities between these images."}, ], }]
# Preparation for inferencetext = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs = process_vision_info(messages)inputs = processor( text=[text], images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt",)inputs = inputs.to("cuda")
# Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=128)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)```</details>
<details><summary>Video inference</summary>
```python# Messages containing a images list as a video and a text querymessages = [ { "role": "user", "content": [ { "type": "video", "video": [ "file:///path/to/frame1.jpg", "file:///path/to/frame2.jpg", "file:///path/to/frame3.jpg", "file:///path/to/frame4.jpg", ], }, {"type": "text", "text": "Describe this video."}, ], }]
# Messages containing a local video path and a text querymessages = [ { "role": "user", "content": [ { "type": "video", "video": "file:///path/to/video1.mp4", "max_pixels": 360 * 420, "fps": 1.0, }, {"type": "text", "text": "Describe this video."}, ], }]
# Messages containing a video url and a text querymessages = [ { "role": "user", "content": [ { "type": "video", "video": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2-VL/space_woaudio.mp4", }, {"type": "text", "text": "Describe this video."}, ], }]
#In Qwen 2.5 VL, frame rate information is also input into the model to align with absolute time.# Preparation for inferencetext = processor.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs, video_kwargs = process_vision_info(messages, return_video_kwargs=True)inputs = processor( text=[text], images=image_inputs, videos=video_inputs, fps=fps, padding=True, return_tensors="pt", **video_kwargs,)inputs = inputs.to("cuda")
# Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=128)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)```
Video URL compatibility largely depends on the third-party library version. The details are in the table below. change the backend by `FORCE_QWENVL_VIDEO_READER=torchvision` or `FORCE_QWENVL_VIDEO_READER=decord` if you prefer not to use the default one.
| Backend | HTTP | HTTPS ||-------------|------|-------|| torchvision >= 0.19.0 | ✅ | ✅ || torchvision < 0.19.0 | ❌ | ❌ || decord | ✅ | ❌ |</details>
<details><summary>Batch inference</summary>
```python# Sample messages for batch inferencemessages1 = [ { "role": "user", "content": [ {"type": "image", "image": "file:///path/to/image1.jpg"}, {"type": "image", "image": "file:///path/to/image2.jpg"}, {"type": "text", "text": "What are the common elements in these pictures?"}, ], }]messages2 = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Who are you?"},]# Combine messages for batch processingmessages = [messages1, messages2]
# Preparation for batch inferencetexts = [ processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True) for msg in messages]image_inputs, video_inputs = process_vision_info(messages)inputs = processor( text=texts, images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt",)inputs = inputs.to("cuda")
# Batch Inferencegenerated_ids = model.generate(**inputs, max_new_tokens=128)generated_ids_trimmed = [ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)]output_texts = processor.batch_decode( generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)print(output_texts)```</details>
### 🤖 ModelScopeWe strongly advise users especially those in mainland China to use ModelScope. `snapshot_download` can help you solve issues concerning downloading checkpoints.
### More Usage Tips
For input images, we support local files, base64, and URLs. For videos, we currently only support local files.
```python# You can directly insert a local file path, a URL, or a base64-encoded image into the position where you want in the text.## Local file pathmessages = [ { "role": "user", "content": [ {"type": "image", "image": "file:///path/to/your/image.jpg"}, {"type": "text", "text": "Describe this image."}, ], }]## Image URLmessages = [ { "role": "user", "content": [ {"type": "image", "image": "http://path/to/your/image.jpg"}, {"type": "text", "text": "Describe this image."}, ], }]## Base64 encoded imagemessages = [ { "role": "user", "content": [ {"type": "image", "image": "data:image;base64,/9j/..."}, {"type": "text", "text": "Describe this image."}, ], }]```#### Image Resolution for performance boost
The model supports a wide range of resolution inputs. By default, it uses the native resolution for input, but higher resolutions can enhance performance at the cost of more computation. Users can set the minimum and maximum number of pixels to achieve an optimal configuration for their needs, such as a token count range of 256-1280, to balance speed and memory usage.
```pythonmin_pixels = 256 * 28 * 28max_pixels = 1280 * 28 * 28processor = AutoProcessor.from_pretrained( "Qwen/Qwen2.5-VL-7B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)```
Besides, We provide two methods for fine-grained control over the image size input to the model:
1. Define min_pixels and max_pixels: Images will be resized to maintain their aspect ratio within the range of min_pixels and max_pixels. 2. Specify exact dimensions: Directly set `resized_height` and `resized_width`. These values will be rounded to the nearest multiple of 28.
```python# min_pixels and max_pixelsmessages = [ { "role": "user", "content": [ { "type": "image", "image": "file:///path/to/your/image.jpg", "resized_height": 280, "resized_width": 420, }, {"type": "text", "text": "Describe this image."}, ], }]# resized_height and resized_widthmessages = [ { "role": "user", "content": [ { "type": "image", "image": "file:///path/to/your/image.jpg", "min_pixels": 50176, "max_pixels": 50176, }, {"type": "text", "text": "Describe this image."}, ], }]```
### Processing Long Texts
The current `config.json` is set for context length up to 32,768 tokens.To handle extensive inputs exceeding 32,768 tokens, we utilize [YaRN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
For supported frameworks, you could add the following to `config.json` to enable YaRN:
{ ..., "type": "yarn", "mrope_section": [ 16, 24, 24 ], "factor": 4, "original_max_position_embeddings": 32768}
However, it should be noted that this method has a significant impact on the performance of temporal and spatial localization tasks, and is therefore not recommended for use.
At the same time, for long video inputs, since MRoPE itself is more economical with ids, the max_position_embeddings can be directly modified to a larger value, such as 64k.
## Citation
If you find our work helpful, feel free to give us a cite.
```@misc{qwen2.5-VL, title = {Qwen2.5-VL}, url = {https://qwenlm.github.io/blog/qwen2.5-vl/}, author = {Qwen Team}, month = {January}, year = {2025}}
@article{Qwen2VL, title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution}, author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang}, journal={arXiv preprint arXiv:2409.12191}, year={2024}}
@article{Qwen-VL, title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond}, author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren}, journal={arXiv preprint arXiv:2308.12966}, year={2023}}```123{ "chat_template": "{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n{% endif %}<|im_start|>{{ message['role'] }}\n{% if message['content'] is string %}{{ message['content'] }}<|im_end|>\n{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>\n{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "architectures": [ "Qwen2_5_VLForConditionalGeneration" ], "attention_dropout": 0.0, "bos_token_id": 151643, "eos_token_id": 151645, "vision_start_token_id": 151652, "vision_end_token_id": 151653, "vision_token_id": 151654, "image_token_id": 151655, "video_token_id": 151656, "hidden_act": "silu", "hidden_size": 3584, "initializer_range": 0.02, "intermediate_size": 18944, "max_position_embeddings": 128000, "max_window_layers": 28, "model_type": "qwen2_5_vl", "num_attention_heads": 28, "num_hidden_layers": 28, "num_key_value_heads": 4, "rms_norm_eps": 1e-06, "rope_theta": 1000000.0, "sliding_window": 32768, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.41.2", "use_cache": true, "use_sliding_window": false, "vision_config": { "depth": 32, "hidden_act": "silu", "hidden_size": 1280, "intermediate_size": 3420, "num_heads": 16, "in_chans": 3, "out_hidden_size": 3584, "patch_size": 14, "spatial_merge_size": 2, "spatial_patch_size": 14, "window_size": 112, "fullatt_block_indexes": [ 7, 15, 23, 31 ], "tokens_per_second": 2, "temporal_patch_size": 2, "_attn_implementation": "flash_attention_2" }, "rope_scaling": { "type": "mrope", "mrope_section": [ 16, 24, 24 ] }, "vocab_size": 152064}123456789101112{ "bos_token_id": 151643, "pad_token_id": 151643, "do_sample": true, "eos_token_id": [ 151645, 151643 ], "repetition_penalty": 1.05, "temperature": 0.000001, "transformers_version": "4.37.0"}12345678910111213141516171819{ "min_pixels": 3136, "max_pixels": 12845056, "patch_size": 14, "temporal_patch_size": 2, "merge_size": 2, "image_mean": [ 0.48145466, 0.4578275, 0.40821073 ], "image_std": [ 0.26862954, 0.26130258, 0.27577711 ], "image_processor_type": "Qwen2VLImageProcessor", "processor_class": "Qwen2_5_VLProcessor"}123version https://git-lfs.github.com/spec/v1oid sha256:c0382117ea329cdf097041132f6d735924b697924d6f6fc3945713e96ce87539size 7031645123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207{ "add_prefix_space": false, "added_tokens_decoder": { "151643": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151644": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151645": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151646": { "content": "<|object_ref_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151647": { "content": "<|object_ref_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151648": { "content": "<|box_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151649": { "content": "<|box_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151650": { "content": "<|quad_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151651": { "content": "<|quad_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151652": { "content": "<|vision_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151653": { "content": "<|vision_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151654": { "content": "<|vision_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151655": { "content": "<|image_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151656": { "content": "<|video_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151657": { "content": "<tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151658": { "content": "</tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151659": { "content": "<|fim_prefix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151660": { "content": "<|fim_middle|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151661": { "content": "<|fim_suffix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151662": { "content": "<|fim_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151663": { "content": "<|repo_name|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151664": { "content": "<|file_sep|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false } }, "additional_special_tokens": [ "<|im_start|>", "<|im_end|>", "<|object_ref_start|>", "<|object_ref_end|>", "<|box_start|>", "<|box_end|>", "<|quad_start|>", "<|quad_end|>", "<|vision_start|>", "<|vision_end|>", "<|vision_pad|>", "<|image_pad|>", "<|video_pad|>" ], "bos_token": null, "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- messages[0]['content'] }}\n {%- else %}\n {{- 'You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + message.content }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "model_max_length": 131072, "pad_token": "<|endoftext|>", "split_special_tokens": false, "tokenizer_class": "Qwen2Tokenizer", "unk_token": null, "add_bos_token": false}123version https://git-lfs.github.com/spec/v1oid sha256:aefbf899795a73b43539f5ce425fddc4618fe38dc07b103a0ee313ea775bfe2esize 6114361498123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566{ "architectures": [ "Qwen2_5_VLForConditionalGeneration" ], "attention_dropout": 0.0, "bos_token_id": 151643, "eos_token_id": 151645, "vision_start_token_id": 151652, "vision_end_token_id": 151653, "vision_token_id": 151654, "image_token_id": 151655, "video_token_id": 151656, "hidden_act": "silu", "hidden_size": 3584, "initializer_range": 0.02, "intermediate_size": 18944, "max_position_embeddings": 128000, "max_window_layers": 28, "model_type": "qwen2_5_vl", "num_attention_heads": 28, "num_hidden_layers": 28, "num_key_value_heads": 4, "rms_norm_eps": 1e-6, "rope_theta": 1000000.0, "sliding_window": 32768, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.41.2", "use_cache": true, "use_sliding_window": false, "vision_config": { "depth": 32, "hidden_act": "silu", "hidden_size": 1280, "intermediate_size": 3420, "num_heads": 16, "in_chans": 3, "out_hidden_size": 3584, "patch_size": 14, "spatial_merge_size": 2, "spatial_patch_size": 14, "window_size": 112, "fullatt_block_indexes": [ 7, 15, 23, 31 ], "tokens_per_second": 2, "temporal_patch_size": 2, "_attn_implementation": "flash_attention_2" }, "rope_scaling": { "type": "mrope", "mrope_section": [ 16, 24, 24 ] }, "vocab_size": 152064, "quantization": { "bits": 4, "group_size": 64 }}123version https://git-lfs.github.com/spec/v1oid sha256:e86ee4199903e00a88dcd43583a43a6eb898cef600e38670f222d7e37d163787size 11361845505123version https://git-lfs.github.com/spec/v1oid sha256:6e197b4d3dbd71da14b4eb255f4fa91c9c1f2068b20a2de2472967ca3d22602bsize 16837417bf16/.gitattributesAdded+36
bf16/README.mdAdded+44
bf16/bernini_planner.jsonAdded+31
bf16/bernini_renderer.jsonAdded+9
bf16/config.jsonAdded+51
bf16/connector.safetensorsAdded+3
bf16/high_noise_model.safetensorsAdded+3
bf16/low_noise_model.safetensorsAdded+3
bf16/mask_tokens.safetensorsAdded+3
bf16/mllm/.gitattributesAdded+35
bf16/mllm/README.mdAdded+528
bf16/mllm/chat_template.jsonAdded+3
bf16/mllm/config.jsonAdded+62
bf16/mllm/generation_config.jsonAdded+12
bf16/mllm/merges.txtAdded
bf16/mllm/preprocessor_config.jsonAdded+19
bf16/mllm/tokenizer.jsonAdded+3
bf16/mllm/tokenizer_config.jsonAdded+207
bf16/mllm/vocab.jsonAdded
bf16/qwen2_5_vl.safetensorsAdded+3
bf16/qwen2_5_vl_config.jsonAdded+62
bf16/t5_encoder.safetensorsAdded+3
bf16/tokenizer.jsonAdded+3
bf16/transformer_2_config.jsonAdded+24
bf16/transformer_config.jsonAdded+24
bf16/vae.safetensorsAdded+3
bf16/vit_decoder.safetensorsAdded+3
q4/.gitattributesAdded+36
q4/README.mdAdded+44
q4/bernini_planner.jsonAdded+31
q4/bernini_renderer.jsonAdded+9
q4/config.jsonAdded+55
q4/connector.safetensorsAdded+3
q4/high_noise_model.safetensorsAdded+3
q4/low_noise_model.safetensorsAdded+3
q4/mask_tokens.safetensorsAdded+3
q4/mllm/.gitattributesAdded+35
q4/mllm/README.mdAdded+528
q4/mllm/chat_template.jsonAdded+3
q4/mllm/config.jsonAdded+62
q4/mllm/generation_config.jsonAdded+12
q4/mllm/merges.txtAdded
q4/mllm/preprocessor_config.jsonAdded+19
q4/mllm/tokenizer.jsonAdded+3
q4/mllm/tokenizer_config.jsonAdded+207
q4/mllm/vocab.jsonAdded
q4/qwen2_5_vl.safetensorsAdded+3
q4/qwen2_5_vl_config.jsonAdded+66
q4/t5_encoder.safetensorsAdded+3
q4/tokenizer.jsonAdded+3