mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4961] [Engine] Metal batch slots: each slot rotates by its own M-RoPE table (pictures beside other requests) #5266
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5266
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4961
Author: @oceanio
Created: 11/1/2026
Status: 🔄 Open
Base:
main← Head:fix/metal-slot-mrope📝 Commits (1)
0aefdcemetal: pictures in batch slots, each slot rotates by its own M-RoPE table📊 Changes
2 files changed (+49 additions, -10 deletions)
View changed files
📝
metal/kernels/qsa.metal(+11 -6)📝
metal/src/engine/window.cpp(+38 -4)📄 Description
Problem and result
With
--visionand"parallel": 2on the Mac engine (0.2.9 and 0.2.10), a picture request decodes other text once another request joins it in the batch slots (#4908). The batch rows'qsa_prepis built with the rows constant (30) but not the M-RoPE one (24), so every slot row rotates by its plain cell position. After a picture, the text sits at fewer M-RoPE positions than it has cells, so it is rotated as if it came later. The slot-by-slot path (STRATA_METAL_BATCH_ROWS=0) reads the process's table instead, which the last request read in rebuilds. On the rows path text requests are not affected, because their table is the identity. On the slot-by-slot path a text request beside a picture can be affected too, because it reads the picture's table (T2 beside I2 on 0.2.10, below).With this PR each slot rotates by its own table, and every request of a pair decodes the same text as alone. Greedy, through 0.2.10's
serve/server.py, up to 400 tokens each, the second request 1 s after the first (rows path):Related discussion
Fixes #4908 (bug report, with the cause above). No maintainer reply yet.
Approach
Only
metal/src/engine/window.cppandmetal/kernels/qsa.metal:mropeBig_, setidxatidx * st_mrope_), allocated inslots_initonly when the table is in use (--vision).slot_copyinto a slot fills the slot's table from the admitting request's table: cells[0, upto)as they are (the K/V rows already hold them rotated), then one position per cell after the last one. A copy whose last cell is part of an image is refused with an error. A chat prompt ends in the assistant turn's text, so serve's requests never end in one.qsa_prep#rows#mrope(constants 30 and 24), with the row's offset inrinfo_'s fourth word, which was 0 until now. In the kernel, every rotation inqsa_prep(Q, K, and the indexer's queries and keys) takes the row's table.mrope_synccopies from the active slot's table instead of the process's.--visionnothing changes: no new buffer, the same pipelines, and the row word stays 0.Cost with
--visionand--batch N: (N + 1) tables of 3.1 MB each at 262K context, so 9.4 MB with 2 slots.Validation
Environment: Apple M5 Max (128 GB), macOS 26.7.1. Revision: this branch,
0aefdce7= 0.2.10 (ffa80d73) + 1 commit, engine 0.1.56-metal. Rebased from 0.2.9 with one conflict, inwindow.cpp's activation buffer size (0.2.10 adds room for its fp16 decode); the resolution keeps both, and the diff is otherwise the same lines. Model: Swift 1.5 IQ3_S (SC117's abliterated build, the same file layout as UkisAI's), repacked by setup, Swift's projector,--max-context 262144 --spec 2with MTP,"parallel": 2. Requests go through this tree'sserve/server.pyon a private port: temperature 0, up to 400 tokens, three synthetic pictures (6 shapes 640×400, a bar chart 640×400, an invoice 800×300). The 0.2.10 column comes from 0.2.10's own build with the same requests, in the same round.Passed:
--vision, batch rows: each request of the 5 pairs above gives its text alone (10 of 10; 0.2.10: 6 of 10). The engine stays the same process, with 10 slot admissions in the log.--visionwithSTRATA_METAL_BATCH_ROWS=0(slot by slot): the same 10 of 10 (0.2.10: 8 of 10, I1 beside T1 and T2 beside I2 differ), and each request alone gives the same text as on the rows path.--vision: two texts side by side give their text alone. T1 and T2 give the same text with and without--vision.--vision; I1, I2 and I3 with it.25eedc11, before the rebase) gave the same results: 10 of 10 on both paths, 0.2.9 itself 6 of 10 on the rows path.Failed:
None in the checks above. Separately, on 0.2.9 and 0.2.10 two requests that decode side by side in the slots for more than 60 s are stopped by the serve watchdog, with or without pictures and with or without this PR. #4960 fixes that.
Not run:
metal/only, which only the Metal build compiles.STRATA_METAL_F16=1: 0.2.10's fp16 decode is used by the solo window only (f16_enc_needs!rows_), so with it a request in a slot is not expected to give its solo text, pictures or not. All checks above run with the default (off).Limits
a slot copy that ends in an image) instead of guessing the positions after it.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.