--- license: cc-by-nc-4.0 library_name: transformers pipeline_tag: video-text-to-text base_model: - Qwen/Qwen3.5-9B - facebook/VGGT-1B tags: - spatial-reasoning - 3d - video - multimodal - vggt - qwen3.5 --- # SpaceTimeVLM-9B SpaceTimeVLM gives a video language model a 3D view of the scene. It is [Qwen/Qwen3.5-9B](https://huggingface.co/Qwen/Qwen3.5-9B) with the frozen geometry encoder of [VGGT-1B](https://huggingface.co/facebook/VGGT-1B) read through a 3D-aware cross-attention: 1. Qwen3.5's vision encoder turns each frame into visual tokens (one per 28 x 28 px cell). 2. VGGT-1B runs on the same frames. Its point head gives a 3D point per pixel, which is averaged per cell, so every visual token gets a position in the scene. 3. After decoder layers 0, 1 and 2, every visual token attends over the geometry tokens of all frames (VGGT layers 11, 17 and 23, one token per cell), with a rotary embedding on (frame, x, y, z) and a learned 3D-distance bias. The result is added to the visual token. The language model was fine-tuned with LoRA (merged into the weights here); the mergers and the cross-attention were trained from scratch; VGGT is unchanged. VSI-Bench: **73.29** (32 frames). ## Usage ```bash pip install torch torchvision transformers==5.20.1 accelerate decord ``` ```python from huggingface_hub import hf_hub_download from transformers import AutoModel video = hf_hub_download("DarioVajda/SpaceTimeVLM-9B", "examples/room.mp4") # a 29 s walkthrough of a dining room and kitchen model = AutoModel.from_pretrained("DarioVajda/SpaceTimeVLM-9B", trust_remote_code=True, device_map="cuda") print(model.chat(video, "How many chairs are in this room?")) ``` ### Expected output ``` 6 ``` ![Four frames of the example video, the question and this model's answer](https://huggingface.co/DarioVajda/SpaceTimeVLM-9B/resolve/main/examples/expected_output.jpg) Four of the video's frames (at 2, 14, 16 and 18 s); the model itself sees 32 frames sampled uniformly over the 29 s. There are six chairs: two on each long side of the dining table and one at each end. The example video is an excerpt of [UE4Arch.com - Viennese apartment](https://commons.wikimedia.org/wiki/File:UE4Arch.com_-_Viennese_apartment.webm) by UE4Arch.com (CC BY-SA 4.0), cut to 82-111 s and scaled to 960 x 540; see `examples/README.md`. Use your own video by passing its path instead. `chat` takes a video file, a directory of frames, or a list of images (paths or PIL images), and one question or a list of questions about the same video (answered in one batch). It samples 32 uniformly spaced frames by default (`num_frames=...`). Answers are greedy; `max_new_tokens` defaults to 256. For full control, `model.prepare(frames, questions)` builds the inputs and `model.answer(batch, **generate_kwargs)` decodes them. The benchmark scores below use the lmms-eval prompts, for example for VSI-Bench: ```python q = "These are frames of a video.\nHow many chairs are in this room?\nPlease answer the question using a single word or phrase." q = "These are frames of a video.\nWhich is closer to the sofa, the lamp or the table?\nOptions:\nA. lamp\nB. table\nAnswer with the option's letter from the given choices directly." ``` **Requirements:** a CUDA GPU, `transformers==5.20.1` (the version it was tested with), `torch`, `torchvision`, `accelerate`, and `decord` or `av` to read videos. Install `flash-linear-attention` and `causal-conv1d` for Qwen3.5's fast linear-attention kernels; without them it falls back to a slow PyTorch path. Qwen3.5 runs in bfloat16; VGGT and the cross-attention keep float32 weights and run under bfloat16 autocast, as in training. ## Results Results across six spatial benchmarks (%). Avg. is the mean of the six overall scores. Higher is better. **Bold** and underlined mark the best and second best results in each column. | Model | Avg. | VSI-Bench | MMSI-Bench | MindCube | ViewSpatial | SITE | CV-Bench | |---|---:|---:|---:|---:|---:|---:|---:| | Qwen2.5-VL-7B | 40.31 | 29.30 | 26.80 | 36.00 | 36.80 | 37.60 | 75.40 | | Qwen3-VL-8B | 47.73 | 57.90 | 28.80 | 29.80 | 39.00 | 45.80 | 85.10 | | Qwen3.5-2B | 42.83 | 45.72 | 26.30 | 34.86 | 36.28 | 31.45 | 82.34 | | Qwen3.5-4B | 50.36 | 53.00 | 31.80 | 44.67 | 40.22 | 45.36 | 87.11 | | Qwen3.5-9B | 52.87 | 60.80 | 31.90 | 44.10 | 44.07 | 48.27 | 88.06 | | Qwen3.5-35B-A3B | 55.18 | 63.79 | 34.60 | 39.81 | 47.79 | 56.09 | **89.01** | | | | | | | | | | | Cambrian-S-7B | 47.28 | 67.50 | 25.80 | 39.60 | 40.90 | 33.00 | 76.90 | | VLM-3R-7B | 45.40 | 60.90 | 27.90 | 40.00 | 40.50 | 31.30 | 71.80 | | VG-LLM-8B | 51.05 | 62.20 | 30.00 | 36.10 | 45.80 | 50.50 | 81.70 | | GeoThinker-7B | 60.43 | 68.50 | 31.70 | 83.60 | 41.90 | 54.80 | 82.10 | | GeoThinker-8B | 62.23 | 72.60 | 30.90 | 83.00 | 45.90 | 55.90 | 85.10 | | DK-VLM-7B | 60.84 | 69.42 | 29.95 | 83.81 | 44.98 | 57.47 | 79.38 | | DK-VLM-8B | 64.09 | **74.33** | 30.79 | 83.83 | 51.25 | **59.81** | 84.52 | | | | | | | | | | | SpaceTimeVLM-2B | 57.85 | 69.22 | 27.40 | 90.95 | 46.44 | 34.40 | 78.67 | | SpaceTimeVLM-4B | 61.94 | 71.97 | 30.60 | 92.57 | 47.23 | 44.74 | 84.54 | | ➡️ **SpaceTimeVLM-9B (this model)** | 64.50 | 73.29 | 32.20 | 94.19 | 49.66 | 50.56 | 87.08 | | SpaceTimeVLM-35B-A3B | **66.95** | 73.22 | **35.90** | **94.95** | **53.77** | 55.54 | 88.31 | ## Training - Base: Qwen/Qwen3.5-9B (revision `c20223623576`), VGGT-1B (revision `860abec7937d`, frozen). - LoRA rank 64, alpha 128 on all linear layers of the language model; the vision encoder is frozen. - 500k question-answer pairs over videos and image sets (spatial and general video understanding), with 8, 16 or 32 frames per sample (60 / 30 / 10 %); 17,201 steps (warmup-stable-decay schedule). ## License and credits This model combines: - [Qwen3.5](https://huggingface.co/Qwen/Qwen3.5-9B) by the Qwen team (Apache 2.0, `LICENSE-QWEN`); - [VGGT](https://github.com/facebookresearch/vggt) by Meta (the code is under the VGGT License, `LICENSE-VGGT`; the VGGT-1B weights are released for non-commercial use). The VGGT modules in `vggt_*.py` are copied from the VGGT repository with only their imports changed. Because of the VGGT weights, the model as a whole is released under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) (non-commercial use only). The example video (`examples/room.mp4`) is not part of the model; it is under CC BY-SA 4.0 (see `examples/README.md`).