Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
README: a short, beginner-friendly front page (details in docs/DETAILS.md); pictures in WebP/TIFF/AVIF
Niko1221e5509707730d
diff --git a/README.md b/README.mdindex df2ba573b..6ec2f0ba0 100644--- a/README.md+++ b/README.md@@ -1,332 +1,140 @@-<h1 align="center">Qwen3.8-Flash-Next (125B MoE) on a 12-24 GB NVIDIA GPU + 64 GB RAM: one-click install for Windows / Linux</h1>+<h1 align="center">Strata</h1>-<p align="center"><b>Strata</b>: an inference engine built for exactly one model and exactly this kind of PC</p>+<p align="center"><b>Run a 125-billion-parameter AI model on a normal gaming PC</b><br>+one NVIDIA card (12-24 GB) + 64 GB of RAM · Windows or Linux · one click to install</p>-A 125-billion-parameter mixture-of-experts model (6B active per token) on a **normal gaming PC**: one NVIDIA card with-12-24 GB of VRAM, 64 GB of RAM and a desktop CPU. Strata keeps the always-used part of the model on the GPU, all 24,576-experts in RAM, computes the experts the GPU does not hold on the CPU at the same time, and checks several tokens per-pass with the model's own multi-token-prediction (MTP) layer. The text it produces is identical to plain greedy decoding.+Strata runs **[Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next)** - a large, smart AI model that+normally needs a server - on your own PC. It writes its answers at **60-95 tokens per second** (a token is about ¾+of a word): faster than you can read.-It serves an **OpenAI-** and **Anthropic-compatible API on localhost**, so any chat app, coding agent or script that-talks to those APIs can use it. Optionally it also **reads images** (screenshots, photos, scanned pages) with the-model's own vision encoder.+- **Private:** everything runs on your PC. Nothing is sent anywhere.+- **Works with your apps:** chat apps, coding agents and scripts that speak the OpenAI or Anthropic API just work.+- **Sees pictures** too, if you want (screenshots, photos, scanned pages).+- **Free and open source.**-> **Jump to:** [Speed](#speed-measured) · [Other GPUs](#other-gpus-estimated) · [Which model?](#which-model) ·-> [Windows](#windows) · [Linux](#linux) · [Using it](#using-it) · [Images](#images-vision) ·-> [Troubleshooting](#troubleshooting) · [How it works](#how-it-works)+> **Jump to:** [Is my PC enough?](#is-my-pc-enough) · [Install](#install-3-steps) · [How fast?](#how-fast-is-it) ·+> [Which model?](#which-model-should-i-pick) · [Using it](#using-it) · [Problems?](#something-went-wrong) ·+> [How it works](#how-does-it-work) · [All the details](docs/DETAILS.md)----## Speed (measured)+## Is my PC enough?-RTX 5070 **12 GB**, Ryzen 5 7600 (6 cores), 64 GB DDR5-5200, Windows. One code-agent prompt per length, 256 generated-tokens, MTP speculative decoding on. "262K" is the model's full context window (a 259,943-token prompt).--### Prompt processing (tokens/s)--| Model | 1K | 4K | 32K | 64K | 128K | 262K |-| --- | ---: | ---: | ---: | ---: | ---: | ---: |-| **Q2_0** | 389 | 539 | 571 | 561 | 543 | 496 |-| **IQ2_XS** | 332 | 463 | 495 | 486 | 472 | 437 |-| **IQ3_XXS** | 285 | 410 | 435 | 427 | 414 | - |--### Output (tokens/s)--| Model | 1K | 4K | 32K | 64K | 128K | 262K |-| --- | ---: | ---: | ---: | ---: | ---: | ---: |-| **Q2_0** | 88.7 | 94.6 | 87.5 | 76.4 | 65.1 | 56.3 |-| **IQ2_XS** | 82.0 | 78.0 | 65.3 | 63.7 | 52.0 | 48.0 |-| **IQ3_XXS** | 64.6 | 65.6 | 57.3 | 54.4 | 44.8 | - |--IQ3_XXS at 262K is not measured: with its 43 GB of experts, a 260K-token context brings a 64 GB PC to its memory-limit. Use up to 128K with IQ3_XXS on 64 GB.--Time to first token is prompt length / prompt speed: about 7 s at 4K, 55 s at 32K, 4 minutes at 128K and 9 minutes at-262K. The raw numbers: `bench/results/`. The [paper](docs/paper/Strata-Paper.pdf) explains every number.--## Other GPUs (estimated)--Not measured - estimated from the runs above (same CPU and 64 GB RAM): the GPU part scaled by memory bandwidth, the CPU-part by how many more experts the card's VRAM holds. Treat as **±20%**. Numbers are *prompt / output* tokens/s.--| GPU | Model | 1K | 4K | 32K | 64K | 128K | 262K |-| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |-| RTX 5060 Ti 16GB | Q2_0 | ~341 / ~80 | ~472 / ~87 | ~501 / ~81 | ~492 / ~72 | ~476 / ~62 | ~435 / ~53 |-| | IQ2_XS | ~291 / ~80 | ~406 / ~77 | ~434 / ~63 | ~426 / ~62 | ~413 / ~51 | ~383 / ~47 |-| | IQ3_XXS | ~249 / ~66 | ~359 / ~65 | ~381 / ~56 | ~374 / ~54 | ~363 / ~45 | - |-| RTX 3090 24GB | Q2_0 | ~355 / ~128 | ~491 / ~140 | ~521 / ~130 | ~512 / ~115 | ~495 / ~100 | ~453 / ~85 |-| | IQ2_XS | ~303 / ~131 | ~422 / ~128 | ~451 / ~103 | ~444 / ~102 | ~430 / ~85 | ~398 / ~78 |-| | IQ3_XXS | ~260 / ~106 | ~374 / ~103 | ~396 / ~89 | ~390 / ~85 | ~378 / ~71 | - |--More VRAM matters more than a faster GPU: every extra GB holds ~700 more experts, and every expert on the GPU is one the-CPU does not have to compute. A 3090's 24 GB takes most of the CPU work away.--## Which model?--All three are [ISTA-DASLab's GSQ-RCO quantizations](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF)-of [Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next).--| Model | Download | RAM it uses | Speed | Quality |-| --- | ---: | ---: | --- | --- |-| **Q2_0** | 66 GB | ~34 GB experts + ~6 GB | fastest | good |-| **IQ2_XS** | 68 GB | ~36 GB experts + ~6 GB | close to Q2_0 | a bit better |-| **IQ3_XXS** | 76 GB | ~43 GB experts + ~6 GB | slower (more CPU work) | best |--With 64 GB of RAM all three fit (close the browser for IQ3_XXS, and keep its context at 128K or less). With 48 GB only Q2_0 / IQ2_XS may fit. 32 GB is not enough.--### Or: Swift 1.5 (a fine-tune that thinks shorter)--The setup's first question also offers **[Swift 1.5](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)**,-UkisAI's fine-tune of Qwen3.8-Flash-Next, trained to reach the answer with much less thinking (its authors: 63% fewer-thinking tokens, 1.8x sooner answers, under 1% accuracy loss). Same architecture, the same three sizes, its own-vision encoder; Strata runs it at the same speed (4K, IQ2_XS: 465 prompt / 78.7 output tokens/s, vs 467 / 78.3 for-the original). Its authors recommend **IQ2_XS** (their Q2_0 is marked experimental). Its license is the Swift Open-License 1.0 - read it on the model page.--Our small check (8 reasoning questions, default thinking, IQ2_XS): both models got **8/8**; Swift used **1,234**-output tokens in 28 s, the original **2,682** in 46 s - most of the difference from one question the original-thought about for 1,524 tokens. Not a benchmark, but consistent with the claim.--```-START-HERE.bat --setup --family swift --model IQ2_XS-```--## Before you start--You need **only an NVIDIA driver** (version 580 or newer; update it with the NVIDIA App or from-[nvidia.com/drivers](https://www.nvidia.com/drivers)). Everything else is installed for you the first time.--| | |+| You need | || --- | --- |-| GPU | NVIDIA **RTX 30, 40 or 50 series**, **12 GB VRAM or more** (8 GB runs, slowly). Measured on an RTX 5070; RTX 30/40 are untested. |-| RAM | **64 GB** recommended (see the table above). |-| CPU | x86-64 with AVX2 (any Intel/AMD desktop CPU from the last ~8 years). AVX-512 (Ryzen 7000/9000) is a bit faster. |-| Disk | ~70-80 GB free for the model, ~6 GB for the MTP layer (+1 GB with images). **Q2_0 on an AVX-512 CPU** also writes a one-time ~40 GB copy of its experts for the fast CPU kernel. An NVMe SSD is strongly recommended. |-| OS | Windows 10/11, or Linux (Ubuntu 22.04/24.04 get everything installed automatically). |--What the first start installs, all inside this folder (`.venv/`, `engine/`, `third_party/`, `models/`, `packs/`, `mtp/`):-Python 3.12 if you have none (for your user account, no admin), a private Python environment, NVIDIA's CUDA libraries-(from pip, ~0.4 GB), the ready-made Strata engine for RTX 30/40/50, the model and the MTP draft layer. If no-ready-made engine fits your PC, it offers to install the build tools (Visual Studio Build Tools + CUDA Toolkit on-Windows, `build-essential` + CUDA on Ubuntu) and compiles the engine for your GPU (asks first; 20-40 minutes once).-------## Windows--### Double-click `START-HERE.bat`+| **Graphics card** | NVIDIA RTX 30, 40 or 50 series with **12 GB of VRAM or more** |+| **Memory (RAM)** | **64 GB** |+| **Free disk space** | ~80 GB (an SSD makes the first start much faster) |+| **System** | Windows 10/11, or Linux |-**The first time** it asks four questions and does the rest:+That's it. The only thing you install yourself is a current **NVIDIA driver**+([nvidia.com/drivers](https://www.nvidia.com/drivers) or the NVIDIA App). Everything else - Python, the engine, the+model - is set up for you.-1. **Which model?** Qwen3.8-Flash-Next (the original) or Swift 1.5 (the fine-tune that thinks shorter).-2. **Which size?** Q2_0, IQ2_XS or IQ3_XXS (it recommends one for your RAM).-3. **How much context?** 8K to 256K tokens (it recommends one for your VRAM).-4. **Images?** yes / no (see [Images](#images-vision)).+## Install (3 steps)-Then it downloads and prepares everything (the model is 66-76 GB, so the first start takes a while; an interrupted-download continues where it stopped) and **starts the model**: your browser opens `http://127.0.0.1:8080`, a small-page that shows it is running and lets you chat. The API is at `http://127.0.0.1:8080/v1` for your apps.+**Windows**-**Every time after that**, `START-HERE.bat` just starts the model (30-90 s to load 34-43 GB into RAM). Nothing is-downloaded again. Closing the window stops the model.+1. [Download this project](https://github.com/Niko1221/Strata/archive/refs/heads/main.zip) and unzip it (or `git clone` it).+2. Double-click **`START-HERE.bat`**.+3. Answer 4 questions - or just press Enter each time for the recommended choice:+ - **Which model?** The original, or Swift 1.5 (a version that thinks shorter and answers sooner)+ - **Which size?** Q2_0, IQ2_XS or IQ3_XXS - see [which model](#which-model-should-i-pick)+ - **How much context?** How much text it can keep in mind at once (it suggests one for your card)+ - **Images?** Whether it should also read pictures-```-START-HERE.bat --setup install another model, or change context / images-START-HERE.bat --model IQ2_XS --context 32768 --vision yes --yes no questions-START-HERE.bat --gguf-dir D:\models\IQ2_XS use GGUF files you already have-START-HERE.bat --port 8081 another port-```+Then it downloads everything (the model is ~70 GB, so the first time takes a while - you can stop and it picks up+where it left off) and **starts the model**. Your browser opens a chat page at `http://127.0.0.1:8080`.-With more than one model installed, it asks which one to start. `run-<model>.bat` starts a model directly.+**Next time**, just double-click `START-HERE.bat` again: it starts right away, nothing is downloaded twice. Close its+window to stop the model.-### Chat in the terminal (optional)+**Linux:** run `./setup.sh` - same questions, same result.-```-.venv\Scripts\python chat.py-```+## How fast is it?------## Linux--```bash-./setup.sh-```--The same questions, the same automatic install (it uses `sudo apt` for Python and, only if it has to compile,-for the build tools), and the same start: `http://127.0.0.1:8080`. Later runs of `./setup.sh` (or `./run-<model>.sh`)-start the model directly. Options as on Windows (`./setup.sh --setup`, `--model Q2_0 --yes`, `--gguf-dir /data/Q2_0`).-Terminal chat: `.venv/bin/python chat.py`.-------## Using it--The server listens on `http://127.0.0.1:8080` (change with `--port` in setup, or edit the run script).--| API | Endpoint |-| --- | --- |-| OpenAI Chat Completions (stream and non-stream, tools) | `POST /v1/chat/completions` |-| Anthropic Messages (stream and non-stream, tools) | `POST /v1/messages` |-| Model list / health | `GET /v1/models`, `GET /health` |--```bash-curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{- "model": "strata", "messages": [{"role": "user", "content": "Write a haiku about GPUs."}], "max_tokens": 512 }'-```--```python-from openai import OpenAI-client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="none")-r = client.chat.completions.create(model="strata", messages=[{"role": "user", "content": "Hello!"}])-print(r.choices[0].message.content)-```--- **Thinking levels: none, low, medium, high.** The model thinks before it answers (streamed as- `reasoning_content`, Anthropic: `thinking` blocks). Choose how much per request - in the chat page (the "Thinking"- menu), in `chat.py` (`/think low`), or over the API:-- | API | how |- | --- | --- |- | OpenAI | `"reasoning_effort": "none" \| "low" \| "medium" \| "high"` (also `"reasoning": {"effort": ...}`, or `"chat_template_kwargs": {"enable_thinking": false}`) |- | Anthropic | `"output_config": {"effort": "low" \| "medium" \| "high"}`, `"thinking": {"type": "disabled"}`, or `"thinking": {"type": "enabled", "budget_tokens": N}` (under 2K = low, under 8K = medium, more = high) |-- Without a setting the model uses its own default, **high**. `none` answers at once (fastest); `low` keeps the thinking- short. The levels are instructions the model was trained with, not a hard token limit: on easy questions all three- think briefly, on hard ones `high` thinks longest and is most accurate.-- **Chat apps.** Any app with an "OpenAI-compatible" provider works: base URL `http://127.0.0.1:8080/v1`, any API key.-- **Context.** Chosen in setup (8K-262K). Requests longer than that are refused, never silently cut.-- **From other devices / the internet.** The server listens on your PC only (`127.0.0.1`). To reach it from elsewhere,- put a tunnel in front of it, for example [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/):- `cloudflared tunnel --url http://127.0.0.1:8080`. **Set a key first**, or anyone with the link can use your PC:- add `"api_key": "some-long-secret"` to `strata-<model>.json` (or set the `STRATA_API_KEY` environment variable);- clients then send it as their API key.--**Current limits (v1):** one request at a time; greedy decoding (temperature is ignored); every request processes its-whole prompt again (no conversation cache yet, so long chats have a long time-to-first-token); images only when set up-with them (below); no video.-----+Measured on an RTX 5070 (12 GB), a Ryzen 5 7600 and 64 GB of RAM:-## Images (vision)+| Size | Writes answers (short chat) | Writes answers (128K context) | Reads your prompt |+| --- | ---: | ---: | ---: |+| **Q2_0** | 95 tokens/s | 65 tokens/s | 539 tokens/s |+| **IQ2_XS** | 78 tokens/s | 52 tokens/s | 463 tokens/s |+| **IQ3_XXS** | 66 tokens/s | 45 tokens/s | 410 tokens/s |-The model has a vision encoder: [`mmproj-Qwen3.8-Flash-Next-BF16.gguf`](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF)-(0.9 GB, a 27-layer ViT plus the projector into the language model). It is **optional**: say yes when the setup asks-"Images?", or run it again with `--vision gpu` (or `--vision cpu`). The setup downloads the encoder, builds a small-helper (`strata-vision`, from llama.cpp's `mtmd` library) and adds it to your start script. Nothing else changes.+- **Writes answers** = how fast the reply appears (tokens per second).+- **Reads your prompt** = how fast it takes in what you send (long documents, code, chat history).-| Encoder on | Time per picture | Cost |-| --- | --- | --- |-| **GPU** (recommended) | **0.1-0.5 s** (up to 1,024 image tokens) | ~1.4 GB of VRAM is kept free for it, so the expert cache is smaller: text output is a few % slower (table below) |-| CPU | 10-30 s (pictures are scaled down to ~300 image tokens) | nothing on the GPU |+A card with more VRAM is faster, because more of the model fits on the GPU: an RTX 3090 (24 GB) should do roughly+100-140 tokens per second. All measurements, long-context numbers and estimates for other cards are in the+[details](docs/DETAILS.md#speed-measured).-A picture becomes up to 1,024 tokens of the context (a 640x480 photo: 300). The same picture sent again, as chat apps-do on every turn, is encoded only once.+## Which model should I pick?-### Sending a picture+**The size** (the same model, compressed more or less):-**Terminal chat:** type `/image <path to a picture>`, press Enter, then type your question.+| Size | Download | Speed | Quality | Pick it if... |+| --- | ---: | --- | --- | --- |+| **Q2_0** | 66 GB | fastest | good | you want speed |+| **IQ2_XS** | 68 GB | fast | better | you want a good all-rounder (**recommended**) |+| **IQ3_XXS** | 76 GB | slower | best | you want the best answers (uses 43 GB of your 64 GB RAM) |-```-you> /image C:\Users\me\Pictures\receipt.jpg-(picture attached: receipt.jpg - now type your question)-you> What is the total on this receipt?-```+**The version:**-**OpenAI API** (an `image_url` part: a `data:` URL, an `http(s)://` URL or a local file path):+- **Qwen3.8-Flash-Next** - the original.+- **[Swift 1.5](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)** - a fine-tune by UkisAI+ that thinks much shorter before answering, so you get the answer sooner, with about the same quality. Same speed per+ token. Its own license applies (see its page).-```python-import base64-from openai import OpenAI-client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="none")-img = base64.b64encode(open("photo.jpg", "rb").read()).decode()-r = client.chat.completions.create(model="strata", messages=[{"role": "user", "content": [- {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{img}"}},- {"type": "text", "text": "What is in this picture?"}]}])-print(r.choices[0].message.content)-```+Not sure? Take **IQ2_XS**. You can add another one later with `START-HERE.bat --setup`.-**Anthropic API:** an `image` block with a `base64` (or `url`) source, as usual.--JPEG, PNG, BMP and GIF work (WebP does not). Chat apps with image upload work the same way.--### Speed with images on (4K context, measured)--| Model | Prompt tok/s, images off | Prompt tok/s, images on | Output tok/s, images off | Output tok/s, images on |-| --- | ---: | ---: | ---: | ---: |-| **Q2_0** | 541 | 531 | 90.7 | 86.9 |-| **IQ2_XS** | 468 | 458 | 77.1 | 74.0 |-| **IQ3_XXS** | 411 | 401 | 64.7 | 59.5 |--"Off" is the published setup; "on" runs with the encoder loaded on the GPU and its VRAM kept free, so ~1,000 fewer-experts fit in VRAM and the CPU computes a few more per token: 2-8% slower. For text, turning images on changes-nothing else (the output is bit-identical when the VRAM is the same).--A question about a picture (a 640x480 newspaper page = 300 image tokens, a 328-token prompt; the whole request, encoder-on the GPU, measured through the API):--| Model | Answer ("MEN WALK ON MOON") | Picture encoded | Prompt | Output |-| --- | ---: | ---: | ---: | ---: |-| **Q2_0** | 1.9 s | ~0.1 s | 207 tok/s | 65-73 tok/s |-| **IQ2_XS** | 2.3 s | ~0.1 s | 173 tok/s | 50-60 tok/s |-| **IQ3_XXS** | 2.7 s | ~0.1 s | 144 tok/s | 41-50 tok/s |--(Short prompts run below the 4K prompt speed: a 2,048-token chunk is where the prompt path is efficient. Short answers-run below the long-output speed: the first rounds have no draft yet.)+## Using it-**How it works inside:** the encoder turns the picture into rows of the same width as the model's word embeddings;-Strata puts them where the prompt has `<|image_pad|>` tokens and gives each one its 2-D position (row and column in the-picture; the model uses interleaved M-RoPE). Answers match llama.cpp's multimodal implementation token for token on our-test images.+- **Chat in the browser:** `http://127.0.0.1:8080` - a simple chat page (it opens by itself when the model starts).+- **Chat in the terminal:** `.venv\Scripts\python chat.py`+- **Your apps and coding agents:** add it as an "OpenAI-compatible" provider with base URL+ **`http://127.0.0.1:8080/v1`**, any API key and any model name. Apps that use Anthropic's API: `http://127.0.0.1:8080/v1/messages`.+- **Thinking:** the model thinks before it answers. Choose **off, low, medium or high** - in the chat page menu, with+ `/think low` in `chat.py`, or with your app's "reasoning effort" setting. Off is fastest; high is best for hard questions.+- **Pictures:** in the chat page click **Picture**; in `chat.py` type `/image <path>`; in apps just attach them.+- **From your phone or another PC:** see the [details](docs/DETAILS.md#using-it) (set an API key first).----+**Good to know:** it answers one request at a time, and it re-reads the whole conversation for every answer. So in+very long chats you wait longer before it starts writing: about 1 minute per 30,000 tokens of conversation.-## Troubleshooting+## Something went wrong?-| Symptom | What to do |+| What you see | What to do || --- | --- |-| `the NVIDIA driver is too old` | Update the driver (NVIDIA App or nvidia.com/drivers), restart, run `START-HERE.bat` again. |-| Python or the build tools could not be installed | Install what it names (links are printed), then run it again. Everything already done is kept. |-| `port 8080 is already in use` | Strata is already running (look for its window), or another program uses the port: `START-HERE.bat --port 8081`. |-| `cudaHostRegister ... out of memory` in the log | Normal on Windows: the engine pins the experts in per-layer slices instead. Only a problem if the load then fails. |-| The first start takes minutes | It is reading 34-43 GB into RAM; the second start is faster while the files are in the OS cache. |-| Slow output, disk light busy | Not enough free RAM: close other programs, or choose Q2_0 / IQ2_XS. |-| `prompt ... exceeds the context` | The request is longer than the context you chose: run setup again with a bigger `--context`. |-| Slower than the tables | The monitor plugged into the GPU and other GPU programs take VRAM from the expert cache; RAM running below its rated speed (enable EXPO/XMP in the BIOS) slows the CPU half. |-| `this server was started without the vision encoder` | The model was set up for text only: run setup again with `--vision gpu`. |-| A picture is refused or `cannot read the image` | Use JPEG, PNG, BMP or GIF (not WebP). |-| Pictures are slow (10-30 s) | The encoder runs on the CPU: run setup again with `--vision gpu` (needs ~1.4 GB of VRAM). |-| Anything else | The engine log is `strata-<model>.log` in this folder. |+| `the NVIDIA driver is too old` | Update the driver (NVIDIA App or nvidia.com/drivers), restart the PC, run `START-HERE.bat` again. |+| It stopped during download or setup | Run `START-HERE.bat` again - it continues where it stopped. |+| `port 8080 is already in use` | Strata is already running - look for its window. |+| The first start takes minutes | Normal: it loads 35-43 GB into RAM. The next start is faster. |+| Slow, and the disk light is busy | Not enough free RAM: close other programs (browsers use a lot), or pick Q2_0 / IQ2_XS. |+| "prompt exceeds the context" | The conversation is longer than the context you chose: run `START-HERE.bat --setup` and pick more. |----+More in the [full troubleshooting table](docs/DETAILS.md#troubleshooting). Still stuck? Open an issue and attach+`strata-<model>.log` from this folder.-## How it works+## How does it work?-<p align="center"><img src="docs/paper/tiers.svg" width="760" alt="memory tiers"></p>+A model this big doesn't fit on a gaming graphics card. Strata splits the work between the parts of your PC:-- **GPU (VRAM):** attention and DeltaNet mixers, the gated-residual weights, routers, shared experts, output head, the MTP- draft layer, the KV cache, and an **expert cache** that fills the rest of VRAM with the most-used experts (it adapts to- the conversation while you chat).-- **RAM:** all 24,576 experts, pinned. The CPU computes the experts that are not on the GPU **in place**, at the same time- as the GPU works on the cached ones (AVX-512 / AVX2 kernels, ggml's for the i-quants).-- **SSD:** the 28.8 GB n-gram table, read a few rows per token through the OS cache.-- **Speculation:** the model's own MTP layer drafts up to 3 tokens; one pass over all 48 layers checks them. 2.4-3.2- tokens per pass on average.-- **Prompts** are processed in 2,048-token chunks with the experts streamed to the GPU over PCIe.+<p align="center"><img src="docs/paper/tiers.svg" width="700" alt="how Strata splits the model between GPU, RAM and SSD"></p>-The full story, with measurements, bottlenecks and what comes next: **[docs/paper/Strata-Paper.pdf](docs/paper/Strata-Paper.pdf)**.+- **The GPU** runs the part of the model that is used for every word, plus the "experts" it needs most often.+- **The RAM** holds all 24,576 experts, and **the CPU** computes the few the GPU doesn't have - at the same time as the GPU.+- **The SSD** holds a big lookup table; the model reads a few rows of it per word.+- **A small helper inside the model guesses the next words**, and Strata checks several guesses at once. That makes+ it 1.6-1.8x faster than going word by word - and the answer is exactly the same.----+The full story is in the [paper](docs/paper/Strata-Paper.pdf) and the [details](docs/DETAILS.md).++## Credits-## Credits and licenses--- Model: [Qwen/Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next) by the Qwen team; quantizations:- [ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF).- Swift 1.5: [ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)- by UkisAI. Their licenses apply to the weights.-- [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp) (MIT): the i-quant formats, the GPU dot products and- dequantizers transcribed in `src/kernels/cuda/iq_kernels.cu`, the CPU backend linked for the i-quant experts, the- `mtmd` library behind the image encoder (`tools/vision/`), and `gguf-py` used by the tools. See- `third_party/ggml/LICENSE`.-- Ideas from [Splash](https://github.com/incoai/splash), [ninfer](https://github.com/Neroued/ninfer) and- [HyperQwen](https://github.com/syv-ai/HyperQwen); references in the paper.+- Model: [Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next) by the Qwen team; compressed versions by+ [ISTA-DASLab](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF);+ [Swift 1.5](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF) by UkisAI. Their licenses apply+ to the model files.+- Built with parts of [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp) (MIT). Ideas from+ [Splash](https://github.com/incoai/splash), [ninfer](https://github.com/Neroued/ninfer) and+ [HyperQwen](https://github.com/syv-ai/HyperQwen). More in the [details](docs/DETAILS.md#credits-and-licenses).diff --git a/docs/DETAILS.md b/docs/DETAILS.mdnew file mode 100644index 000000000..71c873034--- /dev/null+++ b/docs/DETAILS.md@@ -0,0 +1,325 @@+# Strata - the details++The technical side of Strata: every measured number, the API, images, all settings and how the engine works.+New here? Start with the [README](../README.md) - it has everything you need to install and use it.++> **On this page:** [Speed](#speed-measured) · [Other GPUs](#other-gpus-estimated) · [Which model?](#which-model) ·+> [Requirements](#before-you-start) · [Windows](#windows) · [Linux](#linux) · [API](#using-it) · [Images](#images-vision) ·+> [Troubleshooting](#troubleshooting) · [How it works](#how-it-works)++---++## Speed (measured)++RTX 5070 **12 GB**, Ryzen 5 7600 (6 cores), 64 GB DDR5-5200, Windows. One code-agent prompt per length, 256 generated+tokens, MTP speculative decoding on. "262K" is the model's full context window (a 259,943-token prompt).++### Prompt processing (tokens/s)++| Model | 1K | 4K | 32K | 64K | 128K | 262K |+| --- | ---: | ---: | ---: | ---: | ---: | ---: |+| **Q2_0** | 389 | 539 | 571 | 561 | 543 | 496 |+| **IQ2_XS** | 332 | 463 | 495 | 486 | 472 | 437 |+| **IQ3_XXS** | 285 | 410 | 435 | 427 | 414 | - |++### Output (tokens/s)++| Model | 1K | 4K | 32K | 64K | 128K | 262K |+| --- | ---: | ---: | ---: | ---: | ---: | ---: |+| **Q2_0** | 88.7 | 94.6 | 87.5 | 76.4 | 65.1 | 56.3 |+| **IQ2_XS** | 82.0 | 78.0 | 65.3 | 63.7 | 52.0 | 48.0 |+| **IQ3_XXS** | 64.6 | 65.6 | 57.3 | 54.4 | 44.8 | - |++IQ3_XXS at 262K is not measured: with its 43 GB of experts, a 260K-token context brings a 64 GB PC to its memory+limit. Use up to 128K with IQ3_XXS on 64 GB.++Time to first token is prompt length / prompt speed: about 7 s at 4K, 55 s at 32K, 4 minutes at 128K and 9 minutes at+262K. The raw numbers: [`bench/results/`](../bench/results/). The [paper](paper/Strata-Paper.pdf) explains every number.++## Other GPUs (estimated)++Not measured - estimated from the runs above (same CPU and 64 GB RAM): the GPU part scaled by memory bandwidth, the CPU+part by how many more experts the card's VRAM holds. Treat as **±20%**. Numbers are *prompt / output* tokens/s.++| GPU | Model | 1K | 4K | 32K | 64K | 128K | 262K |+| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |+| RTX 5060 Ti 16GB | Q2_0 | ~341 / ~80 | ~472 / ~87 | ~501 / ~81 | ~492 / ~72 | ~476 / ~62 | ~435 / ~53 |+| | IQ2_XS | ~291 / ~80 | ~406 / ~77 | ~434 / ~63 | ~426 / ~62 | ~413 / ~51 | ~383 / ~47 |+| | IQ3_XXS | ~249 / ~66 | ~359 / ~65 | ~381 / ~56 | ~374 / ~54 | ~363 / ~45 | - |+| RTX 3090 24GB | Q2_0 | ~355 / ~128 | ~491 / ~140 | ~521 / ~130 | ~512 / ~115 | ~495 / ~100 | ~453 / ~85 |+| | IQ2_XS | ~303 / ~131 | ~422 / ~128 | ~451 / ~103 | ~444 / ~102 | ~430 / ~85 | ~398 / ~78 |+| | IQ3_XXS | ~260 / ~106 | ~374 / ~103 | ~396 / ~89 | ~390 / ~85 | ~378 / ~71 | - |++More VRAM matters more than a faster GPU: every extra GB holds ~700 more experts, and every expert on the GPU is one the+CPU does not have to compute. A 3090's 24 GB takes most of the CPU work away.++## Which model?++All three are [ISTA-DASLab's GSQ-RCO quantizations](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF)+of [Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next).++| Model | Download | RAM it uses | Speed | Quality |+| --- | ---: | ---: | --- | --- |+| **Q2_0** | 66 GB | ~34 GB experts + ~6 GB | fastest | good |+| **IQ2_XS** | 68 GB | ~36 GB experts + ~6 GB | close to Q2_0 | a bit better |+| **IQ3_XXS** | 76 GB | ~43 GB experts + ~6 GB | slower (more CPU work) | best |++With 64 GB of RAM all three fit (close the browser for IQ3_XXS, and keep its context at 128K or less). With 48 GB only Q2_0 / IQ2_XS may fit. 32 GB is not enough.++### Or: Swift 1.5 (a fine-tune that thinks shorter)++The setup's first question also offers **[Swift 1.5](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)**,+UkisAI's fine-tune of Qwen3.8-Flash-Next, trained to reach the answer with much less thinking (its authors: 63% fewer+thinking tokens, 1.8x sooner answers, under 1% accuracy loss). Same architecture, the same three sizes, its own+vision encoder; Strata runs it at the same speed (4K, IQ2_XS: 465 prompt / 78.7 output tokens/s, vs 467 / 78.3 for+the original). Its authors recommend **IQ2_XS** (their Q2_0 is marked experimental). Its license is the Swift Open+License 1.0 - read it on the model page.++Our small check (8 reasoning questions, default thinking, IQ2_XS): both models got **8/8**; Swift used **1,234**+output tokens in 28 s, the original **2,682** in 46 s - most of the difference from one question the original+thought about for 1,524 tokens. Not a benchmark, but consistent with the claim.++```+START-HERE.bat --setup --family swift --model IQ2_XS+```++## Before you start++You need **only an NVIDIA driver** (version 580 or newer; update it with the NVIDIA App or from+[nvidia.com/drivers](https://www.nvidia.com/drivers)). Everything else is installed for you the first time.++| | |+| --- | --- |+| GPU | NVIDIA **RTX 30, 40 or 50 series**, **12 GB VRAM or more** (8 GB runs, slowly). Measured on an RTX 5070; RTX 30/40 are untested. |+| RAM | **64 GB** recommended (see the table above). |+| CPU | x86-64 with AVX2 (any Intel/AMD desktop CPU from the last ~8 years). AVX-512 (Ryzen 7000/9000) is a bit faster. |+| Disk | ~70-80 GB free for the model, ~6 GB for the MTP layer (+1 GB with images). **Q2_0 on an AVX-512 CPU** also writes a one-time ~40 GB copy of its experts for the fast CPU kernel. An NVMe SSD is strongly recommended. |+| OS | Windows 10/11, or Linux (Ubuntu 22.04/24.04 get everything installed automatically). |++What the first start installs, all inside this folder (`.venv/`, `engine/`, `third_party/`, `models/`, `packs/`, `mtp/`):+Python 3.12 if you have none (for your user account, no admin), a private Python environment, NVIDIA's CUDA libraries+(from pip, ~0.4 GB), the ready-made Strata engine for RTX 30/40/50, the model and the MTP draft layer. If no+ready-made engine fits your PC, it offers to install the build tools (Visual Studio Build Tools + CUDA Toolkit on+Windows, `build-essential` + CUDA on Ubuntu) and compiles the engine for your GPU (asks first; 20-40 minutes once).++---++## Windows++### Double-click `START-HERE.bat`++**The first time** it asks four questions and does the rest:++1. **Which model?** Qwen3.8-Flash-Next (the original) or Swift 1.5 (the fine-tune that thinks shorter).+2. **Which size?** Q2_0, IQ2_XS or IQ3_XXS (it recommends one for your RAM).+3. **How much context?** 8K to 256K tokens (it recommends one for your VRAM).+4. **Images?** yes / no (see [Images](#images-vision)).++Then it downloads and prepares everything (the model is 66-76 GB, so the first start takes a while; an interrupted+download continues where it stopped) and **starts the model**: your browser opens `http://127.0.0.1:8080`, a small+page that shows it is running and lets you chat. The API is at `http://127.0.0.1:8080/v1` for your apps.++**Every time after that**, `START-HERE.bat` just starts the model (30-90 s to load 34-43 GB into RAM). Nothing is+downloaded again. Closing the window stops the model.++```+START-HERE.bat --setup install another model, or change context / images+START-HERE.bat --model IQ2_XS --context 32768 --vision yes --yes no questions+START-HERE.bat --gguf-dir D:\models\IQ2_XS use GGUF files you already have+START-HERE.bat --port 8081 another port+```++With more than one model installed, it asks which one to start. `run-<model>.bat` starts a model directly.++### Chat in the terminal (optional)++```+.venv\Scripts\python chat.py+```++---++## Linux++```bash+./setup.sh+```++The same questions, the same automatic install (it uses `sudo apt` for Python and, only if it has to compile,+for the build tools), and the same start: `http://127.0.0.1:8080`. Later runs of `./setup.sh` (or `./run-<model>.sh`)+start the model directly. Options as on Windows (`./setup.sh --setup`, `--model Q2_0 --yes`, `--gguf-dir /data/Q2_0`).+Terminal chat: `.venv/bin/python chat.py`.++---++## Using it++The server listens on `http://127.0.0.1:8080` (change with `--port` in setup, or edit the run script).++| API | Endpoint |+| --- | --- |+| OpenAI Chat Completions (stream and non-stream, tools) | `POST /v1/chat/completions` |+| Anthropic Messages (stream and non-stream, tools) | `POST /v1/messages` |+| Model list / health | `GET /v1/models`, `GET /health` |++```bash+curl http://127.0.0.1:8080/v1/chat/completions -H "Content-Type: application/json" -d '{+ "model": "strata", "messages": [{"role": "user", "content": "Write a haiku about GPUs."}], "max_tokens": 512 }'+```++```python+from openai import OpenAI+client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="none")+r = client.chat.completions.create(model="strata", messages=[{"role": "user", "content": "Hello!"}])+print(r.choices[0].message.content)+```++- **Thinking levels: none, low, medium, high.** The model thinks before it answers (streamed as+ `reasoning_content`, Anthropic: `thinking` blocks). Choose how much per request - in the chat page (the "Thinking"+ menu), in `chat.py` (`/think low`), or over the API:++ | API | how |+ | --- | --- |+ | OpenAI | `"reasoning_effort": "none" \| "low" \| "medium" \| "high"` (also `"reasoning": {"effort": ...}`, or `"chat_template_kwargs": {"enable_thinking": false}`) |+ | Anthropic | `"output_config": {"effort": "low" \| "medium" \| "high"}`, `"thinking": {"type": "disabled"}`, or `"thinking": {"type": "enabled", "budget_tokens": N}` (under 2K = low, under 8K = medium, more = high) |++ Without a setting the model uses its own default, **high**. `none` answers at once (fastest); `low` keeps the thinking+ short. The levels are instructions the model was trained with, not a hard token limit: on easy questions all three+ think briefly, on hard ones `high` thinks longest and is most accurate.+- **Chat apps.** Any app with an "OpenAI-compatible" provider works: base URL `http://127.0.0.1:8080/v1`, any API key.+- **Context.** Chosen in setup (8K-262K). Requests longer than that are refused, never silently cut.+- **From other devices / the internet.** The server listens on your PC only (`127.0.0.1`). To reach it from elsewhere,+ put a tunnel in front of it, for example [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/do-more-with-tunnels/trycloudflare/):+ `cloudflared tunnel --url http://127.0.0.1:8080`. **Set a key first**, or anyone with the link can use your PC:+ add `"api_key": "some-long-secret"` to `strata-<model>.json` (or set the `STRATA_API_KEY` environment variable);+ clients then send it as their API key.++**Current limits (v1):** one request at a time; greedy decoding (temperature is ignored); every request processes its+whole prompt again (no conversation cache yet, so long chats have a long time-to-first-token); images only when set up+with them (below); no video.++---++## Images (vision)++The model has a vision encoder: [`mmproj-Qwen3.8-Flash-Next-BF16.gguf`](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF)+(0.9 GB, a 27-layer ViT plus the projector into the language model). It is **optional**: say yes when the setup asks+"Images?", or run it again with `--vision gpu` (or `--vision cpu`). The setup downloads the encoder, builds a small+helper (`strata-vision`, from llama.cpp's `mtmd` library) and adds it to your start script. Nothing else changes.++| Encoder on | Time per picture | Cost |+| --- | --- | --- |+| **GPU** (recommended) | **0.1-0.5 s** (up to 1,024 image tokens) | ~1.4 GB of VRAM is kept free for it, so the expert cache is smaller: text output is a few % slower (table below) |+| CPU | 10-30 s (pictures are scaled down to ~300 image tokens) | nothing on the GPU |++A picture becomes up to 1,024 tokens of the context (a 640x480 photo: 300). The same picture sent again, as chat apps+do on every turn, is encoded only once.++### Sending a picture++**Terminal chat:** type `/image <path to a picture>`, press Enter, then type your question.++```+you> /image C:\Users\me\Pictures\receipt.jpg+(picture attached: receipt.jpg - now type your question)+you> What is the total on this receipt?+```++**OpenAI API** (an `image_url` part: a `data:` URL, an `http(s)://` URL or a local file path):++```python+import base64+from openai import OpenAI+client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="none")+img = base64.b64encode(open("photo.jpg", "rb").read()).decode()+r = client.chat.completions.create(model="strata", messages=[{"role": "user", "content": [+ {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{img}"}},+ {"type": "text", "text": "What is in this picture?"}]}])+print(r.choices[0].message.content)+```++**Anthropic API:** an `image` block with a `base64` (or `url`) source, as usual.++JPEG, PNG, BMP, GIF, WebP, TIFF and AVIF work (the last ones are converted to PNG first; agents such as omp send+WebP). Chat apps with image upload work the same way.++### Speed with images on (4K context, measured)++| Model | Prompt tok/s, images off | Prompt tok/s, images on | Output tok/s, images off | Output tok/s, images on |+| --- | ---: | ---: | ---: | ---: |+| **Q2_0** | 541 | 531 | 90.7 | 86.9 |+| **IQ2_XS** | 468 | 458 | 77.1 | 74.0 |+| **IQ3_XXS** | 411 | 401 | 64.7 | 59.5 |++"Off" is the published setup; "on" runs with the encoder loaded on the GPU and its VRAM kept free, so ~1,000 fewer+experts fit in VRAM and the CPU computes a few more per token: 2-8% slower. For text, turning images on changes+nothing else (the output is bit-identical when the VRAM is the same).++A question about a picture (a 640x480 newspaper page = 300 image tokens, a 328-token prompt; the whole request, encoder+on the GPU, measured through the API):++| Model | Answer ("MEN WALK ON MOON") | Picture encoded | Prompt | Output |+| --- | ---: | ---: | ---: | ---: |+| **Q2_0** | 1.9 s | ~0.1 s | 207 tok/s | 65-73 tok/s |+| **IQ2_XS** | 2.3 s | ~0.1 s | 173 tok/s | 50-60 tok/s |+| **IQ3_XXS** | 2.7 s | ~0.1 s | 144 tok/s | 41-50 tok/s |++(Short prompts run below the 4K prompt speed: a 2,048-token chunk is where the prompt path is efficient. Short answers+run below the long-output speed: the first rounds have no draft yet.)++**How it works inside:** the encoder turns the picture into rows of the same width as the model's word embeddings;+Strata puts them where the prompt has `<|image_pad|>` tokens and gives each one its 2-D position (row and column in the+picture; the model uses interleaved M-RoPE). Answers match llama.cpp's multimodal implementation token for token on our+test images.++---++## Troubleshooting++| Symptom | What to do |+| --- | --- |+| `the NVIDIA driver is too old` | Update the driver (NVIDIA App or nvidia.com/drivers), restart, run `START-HERE.bat` again. |+| Python or the build tools could not be installed | Install what it names (links are printed), then run it again. Everything already done is kept. |+| `port 8080 is already in use` | Strata is already running (look for its window), or another program uses the port: `START-HERE.bat --port 8081`. |+| `cudaHostRegister ... out of memory` in the log | Normal on Windows: the engine pins the experts in per-layer slices instead. Only a problem if the load then fails. |+| The first start takes minutes | It is reading 34-43 GB into RAM; the second start is faster while the files are in the OS cache. |+| Slow output, disk light busy | Not enough free RAM: close other programs, or choose Q2_0 / IQ2_XS. |+| `prompt ... exceeds the context` | The request is longer than the context you chose: run setup again with a bigger `--context`. |+| Slower than the tables | The monitor plugged into the GPU and other GPU programs take VRAM from the expert cache; RAM running below its rated speed (enable EXPO/XMP in the BIOS) slows the CPU half. |+| `this server was started without the vision encoder` | The model was set up for text only: run setup again with `--vision gpu`. |+| A picture is refused or `cannot read the image` | The file is not a picture Pillow can open (JPEG, PNG, WebP, GIF, BMP, TIFF, AVIF work). |+| Pictures are slow (10-30 s) | The encoder runs on the CPU: run setup again with `--vision gpu` (needs ~1.4 GB of VRAM). |+| Anything else | The engine log is `strata-<model>.log` in this folder. |++---++## How it works++<p align="center"><img src="paper/tiers.svg" width="760" alt="memory tiers"></p>++- **GPU (VRAM):** attention and DeltaNet mixers, the gated-residual weights, routers, shared experts, output head, the MTP+ draft layer, the KV cache, and an **expert cache** that fills the rest of VRAM with the most-used experts (it adapts to+ the conversation while you chat).+- **RAM:** all 24,576 experts, pinned. The CPU computes the experts that are not on the GPU **in place**, at the same time+ as the GPU works on the cached ones (AVX-512 / AVX2 kernels, ggml's for the i-quants).+- **SSD:** the 28.8 GB n-gram table, read a few rows per token through the OS cache.+- **Speculation:** the model's own MTP layer drafts up to 3 tokens; one pass over all 48 layers checks them. 2.4-3.2+ tokens per pass on average.+- **Prompts** are processed in 2,048-token chunks with the experts streamed to the GPU over PCIe.++The full story, with measurements, bottlenecks and what comes next: **[docs/paper/Strata-Paper.pdf](paper/Strata-Paper.pdf)**.++---++## Credits and licenses++- Model: [Qwen/Qwen3.8-Flash-Next](https://huggingface.co/Qwen/Qwen3.8-Flash-Next) by the Qwen team; quantizations:+ [ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF).+ Swift 1.5: [ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF](https://huggingface.co/ukisai/Swift-1.5-Qwen3.8-Flash-Next-GSQ-RCO-GGUF)+ by UkisAI. Their licenses apply to the weights.+- [llama.cpp / ggml](https://github.com/ggml-org/llama.cpp) (MIT): the i-quant formats, the GPU dot products and+ dequantizers transcribed in `src/kernels/cuda/iq_kernels.cu`, the CPU backend linked for the i-quant experts, the+ `mtmd` library behind the image encoder (`tools/vision/`), and `gguf-py` used by the tools. See+ `third_party/ggml/LICENSE`.+- Ideas from [Splash](https://github.com/incoai/splash), [ninfer](https://github.com/Neroued/ninfer) and+ [HyperQwen](https://github.com/syv-ai/HyperQwen); references in the paper.diff --git a/serve/server.py b/serve/server.pyindex 1afb7e194..a42eda25b 100644--- a/serve/server.py+++ b/serve/server.py@@ -6,8 +6,9 @@Endpoints: POST /v1/chat/completions (OpenAI, stream and non-stream), POST /v1/messages (Anthropic, stream andnon-stream), GET /v1/models, GET /health. One sequence at a time behind a FIFO (plan: one resident sequence).Images (optional, when the config has a "vision" entry): OpenAI image_url parts and Anthropic image blocks (base64-data, http(s) URLs or local file paths; JPEG/PNG/BMP/GIF) go through `strata-vision` (the model's mmproj file) and-reach the engine as embeddings (`GENI`).+data, http(s) URLs or local file paths) go through `strata-vision` (the model's mmproj file) and reach the engine as+embeddings (`GENI`). JPEG/PNG/BMP/GIF go straight in; WebP, TIFF, AVIF, ... (agents like omp send WebP) are+converted to PNG first with Pillow.Requests whose prompt plus max tokens exceed the engine's context are REJECTED with 400, never truncated.The engine boundary is `Engine.generate(prompt_ids, max_new, sampling, cancel) -> iterator of token ids`.@@ -155,9 +156,37 @@ class Vision:return Path(path).read_bytes()raise ValueError("an image must be a data: URL, an http(s) URL or a local file path")+ @staticmethod+ def normalize(data: bytes) -> bytes:+ """The formats strata-vision's decoder (stb_image) reads pass through; anything else is converted to PNG."""+ if data[:3] == b"\xff\xd8\xff" or data[:8] == b"\x89PNG\r\n\x1a\n" or data[:2] == b"BM" or \+ data[:6] in (b"GIF87a", b"GIF89a"):+ return data+ try:+ import io+ from PIL import Image+ except ImportError:+ raise ValueError("this image format needs Pillow (python -m pip install pillow); JPEG, PNG, BMP and "+ "GIF work without it") from None+ try:+ im = Image.open(io.BytesIO(data))+ im.load()+ except Exception as e:+ raise ValueError(f"the image could not be read ({e})") from None+ if im.mode in ("RGBA", "LA", "P") and "transparency" in im.info or im.mode in ("RGBA", "LA"):+ im = im.convert("RGBA")+ bg = Image.new("RGB", im.size, (255, 255, 255)) # transparent areas become white, not black+ bg.paste(im, mask=im.split()[-1])+ im = bg+ elif im.mode != "RGB":+ im = im.convert("RGB")+ out = io.BytesIO()+ im.save(out, format="PNG")+ return out.getvalue()+def encode(self, source: str) -> tuple[Path, int]:"""-> (embeddings file, number of image tokens)."""- data = self.load(source)+ data = self.normalize(self.load(source))key = hashlib.sha256(data).hexdigest()[:32]with self.lock:if key in self.cache:diff --git a/setup.py b/setup.pyindex 2d9efcdd4..f53493f70 100644--- a/setup.py+++ b/setup.py@@ -55,7 +55,7 @@ PREBUILT_ASSET = "strata-windows-x64.zip" if WIN else "strata-linux-x64.zip"CUDA_WHEELS = ["nvidia-cublas==13.0.2.14", "nvidia-cuda-runtime==13.0.96"]MIN_DRIVER = 580 # CUDA 13.0MIN_ENGINE = (0, 1, 1) # the ready-made engine that reads split models (Swift 1.5)-PY_PACKAGES = ["numpy", "jinja2", "regex", "pyyaml", "tqdm", "requests", "cmake", "ninja"]+PY_PACKAGES = ["numpy", "jinja2", "regex", "pyyaml", "tqdm", "requests", "cmake", "ninja", "pillow"]MODELS = {"Q2_0": {"about": "2-bit, the fastest", "download_gb": 66.4, "ram_gb": 48, "arena_gb": 34.0},@@ -725,7 +725,7 @@ def main() -> int:# ---- 3. python packagesstep(3, "Python packages")- pip_install(PY_PACKAGES, "numpy, jinja2, regex, pyyaml, tqdm, requests, cmake, ninja")+ pip_install(PY_PACKAGES, "numpy, jinja2, regex, pyyaml, tqdm, requests, cmake, ninja, pillow")# ---- 4. the enginestep(4, "the Strata engine")