Image-Text-to-Text
Transformers
Safetensors
qwen3_5
decision-model
typed-decisions
multimodal
conversational
Instructions to use inclusionAI/SingVL_S1_4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use inclusionAI/SingVL_S1_4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="inclusionAI/SingVL_S1_4B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("inclusionAI/SingVL_S1_4B") model = AutoModelForMultimodalLM.from_pretrained("inclusionAI/SingVL_S1_4B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use inclusionAI/SingVL_S1_4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "inclusionAI/SingVL_S1_4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "inclusionAI/SingVL_S1_4B", "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/inclusionAI/SingVL_S1_4B
- SGLang
How to use inclusionAI/SingVL_S1_4B 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 "inclusionAI/SingVL_S1_4B" \ --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": "inclusionAI/SingVL_S1_4B", "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 "inclusionAI/SingVL_S1_4B" \ --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": "inclusionAI/SingVL_S1_4B", "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 inclusionAI/SingVL_S1_4B with Docker Model Runner:
docker model run hf.co/inclusionAI/SingVL_S1_4B
Upload 5 files
Browse files- inference/DECISION_INDEX.md +10 -17
- inference/README.md +9 -11
- inference/SHA256SUMS +4 -4
- inference/model.py +108 -11
- inference/release.json +11 -3
inference/DECISION_INDEX.md
CHANGED
|
@@ -8,24 +8,19 @@ Decision Index adapter, `inference.engine:D3Engine`. The adapter calls
|
|
| 8 |
|
| 9 |
| Component | Revision |
|
| 10 |
|---|---|
|
| 11 |
-
| Downloadable model and DI adapter | `inclusionAI/SingVL_S1_4B`,
|
| 12 |
| Originally evaluated checkpoint | `93f15cd61c1cf417d9cb2631f6be2df13510829e` |
|
| 13 |
| Original results and code snapshot | `echoxvf/SingVL_S1_4B-DI-results`, dataset revision `90ec7e159da6fa21d762f1f75876ea79049d0f4a` |
|
| 14 |
| Decision Index kit | `f5a6e4fd85fed05e77878dfc4966d0568bfb45ec` |
|
| 15 |
|
| 16 |
-
The
|
| 17 |
-
updates on `main` use the same inference code and weights.
|
| 18 |
-
Its weights, configuration, tokenizer, processor and `inference/model.py` are
|
| 19 |
-
unchanged from the originally evaluated checkpoint. Its `engine.py` is copied
|
| 20 |
-
byte-for-byte from the pinned results repository. The original results repository
|
| 21 |
-
is retained as the submission snapshot; downloading it is optional for new runs.
|
| 22 |
-
See `release.json` for the weight hashes and source revisions.
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
## Download and install
|
| 31 |
|
|
@@ -35,7 +30,7 @@ The Hub CLI downloads the code and the weights from the same pinned model releas
|
|
| 35 |
```bash
|
| 36 |
python -m pip install "huggingface_hub>=0.34,<2"
|
| 37 |
hf download inclusionAI/SingVL_S1_4B \
|
| 38 |
-
--revision
|
| 39 |
python -m pip install -r ./singvl-s1-4b/inference/requirements-di.txt
|
| 40 |
```
|
| 41 |
|
|
@@ -108,9 +103,7 @@ python -m decision_index vision pipeline --dir /path/to/vision --workers 1 \
|
|
| 108 |
--out /path/to/new-vision-run
|
| 109 |
```
|
| 110 |
|
| 111 |
-
The
|
| 112 |
-
full attention, causal GDN, one full forward pass per question, last-valid-input
|
| 113 |
-
readout, and disabled KV caching. Limits are 256 options, four images, 65,536
|
| 114 |
text input tokens or 10,000 tokens with images, and 1,638,400 pixels per image.
|
| 115 |
Inputs exceeding capacity raise `Unsupported`; they are not truncated.
|
| 116 |
|
|
|
|
| 8 |
|
| 9 |
| Component | Revision |
|
| 10 |
|---|---|
|
| 11 |
+
| Downloadable model and DI adapter | `inclusionAI/SingVL_S1_4B`, revision `main` |
|
| 12 |
| Originally evaluated checkpoint | `93f15cd61c1cf417d9cb2631f6be2df13510829e` |
|
| 13 |
| Original results and code snapshot | `echoxvf/SingVL_S1_4B-DI-results`, dataset revision `90ec7e159da6fa21d762f1f75876ea79049d0f4a` |
|
| 14 |
| Decision Index kit | `f5a6e4fd85fed05e77878dfc4966d0568bfb45ec` |
|
| 15 |
|
| 16 |
+
Use `inference.engine:D3Engine` with its default settings for both public and private evaluations. The model weights, configuration, tokenizer and processor match the original checkpoint. The new native predictor batches text questions within each request. `release.json` records the weight and code hashes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
| Complete public suite | Requests (all successful) | Batch engine | Original serial engine |
|
| 19 |
+
|---|---:|---:|---:|
|
| 20 |
+
| Text | 140,178 | 69.75 | 69.76 |
|
| 21 |
+
| Vision | 12,210 | 73.74949871316771 | 73.74949871316771 |
|
| 22 |
+
|
| 23 |
+
Both runs used the same PPU2 system, public suites, scoring kit and maximum of 1,638,400 pixels per image. The [batch release predictions and scores](https://huggingface.co/datasets/echoxvf/SingVL_S1_4B-DI-results/tree/main/releases/batch-65k) correspond to the batch engine. The original results and prediction code remain accessible at the submission revision above. Private scores and official RTX PRO 6000 latency qualification are maintainer-run.
|
| 24 |
|
| 25 |
## Download and install
|
| 26 |
|
|
|
|
| 30 |
```bash
|
| 31 |
python -m pip install "huggingface_hub>=0.34,<2"
|
| 32 |
hf download inclusionAI/SingVL_S1_4B \
|
| 33 |
+
--revision main --local-dir ./singvl-s1-4b
|
| 34 |
python -m pip install -r ./singvl-s1-4b/inference/requirements-di.txt
|
| 35 |
```
|
| 36 |
|
|
|
|
| 103 |
--out /path/to/new-vision-run
|
| 104 |
```
|
| 105 |
|
| 106 |
+
The engine uses BF16, SDPA, prefix-bidirectional full attention, causal GDN, last-valid-input readout and disabled KV caching. For a text request with multiple questions, it sorts complete question prompts by length, then groups them so that the longest prompt length times the number of prompts in a batch is at most 65,536 tokens. Each question retains independent attention and a separate answer. Single-question and image requests follow the serial path. Limits are 256 options, four images, 65,536
|
|
|
|
|
|
|
| 107 |
text input tokens or 10,000 tokens with images, and 1,638,400 pixels per image.
|
| 108 |
Inputs exceeding capacity raise `Unsupported`; they are not truncated.
|
| 109 |
|
inference/README.md
CHANGED
|
@@ -9,7 +9,7 @@ tags:
|
|
| 9 |
|
| 10 |
# Sing VL S1
|
| 11 |
|
| 12 |
-
Sing VL S1 is a multimodal decision model built on Qwen3.5. It answers named questions over text or JSON and up to four images. Each question
|
| 13 |
|
| 14 |
- **Choice** selects an option and returns a probability for each candidate.
|
| 15 |
- **Noul** returns the probability that a yes/no proposition is true.
|
|
@@ -17,7 +17,9 @@ Sing VL S1 is a multimodal decision model built on Qwen3.5. It answers named que
|
|
| 17 |
|
| 18 |
## Public Decision Index 0.3
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
| :---: | ---: | ---: | ---: | ---: |
|
| 22 |
| Text | **69.76** | 60.70 | 67.8 | 60.1 |
|
| 23 |
| Vision | **73.75** | — | 67.90 |72.5 |
|
|
@@ -215,14 +217,11 @@ The response puts results under `answers` using the supplied question IDs. The t
|
|
| 215 |
|
| 216 |
## Decision Index compatibility and submission
|
| 217 |
|
| 218 |
-
|
| 219 |
-
`inference.engine:D3Engine`. Download the pinned `b6672ce4fd31aab79aee3f0729fd8738f87361cf` model release;
|
| 220 |
-
it includes both the model weights and the adapter. You do not need code from a
|
| 221 |
-
second repository to run new evaluations.
|
| 222 |
|
| 223 |
```bash
|
| 224 |
python -m pip install "huggingface_hub>=0.34,<2"
|
| 225 |
-
hf download inclusionAI/SingVL_S1_4B --revision
|
| 226 |
python -m pip install -r ./singvl-s1-4b/inference/requirements-di.txt
|
| 227 |
|
| 228 |
# With already-built and verified Public 0.3 suites:
|
|
@@ -239,10 +238,9 @@ adapter applies the submitted prefix-bidirectional attention and decision readou
|
|
| 239 |
See [the complete reproduction guide](DECISION_INDEX.md) for suite
|
| 240 |
preparation, direct DI commands, HTTP serving, capacity limits and exact revisions.
|
| 241 |
The [original public results and code snapshot](https://huggingface.co/datasets/echoxvf/SingVL_S1_4B-DI-results/tree/90ec7e159da6fa21d762f1f75876ea79049d0f4a)
|
| 242 |
-
|
| 243 |
-
|
| 244 |
[inference/release.json](release.json) for hashes and provenance.
|
| 245 |
|
| 246 |
-
The
|
| 247 |
-
at the 1,638,400-pixel image cap. Private Text/Vision evaluation and official
|
| 248 |
single-RTX-PRO-6000 latency qualification remain maintainer-run.
|
|
|
|
| 9 |
|
| 10 |
# Sing VL S1
|
| 11 |
|
| 12 |
+
Sing VL S1 is a multimodal decision model built on Qwen3.5. It answers named questions over text or JSON and up to four images. Each question is encoded as a complete prompt. In text requests with multiple questions, the engine batches those prompts by length with a budget of 65,536 padded tokens per forward pass.
|
| 13 |
|
| 14 |
- **Choice** selects an option and returns a probability for each candidate.
|
| 15 |
- **Noul** returns the probability that a yes/no proposition is true.
|
|
|
|
| 17 |
|
| 18 |
## Public Decision Index 0.3
|
| 19 |
|
| 20 |
+
The 65,536-token batch engine scored **69.75 Text** (140,178 requests) and **73.74949871316771 Vision** (12,210 requests) on the complete public suites. The table and per-dataset figures below document the original serial submission.
|
| 21 |
+
|
| 22 |
+
| Panel | Sing VL S1 (original submission) | TypeSafe Jev 1.14 | StartLux-Decision v1.1 4B |Perplexity Decider Flash v1.2 (4B) |
|
| 23 |
| :---: | ---: | ---: | ---: | ---: |
|
| 24 |
| Text | **69.76** | 60.70 | 67.8 | 60.1 |
|
| 25 |
| Vision | **73.75** | — | 67.90 |72.5 |
|
|
|
|
| 217 |
|
| 218 |
## Decision Index compatibility and submission
|
| 219 |
|
| 220 |
+
Both the Public and private suites use `inference.engine:D3Engine` with the same model weights and the same default request-level batching. Download the model and DI adapter together.
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
```bash
|
| 223 |
python -m pip install "huggingface_hub>=0.34,<2"
|
| 224 |
+
hf download inclusionAI/SingVL_S1_4B --revision main --local-dir ./singvl-s1-4b
|
| 225 |
python -m pip install -r ./singvl-s1-4b/inference/requirements-di.txt
|
| 226 |
|
| 227 |
# With already-built and verified Public 0.3 suites:
|
|
|
|
| 238 |
See [the complete reproduction guide](DECISION_INDEX.md) for suite
|
| 239 |
preparation, direct DI commands, HTTP serving, capacity limits and exact revisions.
|
| 240 |
The [original public results and code snapshot](https://huggingface.co/datasets/echoxvf/SingVL_S1_4B-DI-results/tree/90ec7e159da6fa21d762f1f75876ea79049d0f4a)
|
| 241 |
+
are pinned to `90ec7e159da6fa21d762f1f75876ea79049d0f4a`. For the batch release, see the
|
| 242 |
+
[Public predictions and scores](https://huggingface.co/datasets/echoxvf/SingVL_S1_4B-DI-results/tree/main/releases/batch-65k) and
|
| 243 |
[inference/release.json](release.json) for hashes and provenance.
|
| 244 |
|
| 245 |
+
The original serial submission scored Text **69.76** and Vision **73.7495**. Both releases use a 1,638,400-pixel image cap. Private Text/Vision evaluation and official
|
|
|
|
| 246 |
single-RTX-PRO-6000 latency qualification remain maintainer-run.
|
inference/SHA256SUMS
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
df73027077c2c961a7fb74f3248211a9ae009ff01e4f1f118cad7d8841db3d6c __init__.py
|
| 4 |
47c4e333c1220d903d1e91188f4aaea8b010f214b1594a868883281b0fdee2a9 benchmark.py
|
| 5 |
57dd22ca4cb9414e9820831bc455b6238525b28f5a52e25bb976d64f3984b237 engine.py
|
|
@@ -8,8 +8,8 @@ df73027077c2c961a7fb74f3248211a9ae009ff01e4f1f118cad7d8841db3d6c __init__.py
|
|
| 8 |
c7a98b7fc4e2247863c5270b50bed8dc9b78e78fc775d5f56e64958d014f4e03 examples/text.json
|
| 9 |
c6475acd2214ea4b47912fbe4c1acd86ae14ea0727dc8bc1c84c0b0665d899a6 examples/vision.json
|
| 10 |
66fe5318a083bc846c86cc275d285f927755a6c1ac14e625c99949a844f02f35 infer.py
|
| 11 |
-
|
| 12 |
-
|
| 13 |
3a1159102270f3bfddf230d78351edcd54a5480f9dab7b71848f23b7c5fcc742 requirements-di.txt
|
| 14 |
3e0b10110da340af605d5f956d896d0cb36bf10fd5c15cc7cbbf22cf42236f9a requirements.txt
|
| 15 |
b1ead84c60b16d69b893e71197f1bf8c4d4b9c3103ba2731b50202f18b135b4f run_decision_index.py
|
|
|
|
| 1 |
+
92a297d0288d554c17bbb28c63de26e0c4885fb66787dd1dd9a4fd49fd79822b DECISION_INDEX.md
|
| 2 |
+
5e898f5eb9d2a33e372b8a9e610c6a28e727e7e3cde8ecdc2d2a882b01c2c9d1 README.md
|
| 3 |
df73027077c2c961a7fb74f3248211a9ae009ff01e4f1f118cad7d8841db3d6c __init__.py
|
| 4 |
47c4e333c1220d903d1e91188f4aaea8b010f214b1594a868883281b0fdee2a9 benchmark.py
|
| 5 |
57dd22ca4cb9414e9820831bc455b6238525b28f5a52e25bb976d64f3984b237 engine.py
|
|
|
|
| 8 |
c7a98b7fc4e2247863c5270b50bed8dc9b78e78fc775d5f56e64958d014f4e03 examples/text.json
|
| 9 |
c6475acd2214ea4b47912fbe4c1acd86ae14ea0727dc8bc1c84c0b0665d899a6 examples/vision.json
|
| 10 |
66fe5318a083bc846c86cc275d285f927755a6c1ac14e625c99949a844f02f35 infer.py
|
| 11 |
+
b08a6287081282065b8b909a4f7baffe37a5d268d57f513f219220dd43c951b2 model.py
|
| 12 |
+
5a57eebf31cfc031160481e47a24170787d71a1b18864f6f654122e1e77784ee release.json
|
| 13 |
3a1159102270f3bfddf230d78351edcd54a5480f9dab7b71848f23b7c5fcc742 requirements-di.txt
|
| 14 |
3e0b10110da340af605d5f956d896d0cb36bf10fd5c15cc7cbbf22cf42236f9a requirements.txt
|
| 15 |
b1ead84c60b16d69b893e71197f1bf8c4d4b9c3103ba2731b50202f18b135b4f run_decision_index.py
|
inference/model.py
CHANGED
|
@@ -116,10 +116,20 @@ def resize_image(image, factor, min_pixels, max_pixels):
|
|
| 116 |
|
| 117 |
|
| 118 |
def bidirectional_prompt(_module, args, kwargs):
|
| 119 |
-
"""
|
| 120 |
attention = kwargs["attention_mask"]
|
| 121 |
-
if
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
or not attention.bool().all().item()):
|
| 124 |
raise ValueError("Sing VL S1 expects a single unpadded prompt without a cache")
|
| 125 |
kwargs["attention_mask"] = {"full_attention": None, "linear_attention": None}
|
|
@@ -127,7 +137,11 @@ def bidirectional_prompt(_module, args, kwargs):
|
|
| 127 |
|
| 128 |
|
| 129 |
class SingVLS1:
|
| 130 |
-
def __init__(self, model, device="cuda:0", image_max_pixels=PUBLIC_IMAGE_MAX_PIXELS):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
self.model_path = str(Path(model).resolve())
|
| 132 |
self.device = torch.device(device)
|
| 133 |
self.processor = AutoProcessor.from_pretrained(self.model_path, local_files_only=True)
|
|
@@ -188,8 +202,90 @@ class SingVLS1:
|
|
| 188 |
batch["mm_token_type_ids"] = (tokens == self.image_id).to(torch.int32)
|
| 189 |
return batch, ids
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
def predict(self, state, questions, images=()):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
if len(images) > 4:
|
| 194 |
raise Unsupported("at most four images per request")
|
| 195 |
requests = list(questions_for_state(state, questions, len(images)))
|
|
@@ -197,12 +293,11 @@ class SingVLS1:
|
|
| 197 |
image_grid = image_features["image_grid_thw"].tolist() if image_features else None
|
| 198 |
image_tokens = sum(math.prod(grid) // self.merge_size ** 2 for grid in image_grid or ())
|
| 199 |
answers, details = {}, {}
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
logits = output.logits[0, -1, self.choice_ids[:len(options)]].float()
|
| 206 |
if not torch.isfinite(logits).all():
|
| 207 |
raise ValueError("nonfinite candidate logits")
|
| 208 |
probabilities = dict(zip(options, logits.softmax(-1).tolist()))
|
|
@@ -230,6 +325,8 @@ class SingVLS1:
|
|
| 230 |
"candidate_logits": logits.tolist(),
|
| 231 |
}
|
| 232 |
usage = {"input_tokens": sum(item["input_tokens"] for item in details.values()), "output_tokens": 0}
|
|
|
|
|
|
|
| 233 |
return {"model": MODEL_ID, "answers": answers, "usage": usage}, details
|
| 234 |
|
| 235 |
def runtime(self):
|
|
|
|
| 116 |
|
| 117 |
|
| 118 |
def bidirectional_prompt(_module, args, kwargs):
|
| 119 |
+
"""Apply SingVL's noncausal full attention and causal GDN without a KV cache."""
|
| 120 |
attention = kwargs["attention_mask"]
|
| 121 |
+
if kwargs.get("use_cache") or kwargs.get("past_key_values") is not None:
|
| 122 |
+
raise ValueError("Sing VL S1 expects complete prompts without a cache")
|
| 123 |
+
if isinstance(attention, dict):
|
| 124 |
+
# The text batch path supplies the per-layer masks directly, with right padding.
|
| 125 |
+
if set(attention) != {"full_attention", "linear_attention"} or attention["linear_attention"] is not None:
|
| 126 |
+
raise ValueError("unexpected Sing VL S1 batch attention masks")
|
| 127 |
+
mask = attention["full_attention"]
|
| 128 |
+
ids = kwargs["input_ids"]
|
| 129 |
+
if mask is not None and (mask.dtype != torch.bool or mask.shape != (ids.size(0), 1, 1, ids.size(1))):
|
| 130 |
+
raise ValueError("full attention requires a per-row boolean key mask")
|
| 131 |
+
return args, kwargs
|
| 132 |
+
if (attention is None or attention.ndim != 2 or attention.shape[0] != 1
|
| 133 |
or not attention.bool().all().item()):
|
| 134 |
raise ValueError("Sing VL S1 expects a single unpadded prompt without a cache")
|
| 135 |
kwargs["attention_mask"] = {"full_attention": None, "linear_attention": None}
|
|
|
|
| 137 |
|
| 138 |
|
| 139 |
class SingVLS1:
|
| 140 |
+
def __init__(self, model, device="cuda:0", image_max_pixels=PUBLIC_IMAGE_MAX_PIXELS, batch_token_budget=65_536):
|
| 141 |
+
if batch_token_budget < 1:
|
| 142 |
+
raise ValueError("batch_token_budget must be positive")
|
| 143 |
+
self.batch_token_budget = int(batch_token_budget)
|
| 144 |
+
self.batch_oom_splits = 0
|
| 145 |
self.model_path = str(Path(model).resolve())
|
| 146 |
self.device = torch.device(device)
|
| 147 |
self.processor = AutoProcessor.from_pretrained(self.model_path, local_files_only=True)
|
|
|
|
| 202 |
batch["mm_token_type_ids"] = (tokens == self.image_id).to(torch.int32)
|
| 203 |
return batch, ids
|
| 204 |
|
| 205 |
+
def _last_logits(self, model_inputs):
|
| 206 |
+
self.model.model.rope_deltas = None
|
| 207 |
+
output = self.model(**model_inputs, use_cache=False, logits_to_keep=1)
|
| 208 |
+
return output.logits[:, -1]
|
| 209 |
+
|
| 210 |
+
def _score_serial(self, requests, image_features):
|
| 211 |
+
for key, kind, state, instructions, options in requests:
|
| 212 |
+
batch, ids = self.encode(render(state, instructions, options, self.labels), image_features)
|
| 213 |
+
model_inputs = {name: value.to(self.device) for name, value in batch.items()}
|
| 214 |
+
logits = self._last_logits(model_inputs)[0, self.choice_ids[:len(options)]].float()
|
| 215 |
+
yield key, kind, options, ids, logits
|
| 216 |
+
|
| 217 |
+
def _text_batches(self, rows):
|
| 218 |
+
current = []
|
| 219 |
+
for row in sorted(rows, key=lambda item: len(item[3])):
|
| 220 |
+
if current and len(row[3]) * (len(current) + 1) > self.batch_token_budget:
|
| 221 |
+
yield current
|
| 222 |
+
current = []
|
| 223 |
+
current.append(row)
|
| 224 |
+
if current:
|
| 225 |
+
yield current
|
| 226 |
+
|
| 227 |
+
def _score_text_batch(self, rows):
|
| 228 |
+
lengths = [len(row[3]) for row in rows]
|
| 229 |
+
width = max(lengths)
|
| 230 |
+
input_ids = torch.full((len(rows), width), self.tokenizer.pad_token_id, dtype=torch.long)
|
| 231 |
+
for i, row in enumerate(rows):
|
| 232 |
+
input_ids[i, :lengths[i]] = torch.tensor(row[3], dtype=torch.long)
|
| 233 |
+
input_ids = input_ids.to(self.device)
|
| 234 |
+
lengths_tensor = torch.tensor(lengths, device=self.device)
|
| 235 |
+
if len(rows) == 1:
|
| 236 |
+
logits = self._last_logits({"input_ids": input_ids, "attention_mask": torch.ones_like(input_ids)})
|
| 237 |
+
else:
|
| 238 |
+
# Right padding preserves each real token's original RoPE position and cannot
|
| 239 |
+
# influence any earlier token in the causal GDN. In full attention pad keys
|
| 240 |
+
# must be invisible to all queries in the same row.
|
| 241 |
+
key_mask = None
|
| 242 |
+
if lengths[0] != lengths[-1]:
|
| 243 |
+
valid = torch.arange(width, device=self.device)[None, :] < lengths_tensor[:, None]
|
| 244 |
+
key_mask = valid[:, None, None, :]
|
| 245 |
+
masks = {"full_attention": key_mask, "linear_attention": None}
|
| 246 |
+
backbone = self.model.model.language_model
|
| 247 |
+
hidden = backbone(input_ids=input_ids, attention_mask=masks, use_cache=False,
|
| 248 |
+
return_dict=True).last_hidden_state
|
| 249 |
+
row_indices = torch.arange(len(rows), device=self.device)
|
| 250 |
+
logits = self.model.lm_head(hidden[row_indices, lengths_tensor - 1, :])
|
| 251 |
+
most_options = max(len(row[2]) for row in rows)
|
| 252 |
+
return logits[:, self.choice_ids[:most_options]].float()
|
| 253 |
+
|
| 254 |
+
def _score_batched_text(self, requests):
|
| 255 |
+
rows = []
|
| 256 |
+
for key, kind, state, instructions, options in requests:
|
| 257 |
+
_, ids = self.encode(render(state, instructions, options, self.labels), {})
|
| 258 |
+
rows.append((key, kind, options, ids))
|
| 259 |
+
for batch in self._text_batches(rows):
|
| 260 |
+
yield from self._score_with_oom_retry(batch)
|
| 261 |
+
|
| 262 |
+
def _score_with_oom_retry(self, rows):
|
| 263 |
+
try:
|
| 264 |
+
logits = self._score_text_batch(rows)
|
| 265 |
+
except torch.cuda.OutOfMemoryError:
|
| 266 |
+
if self.device.type != "cuda" or len(rows) == 1:
|
| 267 |
+
raise
|
| 268 |
+
else:
|
| 269 |
+
for i, (key, kind, options, ids) in enumerate(rows):
|
| 270 |
+
yield key, kind, options, ids, logits[i, :len(options)]
|
| 271 |
+
return
|
| 272 |
+
# The failed forward's traceback (and its CUDA tensors) has left scope here.
|
| 273 |
+
self.batch_oom_splits += 1
|
| 274 |
+
with torch.cuda.device(self.device):
|
| 275 |
+
torch.cuda.empty_cache()
|
| 276 |
+
mid = len(rows) // 2
|
| 277 |
+
yield from self._score_with_oom_retry(rows[:mid])
|
| 278 |
+
yield from self._score_with_oom_retry(rows[mid:])
|
| 279 |
+
|
| 280 |
def predict(self, state, questions, images=()):
|
| 281 |
+
return self._predict(state, questions, images, batch_text=True)
|
| 282 |
+
|
| 283 |
+
def predict_serial(self, state, questions, images=()):
|
| 284 |
+
"""Run the release's one-prompt-at-a-time path for comparison."""
|
| 285 |
+
return self._predict(state, questions, images, batch_text=False)
|
| 286 |
+
|
| 287 |
+
@torch.inference_mode()
|
| 288 |
+
def _predict(self, state, questions, images, batch_text):
|
| 289 |
if len(images) > 4:
|
| 290 |
raise Unsupported("at most four images per request")
|
| 291 |
requests = list(questions_for_state(state, questions, len(images)))
|
|
|
|
| 293 |
image_grid = image_features["image_grid_thw"].tolist() if image_features else None
|
| 294 |
image_tokens = sum(math.prod(grid) // self.merge_size ** 2 for grid in image_grid or ())
|
| 295 |
answers, details = {}, {}
|
| 296 |
+
if batch_text and not image_features and len(requests) > 1:
|
| 297 |
+
scored = self._score_batched_text(requests)
|
| 298 |
+
else:
|
| 299 |
+
scored = self._score_serial(requests, image_features)
|
| 300 |
+
for question_id, kind, options, ids, logits in scored:
|
|
|
|
| 301 |
if not torch.isfinite(logits).all():
|
| 302 |
raise ValueError("nonfinite candidate logits")
|
| 303 |
probabilities = dict(zip(options, logits.softmax(-1).tolist()))
|
|
|
|
| 325 |
"candidate_logits": logits.tolist(),
|
| 326 |
}
|
| 327 |
usage = {"input_tokens": sum(item["input_tokens"] for item in details.values()), "output_tokens": 0}
|
| 328 |
+
answers = {key: answers[key] for key in questions}
|
| 329 |
+
details = {key: details[key] for key in questions}
|
| 330 |
return {"model": MODEL_ID, "answers": answers, "usage": usage}, details
|
| 331 |
|
| 332 |
def runtime(self):
|
inference/release.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"download_revision": "
|
| 3 |
"model_repo": "inclusionAI/SingVL_S1_4B",
|
| 4 |
"evaluated_weights_revision": "93f15cd61c1cf417d9cb2631f6be2df13510829e",
|
| 5 |
"results_repo": "echoxvf/SingVL_S1_4B-DI-results",
|
|
@@ -11,7 +11,15 @@
|
|
| 11 |
"model-00001-of-00002.safetensors": "167ea2740250a44a210d3bdec1c36123c7b518d12fe69e423f913807afdd03a7",
|
| 12 |
"model-00002-of-00002.safetensors": "d348920079085286938444faebe746e5cd4433c07cb192d28f87825c6c403db9"
|
| 13 |
},
|
| 14 |
-
"model_py_sha256": "
|
| 15 |
"engine_py_sha256": "57dd22ca4cb9414e9820831bc455b6238525b28f5a52e25bb976d64f3984b237",
|
| 16 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"download_revision": "main",
|
| 3 |
"model_repo": "inclusionAI/SingVL_S1_4B",
|
| 4 |
"evaluated_weights_revision": "93f15cd61c1cf417d9cb2631f6be2df13510829e",
|
| 5 |
"results_repo": "echoxvf/SingVL_S1_4B-DI-results",
|
|
|
|
| 11 |
"model-00001-of-00002.safetensors": "167ea2740250a44a210d3bdec1c36123c7b518d12fe69e423f913807afdd03a7",
|
| 12 |
"model-00002-of-00002.safetensors": "d348920079085286938444faebe746e5cd4433c07cb192d28f87825c6c403db9"
|
| 13 |
},
|
| 14 |
+
"model_py_sha256": "b08a6287081282065b8b909a4f7baffe37a5d268d57f513f219220dd43c951b2",
|
| 15 |
"engine_py_sha256": "57dd22ca4cb9414e9820831bc455b6238525b28f5a52e25bb976d64f3984b237",
|
| 16 |
+
"weights_unchanged": true,
|
| 17 |
+
"batch_token_budget": 65536,
|
| 18 |
+
"original_serial_model_revision": "b6672ce4fd31aab79aee3f0729fd8738f87361cf",
|
| 19 |
+
"batch_results_path": "releases/batch-65k",
|
| 20 |
+
"batch_results_revision": "main",
|
| 21 |
+
"batch_public_scores": {
|
| 22 |
+
"text": 69.75,
|
| 23 |
+
"vision": 73.74949871316771
|
| 24 |
+
}
|
| 25 |
}
|