Merge f-027-gh-eng-g (#3935 sm_89 in the DeepSeek CUDA package builds, #3796 collapsed tool-name alias and the rejected-calls marker)

This commit is contained in:
Niko1221 committed 2026-10-26 20:31:38 +01:00
commit 40c9dae95b
14 files changed
+283 -21

No files matched your search

+8 -2
View File
@@ -179,7 +179,13 @@ elseif(STRATA_ENABLE_CUDA)
# a build with no option was an sm_75 build. -DCMAKE_CUDA_ARCHITECTURES and the CUDAARCHS environment variable win.
set(_strata_cuda_arch_defaulted OFF)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES AND NOT DEFINED ENV{CUDAARCHS})
set(CMAKE_CUDA_ARCHITECTURES 120 CACHE STRING "CUDA architectures")
if(STRATA_BUILD_DSV41)
# #3935: the DeepSeek engine's own release shape (sm_86, sm_89, sm_120 + PTX 120, as packaging/build_dsv41_cuda.sh), so a hand
# build of strata-dsv41 with no architecture runs on an RTX 30, 40 or 50 card; the Qwen engine's default below is unchanged
set(CMAKE_CUDA_ARCHITECTURES "86-real;89-real;120" CACHE STRING "CUDA architectures")
else()
set(CMAKE_CUDA_ARCHITECTURES 120 CACHE STRING "CUDA architectures")
endif()
set(_strata_cuda_arch_defaulted ON)
endif()
enable_language(CUDA)
@@ -189,7 +195,7 @@ elseif(STRATA_ENABLE_CUDA)
option(STRATA_EXPERIMENTAL_SM60 "community build for GPUs below compute capability 7.5: Pascal sm_60, Volta sm_70 (#236)" OFF)
if(_strata_cuda_arch_defaulted)
# a recommendation, not a refusal: the release engine is built for 75;86;89;120, a hand build names its card
message(WARNING "Strata: CMAKE_CUDA_ARCHITECTURES was not set, so this build is for sm_120 (RTX 50) only. For another "
message(WARNING "Strata: CMAKE_CUDA_ARCHITECTURES was not set, so this build is for ${CMAKE_CUDA_ARCHITECTURES} only (sm_120 = RTX 50). For another "
"card pass it: -DCMAKE_CUDA_ARCHITECTURES=native (the GPUs in this PC), 75 (RTX 20), 86 (RTX 30), "
"89 (RTX 40), or a list like \"86;120\".")
endif()
+28
View File
@@ -55,6 +55,12 @@ Measured: an RTX 5070 (12 GB) with 64 GB of RAM and a 3.6 GB/s NVMe drive answer
tokens/s (4K) to 231 tokens/s (8K, layer-major path); an RTX 3060 (12 GB) with 46 GB of RAM about 8 to 10 tokens/s (code 9.9, agent work 7.8; 149 tokens/s at 8K; DSpark stays off there, `--dspark on` adds 2-13%); four R9700 about 48
tokens/s on 2.00 and 80 on 2.25 (code, with the shipped hot-expert profile). Under about 40 GB of RAM it is untested and slow; setup says so and still installs.
**RTX 40 series (sm_89).** The engine packages carry machine code for sm_86, sm_89 and sm_120 since 0.2.7 (before, an RTX 40 card ran the sm_86 code through
CUDA's same-generation rule). We have no RTX 40 card: the sm_89 build was compiled here but not run. A user's own build for sm_89 ran the 2.00 set on an
RTX 4090 48 GB with 128 GB of RAM (#3935, their numbers): decode 40.2 tokens/s (median of 5 answers of 64 tokens, `--ssd-cache 108 --dspark on --dspark-conf 0.65`),
prompts 141 tokens/s at 1.2K and 615 at 4.6K. They saw 16 to 22 tokens/s with `--dspark auto`, which decided "off" on their computer. This is one report on one
computer; other cards and RAM sizes can differ, and `--dspark auto` stays the default.
Setup downloads with resume and SHA-256, packs the model with the plain recipe (`pack_gguf.py --model SET --shards ... --engram
engram-IQ4_NL.gguf --engram-meta <UD shard 1> --dspark-gguf dspark-...-Q8_0.gguf`; do not add `--skip-tensors` or `--dense-override`:
that packs without an error and gives garbage text), copies the shipped hot-expert profile (`data/dsv41/profile-2.00.bin` or `-2.25.bin`)
@@ -144,6 +150,28 @@ Strata checks the package before it uses it: it must be the DeepSeek engine (not
Strata trusts, and every file must match the hash in the manifest. A damaged or foreign file is refused with a plain line and nothing is installed.
The unpacked folder works as well as the archive. The Strata (Qwen) engine is not touched either way.
### Building the engine for your card
The packages hold machine code for these NVIDIA cards (CUDA 13, Windows and Linux): sm_86 (RTX 30), sm_89 (RTX 40) and sm_120 (RTX 50), plus PTX for
sm_120. If your card is none of these, or you want your own build, compile `strata-dsv41` and put it where Strata looks for it. You need the CUDA toolkit
(the packages are built with 13.0), a C++ compiler, CMake, Ninja and the llama.cpp checkout Strata pins (`third_party/llama.cpp`).
```
cmake -S . -B build-dsv41 -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_DSV41=ON -DSTRATA_NATIVE_EXPERTS=ON "-DCMAKE_CUDA_ARCHITECTURES=89-real" -DSTRATA_GGML_DIR=third_party/llama.cpp
cmake --build build-dsv41 --target strata-dsv41 -j 8
```
Use your card's number in `CMAKE_CUDA_ARCHITECTURES`: 86 for RTX 30, 89 for RTX 40, 120 for RTX 50, or `native` for the cards in this computer. Without the
option a DeepSeek build is made for 86, 89 and 120. On Windows, `packaginguild_dsv41_windows.bat BUILD_DIR` does the same (`DSV41_ARCH` names the cards);
on Linux, `packaging/build_dsv41_cuda.sh` (`ARCH=...`). Then copy the file into the `engine` folder of your Strata install (next to `strata`); setup finds it there and does not download an engine:
```
python setup.py --family deepseek41 --model IST-DAS-2.00bpw
```
`strata-dsv41 --version` prints the commit it was built from. A build you made yourself is not signed by Strata, which is fine for your own computer.
Please tell us how it runs on your card (the speed, and the card and RAM): we only list a card as tested after someone has run it.
## Compressed experts (trellis), for testing
`strata-dsv41` reads the routed experts in the trellis types as well as the source MXFP4: TQK6 and TQK7 (agentionai's files), and the
+13 -2
View File
@@ -493,9 +493,20 @@ applies at the next start. Network, key, MCP and program keys are not editable t
every 15 s and `GET /status` says what it is doing. Closing the connection or pressing stop in your app stops the model.
- A tool call counts only when it names a tool the request declared. A namespaced tool (`mcp__filesystem.write_file`) is
that call when the model writes `mcp__filesystem__write_file`, `mcp__filesystem=write_file`, `mcp__filesystem_write_file`,
or the bare member (`write_file`) and exactly one declared tool has that member. Any other call, or any call in a request
that declared no tools, comes back as the text it was written as. A call whose envelope drifted by a token (`<=NAME>`,
or the bare member (`write_file`) and exactly one declared tool has that member. A name with `__` in it (`mcp__playwright__browser_navigate`)
is also that call when the model writes every `__` as `_` (`mcp_playwright_browser_navigate`), unless two declared tools collapse to the same
spelling. Any other call, or any call in a request that declared no tools, comes back as the text it was written as. Names are never
guessed: `bash` is not `shell`, and a reordered name (`server1_label_values` for `label_values_mcp_server1`) is not the declared one.
A call whose envelope drifted by a token (`<=NAME>`,
`<function:NAME>` or `<NAME>` instead of `<function=NAME>`) is read as the call when NAME is a declared tool.
- **A call that came back as text because its name was not declared (#3796).** The text stays exactly as the model wrote it and
`finish_reason` stays `stop` (or `end_turn` on `/v1/messages`). Next to it the reply carries a list, only when there is something in it:
`"strata_rejected_tool_calls": [{"name": "bash", "reason": "undeclared"}]` (at the top level of a Chat Completions reply, in
its last streamed chunk, and in the `message_delta` event and the message of `/v1/messages`; up to five names). A client that
wants to recover can answer the model with the tool names it does have and ask again; Strata never runs or forwards a call for a
tool the request did not declare. The server window prints the same names (`N <tool_call> block(s) ... went back as text`), and
`/metrics/prometheus` counts the blocks in `strata:tool_calls_unread_total`. A block that is malformed (not an undeclared name) is counted
there and in the window, but has no name to list.
- JSON output: `response_format: {"type":"json_object"}` or `{"type":"json_schema", ...}` on `/v1/chat/completions`. The schema
must accept only JSON objects at its root (`"type":"object"`, or `anyOf`/`oneOf` of object schemas). Local `#` references
work and remote ones are refused. This is schema prompting followed by server validation, not grammar-constrained
+2
View File
@@ -78,6 +78,8 @@ Tested on an RTX 3060 (Linux), an RTX 5070 (Windows), four R9700 cards (Linux) a
and Strix Halo on Linux do not run it yet; on Strix Halo Windows the graphics memory is the RAM, so most of the experts are
read from the SSD and an NVMe drive matters.
RTX 40 cards are covered by the engine packages since 0.2.7 (sm_89 code); we have not run one ourselves, see [DEEPSEEK41.md](DEEPSEEK41.md#the-engine-package) for a user's measurement.
**What you need:** a graphics card with 12 GB or more, 46 GB of RAM at least (64 GB is the tested comfortable size),
an NVMe SSD, and the disk space above. Setup warns when disk or RAM is short and does not stop you.
+6 -5
View File
@@ -3,18 +3,19 @@
# beside `strata` (setup.py dsv41_exe() looks for strata-dsv41 in the engine folder). Same toolchain and RUNPATH rule as the
# engine build: the result finds cudart/cublas beside itself ($ORIGIN), never the toolkit it was built with.
#
# SRC=<checkout> B=<build dir> CUDA=/usr/local/cuda-13.0 GG=<llama.cpp checkout> [ARCH="86-real;120"] [JOBS=6] packaging/build_dsv41_cuda.sh
# SRC=<checkout> B=<build dir> CUDA=/usr/local/cuda-13.0 GG=<llama.cpp checkout> [ARCH="86-real;89-real;120"] [JOBS=6] packaging/build_dsv41_cuda.sh
#
# ARCH defaults to the 0.2.4 release shape: SASS for sm_86 (RTX 3090 / 3060) and sm_120 (RTX Blackwell) + PTX sm_120 (the Windows twin
# built and ran on an RTX 5070; the Linux sm_86 build is the one tested on the RTX 3060 box). Needs CUDA 13 (the sm_120 code); for a
# CUDA 12.9 package pass ARCH="86-real;89-real;89-virtual" or leave strata-dsv41 out (the Pascal cuda12 variant has no DeepSeek path).
# ARCH defaults to the 0.2.7 release shape: SASS for sm_86 (RTX 3090 / 3060), sm_89 (RTX 40, #3935) and sm_120 (RTX Blackwell) + PTX sm_120, i.e.
# the package lists sm_86, sm_89, sm_120, compute_120 (the Windows twin built and ran on an RTX 5070; the Linux sm_86 build is the one tested on the
# RTX 3060 box; sm_89 is built here, not run: the one reporter's own build ran at 40.2 tok/s on an RTX 4090). Needs CUDA 13 (the sm_120 code);
# for a CUDA 12.9 package pass ARCH="86-real;89" (sm_86, sm_89, compute_89) or leave strata-dsv41 out (the Pascal cuda12 variant has no DeepSeek path).
# Prints the binary path on the last line; collect its libraries with packaging/collect_libs.py --binary <it> --search $CUDA/lib64.
set -eu
SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)}
B=${B:?B=<build dir>}
CUDA=${CUDA:?CUDA=<toolkit root>}
GG=${GG:?GG=<llama.cpp checkout at the pinned commit>}
ARCH=${ARCH:-86-real;120}
ARCH=${ARCH:-86-real;89-real;120}
JOBS=${JOBS:-6}
export PATH=$CUDA/bin:$PATH
# the build id: the commit, 9 characters. A git checkout gives it to CMake itself; a tarball has no .git, so COMMIT=<hex> is required there and goes to BUILD_ID.
+2 -2
View File
@@ -3,7 +3,7 @@ rem strata-dsv41.exe (the DeepSeek-V4.1 engine) for NVIDIA on Windows, built nex
rem beside strata.exe (setup.py dsv41_exe() looks for it in the engine folder). cudart is static; the only extra DLL is cublas64_13.dll,
rem which package_engine.py copies from CUDA_PATH like it does for strata.exe.
rem build_dsv41_windows.bat <build dir> [source dir] env: STRATA_GGML_DIR (llama.cpp), CUDA_ROOT (default CUDA 13.0), BUILD_JOBS (default 4),
rem DSV41_ARCH (default "86-real;120" = sm_86 + sm_120 SASS, PTX sm_120)
rem DSV41_ARCH (default "86-real;89-real;120" = sm_86 + sm_89 + sm_120 SASS, PTX sm_120)
rem Result: <build dir>\strata-dsv41.exe (about 66 MB). Windows: only the cuda13 variant gets it (sm_120 needs CUDA 13).
setlocal
set "BD=%~1"
@@ -11,7 +11,7 @@ set "SRCD=%~2"
if "%BD%"=="" ( echo usage: build_dsv41_windows.bat ^<build dir^> [source dir] & exit /b 2 )
if "%SRCD%"=="" set "SRCD=%~dp0.."
if "%CUDA_ROOT%"=="" set "CUDA_ROOT=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0"
if "%DSV41_ARCH%"=="" set "DSV41_ARCH=86-real;120"
if "%DSV41_ARCH%"=="" set "DSV41_ARCH=86-real;89-real;120"
if "%BUILD_JOBS%"=="" set "BUILD_JOBS=4"
if "%STRATA_GGML_DIR%"=="" ( echo set STRATA_GGML_DIR to the llama.cpp checkout & exit /b 2 )
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" >nul 2>&1
+6
View File
@@ -935,6 +935,12 @@ class OutputParser:
for alias in (f"{namespace}__{member}", f"{namespace}={member}",
f"{namespace}_{member}", member):
aliases.setdefault(alias, set()).add(name)
# #3796: the same tool written with every `__` collapsed to `_` (`mcp__playwright__browser_navigate` as
# `mcp_playwright_browser_navigate`, the way Qwen often flattens a name) is that tool. Only a spelling of a declared
# name: a reordered or renamed tool (`server1_label_values` for `label_values_mcp_server1`) is not guessed.
for name in self.schemas:
if isinstance(name, str) and "__" in name:
aliases.setdefault(name.replace("__", "_"), set()).add(name)
self.aliases = {alias: next(iter(names)) for alias, names in aliases.items()
if len(names) == 1 and alias not in self.schemas}
self.unread = 0 # #3441: `<tool_call>` blocks that opened like a call and were returned as text
+23 -6
View File
@@ -4775,6 +4775,8 @@ class Service:
("strata:requests_total", "counter", "Requests finished", t["requests"]),
("strata:drafts_offered_total", "counter", "Speculative draft tokens offered", t["drafts_offered"]),
("strata:drafts_accepted_total", "counter", "Speculative draft tokens accepted", t["drafts_accepted"]),
("strata:tool_calls_unread_total", "counter", "<tool_call> blocks returned as text (an undeclared name or a form the template does not use)",
t.get("tool_calls_unread", 0)),
("strata:model_loaded", "gauge", "1 while the model is loaded", int(self.loaded())),
]
return "".join(f"# HELP {name} {help_}\n# TYPE {name} {kind}\n{name} {value}\n"
@@ -5691,11 +5693,17 @@ class Service:
self.totals["tool_calls_from_reasoning"] = self.totals.get("tool_calls_from_reasoning", 0) + parser.rescued
print(f"[strata] tool calls inside the thinking: {parser.rescued} read as calls, {parser.refused} kept as "
f"reasoning (quoted, or the turn did not end on a stop)", flush=True)
rejected = []
if parser.unread:
named = getattr(parser, "unread_names", None)
print(f"[strata] {parser.unread} <tool_call> block(s) in the answer did not read as a call of a declared "
"tool and went back as text (a name the request did not declare, or a form the template does "
"not use)" + (f"; the names the model wrote: {', '.join(named)}" if named else ""), flush=True)
"not use)" + (f"; the names the model wrote: {', '.join(named)}" if named else "")
+ "; the response carries them as strata_rejected_tool_calls, /metrics counts them", flush=True)
with self.status_lock:
self.totals["tool_calls_unread"] = self.totals.get("tool_calls_unread", 0) + parser.unread
# #3796: the same names for the client (a machine-readable marker next to the text, which stays as the model wrote it)
rejected = [{"name": nm, "reason": "undeclared"} for nm in named or []]
if stops is not None and stops.hit is None and stops.held:
yield "event", Event("content", stops.flush()) # the held tail was not a stop string after all
done = {"finish": finish, "completion_tokens": n, "reused": (timings or {}).get("cache_n", 0),
@@ -5703,6 +5711,8 @@ class Service:
"reasoning_recoveries": recovery_count}
if stops is not None and stops.hit is not None:
done["stop_sequence"] = stops.hit
if rejected:
done["rejected_tool_calls"] = rejected
yield "done", done
@@ -6129,6 +6139,8 @@ def openai_chunks(svc: Service, req: dict, ids, thinking, tools, max_new, cancel
"prompt_tokens_details": {"cached_tokens": x.get("reused") or 0}}
if x.get("timings"):
last["timings"] = x["timings"] # llama.cpp's field: the speed its clients show
if x.get("rejected_tool_calls"):
last["strata_rejected_tool_calls"] = x["rejected_tool_calls"] # #3796: only when a call was refused as undeclared
yield last
@@ -6181,6 +6193,8 @@ def openai_collect(chunks) -> dict:
{"reasoning_content": lps["reasoning_content"]} if lps.get("reasoning_content") else {})}
if last.get("timings"):
out["timings"] = last["timings"]
if last.get("strata_rejected_tool_calls"):
out["strata_rejected_tool_calls"] = last["strata_rejected_tool_calls"]
return out
@@ -6349,11 +6363,12 @@ def anthropic_events(svc: Service, req: dict, ids, thinking, tools, max_new, can
# request, a cache write; input_tokens keeps the last token, as 0 makes Claude Code count the prompt twice (#1013)
reused = max(0, min(x.get("reused") or 0, len(ids) - 1))
read_now = len(ids) - reused
yield "message_delta", {"type": "message_delta", "delta": {"stop_reason": stop,
"stop_sequence": x.get("stop_sequence")},
"usage": {"input_tokens": 1, "cache_creation_input_tokens": read_now - 1,
"cache_read_input_tokens": reused,
"output_tokens": x["completion_tokens"]}}
delta_event = {"type": "message_delta", "delta": {"stop_reason": stop, "stop_sequence": x.get("stop_sequence")},
"usage": {"input_tokens": 1, "cache_creation_input_tokens": read_now - 1,
"cache_read_input_tokens": reused, "output_tokens": x["completion_tokens"]}}
if x.get("rejected_tool_calls"):
delta_event["strata_rejected_tool_calls"] = x["rejected_tool_calls"] # #3796
yield "message_delta", delta_event
yield "message_stop", {"type": "message_stop"}
@@ -6385,6 +6400,8 @@ def anthropic_collect(events) -> dict:
msg["stop_reason"] = e["delta"]["stop_reason"]
msg["stop_sequence"] = e["delta"].get("stop_sequence")
msg["usage"].update(e["usage"])
if e.get("strata_rejected_tool_calls"):
msg["strata_rejected_tool_calls"] = e["strata_rejected_tool_calls"]
for i in range(len(blocks) - 1): # a turn with no </think> (serve/dsml.py): the text is the answer; it is not also a thinking block
a, b = blocks[i], blocks[i + 1]
if a.get("type") == "thinking" and b.get("type") == "text" and a.get("thinking", "").strip() == b.get("text", "").strip():
+68
View File
@@ -4534,6 +4534,74 @@ class ForcedToolChoice(unittest.TestCase):
self.assertIn("Here is the report.", content)
self.assertIn("<function=lookup>", content)
def _undeclared_call_answer(self, name="lookup"):
from serve.frontend import CALL_END, CALL_START
return ("I will check that.\n" + CALL_START + f"\n<function={name}>\n<parameter=q>\n2+2\n</parameter>\n"
"</function>\n" + CALL_END)
def _rejected_of(self, b, stream):
"""The strata_rejected_tool_calls of a whole reply or of a streamed one (None when the reply has none)."""
if not stream:
return b.get("strata_rejected_tool_calls")
found = [json.loads(line[6:]).get("strata_rejected_tool_calls") for line in b.splitlines() if line.startswith("data: {")]
found = [f for f in found if f]
self.assertLessEqual(len(found), 1, "sent once, with the last chunk")
return found[0] if found else None
def test_an_undeclared_call_is_named_in_the_response(self):
"""#3796: the call stays text and finish_reason stays "stop"; the response also lists the names the model wrote
(strata_rejected_tool_calls), so a client can tell this from an ordinary answer and answer the model."""
self.says(self._undeclared_call_answer("execute_gdscript"))
for stream in (False, True):
with self.subTest(stream=stream):
before = self.svc.totals.get("tool_calls_unread", 0)
code, b = self.openai(stream=stream)
finish, calls, _ = self.call_of(code, b, stream)
self.assertEqual((finish, calls), ("stop", []), b)
self.assertEqual(self._rejected_of(b, stream), [{"name": "execute_gdscript", "reason": "undeclared"}])
self.assertEqual(self.svc.totals["tool_calls_unread"], before + 1) # /metrics counts it
if not stream:
self.assertIn("<function=execute_gdscript>", b["choices"][0]["message"]["content"]) # the text is untouched
def test_no_marker_when_nothing_was_rejected(self):
"""An ordinary answer and a declared call carry no extra field: the API is what it was."""
from serve.frontend import CALL_END, CALL_START
for label, answer in (("text", "The answer is 4."),
("declared call", CALL_START + "\n<function=search>\n<parameter=q>\n2+2\n</parameter>\n</function>\n" + CALL_END)):
self.says(answer)
for stream in (False, True):
with self.subTest(case=label, stream=stream):
code, b = self.openai(stream=stream)
self.call_of(code, b, stream)
self.assertIsNone(self._rejected_of(b, stream))
if stream:
self.assertNotIn("strata_rejected_tool_calls", b)
def test_a_collapsed_mcp_name_is_a_call_not_a_rejection(self):
"""#3796: `mcp_playwright_browser_navigate` for the declared `mcp__playwright__browser_navigate`."""
from serve.frontend import CALL_END, CALL_START
tools = [{"type": "function", "function": {"name": "mcp__playwright__browser_navigate", "description": "open a page",
"parameters": {"type": "object", "properties": {"q": {"type": "string"}}}}}]
self.says(CALL_START + "\n<function=mcp_playwright_browser_navigate>\n<parameter=q>\nx\n</parameter>\n</function>\n" + CALL_END)
for stream in (False, True):
with self.subTest(stream=stream):
code, b = self.openai(stream=stream, tools=tools)
finish, calls, _ = self.call_of(code, b, stream)
self.assertEqual((finish, calls), ("tool_calls", [("mcp__playwright__browser_navigate", {"q": "x"})]))
self.assertIsNone(self._rejected_of(b, stream))
def test_the_anthropic_reply_names_the_rejected_call_too(self):
self.says(self._undeclared_call_answer("bash"))
body = {"model": "m", "max_tokens": 400, "messages": [{"role": "user", "content": "2+2?"}],
"tools": [{"name": "search", "description": "search", "input_schema": {"type": "object", "properties": {}}}]}
req = urllib.request.Request(self.base + "/v1/messages", data=json.dumps(body).encode(),
headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req, timeout=30) as r:
msg = json.loads(r.read().decode())
self.assertEqual(msg["stop_reason"], "end_turn")
self.assertEqual(msg["strata_rejected_tool_calls"], [{"name": "bash", "reason": "undeclared"}])
self.assertFalse([c for c in msg["content"] if c["type"] == "tool_use"])
def test_a_call_with_a_dropped_function_keyword_is_still_the_call(self):
"""#3441: `<=search>` for `<function=search>`, as a model under a large tool surface writes it."""
from serve.frontend import CALL_END, CALL_START
+64
View File
@@ -193,5 +193,69 @@ class DriftedMcpNames(unittest.TestCase):
self.assertNotIn("namespace", calls[0])
def plain_tool(name):
return {"name": name, "parameters": {"type": "object", "properties": {"url": {"type": "string"}}}}
def call_text(name, param="url", value="https://example.com"):
return f"<tool_call>\n<function={name}>\n<parameter={param}>\n{value}\n</parameter>\n</function>\n</tool_call>"
def run_parser(text, tools, width=0):
parser = OutputParser(thinking=False, tools=tools, stream_tools=True, declared_only=True)
evs = []
step = width or len(text) or 1
for k in range(0, len(text), step):
evs += parser.feed(text[k:k + step])
evs += parser.finish("stop")
return evs, parser
class CollapsedUnderscoreNames(unittest.TestCase):
"""#3796: `mcp__server__tool` written as `mcp_server_tool` is a spelling of the declared tool (the same class of
difference as namespace__member). A name that is only similar stays text, and is named for the client."""
MCP = [plain_tool("mcp__playwright__browser_navigate"), plain_tool("mcp__playwright__browser_snapshot"),
plain_tool("mcp__playwright__browser_tabs"), plain_tool("todo_write")]
def test_the_collapsed_spelling_is_the_declared_tool(self):
for name in ("browser_navigate", "browser_snapshot", "browser_tabs"):
for width in (0, 1, 5):
with self.subTest(name=name, width=width):
evs, parser = run_parser("Opening it.\n" + call_text("mcp_playwright_" + name), self.MCP, width)
found = [e.call for e in evs if e.kind == "tool_call"]
self.assertEqual([c.name for c in found], ["mcp__playwright__" + name]) # the client gets the name it declared
self.assertEqual(found[0].arguments, {"url": "https://example.com"})
self.assertEqual(text_of(evs).strip(), "Opening it.")
self.assertEqual((parser.unread, parser.unread_names), (0, []))
def test_the_declared_spelling_and_a_plain_tool_are_unchanged(self):
evs, _ = run_parser(call_text("mcp__playwright__browser_tabs") + "\n" + call_text("todo_write"), self.MCP)
self.assertEqual([e.call.name for e in evs if e.kind == "tool_call"], ["mcp__playwright__browser_tabs", "todo_write"])
def test_a_tool_declared_in_the_collapsed_spelling_wins(self):
tools = self.MCP + [plain_tool("mcp_playwright_browser_tabs")]
evs, _ = run_parser(call_text("mcp_playwright_browser_tabs"), tools)
self.assertEqual([e.call.name for e in evs if e.kind == "tool_call"], ["mcp_playwright_browser_tabs"])
def test_two_tools_with_the_same_collapsed_spelling_are_not_guessed(self):
tools = [plain_tool("a__b_c"), plain_tool("a_b__c")]
evs, parser = run_parser(call_text("a_b_c"), tools)
self.assertEqual([e for e in evs if e.kind == "tool_call"], [])
self.assertIn("a_b_c", text_of(evs))
self.assertEqual(parser.unread_names, ["a_b_c"])
def test_a_reordered_or_renamed_tool_stays_text_and_is_named(self):
"""The LibreChat case (`server1_label_values` for `label_values_mcp_server1`) and the bash/shell case: no guessing."""
for declared, written in (("label_values_mcp_server1", "server1_label_values"), ("shell", "bash"),
("godot_execute_gdscript", "execute_gdscript")):
for width in (0, 3):
with self.subTest(written=written, width=width):
raw = "Done.\n" + call_text(written)
evs, parser = run_parser(raw, [plain_tool(declared)], width)
self.assertEqual([e for e in evs if e.kind == "tool_call"], [])
self.assertEqual(text_of(evs), raw) # the text is exactly what the model wrote
self.assertEqual((parser.unread, parser.unread_names), (1, [written]))
if __name__ == "__main__":
unittest.main()
+4 -2
View File
@@ -8235,11 +8235,13 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,
lib_dirs = [*lib_dirs, *dsv41_engine.lib_dirs(exe)] # its own package, and the rocm/bin an AMD package keeps the ROCm DLLs in
if exe is None:
if os.environ.get("STRATA_VERBOSE") == "1" or "--verbose" in sys.argv:
say(" Details for developers: build it with cmake -DSTRATA_BUILD_DSV41=ON and point STRATA_DSV41_EXE at it.")
say(" Details for developers: build it with cmake -DSTRATA_BUILD_DSV41=ON -DCMAKE_CUDA_ARCHITECTURES=<your card: 86 RTX 30, 89 RTX 40, 120 RTX 50> "
"and point STRATA_DSV41_EXE at it (docs/DEEPSEEK41.md, \"Building the engine for your card\").")
fail("DeepSeek's engine is not available for this computer yet",
"Supported graphics cards: NVIDIA RTX 30, 40 and 50 series, the Radeon AI PRO R9700, and a Ryzen AI Max (Strix Halo) on "
"Windows with the AMD DeepSeek engine package. " + dsv41_manual_steps(eng)
+ " Or update Strata later (a newer version may add your card), or pick another model. Nothing has been downloaded.")
+ " Or update Strata later (a newer version may add your card), pick another model, or build the engine for your card yourself "
"(docs/DEEPSEEK41.md, \"Building the engine for your card\"). Nothing has been downloaded.")
ok(f"engine: {exe}")
step(5, f"downloading {fam['title']} {model}")
+9 -1
View File
@@ -808,6 +808,14 @@ def arch_covers(archs, present: list[str]) -> bool:
return False
def arch_native(archs, present: list[str]) -> bool:
"""Whether a build with `archs` holds machine code made for one of the `present` cards itself (``sm_89`` on an ``sm_89`` card),
not only code that runs there through the same-major rule of `arch_covers` (``sm_86`` on an RTX 40) or as PTX. Only a tie-breaker
between packages that fit equally: a package with the card's own image is taken first (#3935)."""
cards = {item[3:] for item in present if item.startswith("sm_") and item[3:].isdigit()}
return any(arch.startswith("sm_") and arch[3:] in cards for arch in archs)
# ----------------------------------------------------------------------------------------------- resolve
def scan(root: Path | None = None) -> tuple[list[EngineComponent], list[dict]]:
@@ -974,7 +982,7 @@ def resolve(root: Path | None = None, *, backend: str | None = None, target: str
return item
# newest version first; with equal versions the build for the newer driver (the CUDA 13 build beside the CUDA 12 one)
return max(usable, key=lambda item: (_version_key(item.version), _version_key(item.min_driver.get("nvidia", "0")),
hip_preference(item.hip_archs)))
hip_preference(item.hip_archs), arch_native(item.cuda_archs, archs_here)))
#: A run config can name its engine as "component:strata-engine" instead of a path: the server then asks the
+2 -1
View File
@@ -412,7 +412,8 @@ def select_engine(packages, hardware: dict) -> tuple[EnginePackage | None, list[
if not fitting:
return None, reasons
best = max(fitting, key=lambda p: (version_key(p.version), ec._version_key(p.min_driver.get("nvidia", "0")),
ec.hip_preference(p.archs) if p.backend == "hip" else 1))
ec.hip_preference(p.archs) if p.backend == "hip" else 1,
ec.arch_native(p.archs, hardware.get("cuda_archs") or []) if p.backend == "cuda" else False))
kept = str(hardware.get("installed_variant") or "")
if best.backend == "cuda" and kept and best.variant != kept:
# An update never switches the CUDA build (#3835): a model on the CUDA 12 engine (its card is one CUDA 13 has no code for) must not
+48
View File
@@ -218,6 +218,54 @@ class Arch(unittest.TestCase):
self.assertFalse(ec.arch_covers(["sm_89"], ["sm_100"]), "sm_100 is major 10, not major 1 + minor 00")
self.assertTrue(ec.arch_covers(["sm_86", "sm_120"], ["sm_75", "sm_89"]), "one covered card is enough")
def test_a_native_image_is_the_card_itself_only(self):
"""#3935: arch_native tells a package with the card's own machine code from one that only runs there."""
self.assertTrue(ec.arch_native(["sm_86", "sm_89", "sm_120", "compute_120"], ["sm_89"]))
self.assertFalse(ec.arch_native(["sm_86", "sm_120", "compute_120"], ["sm_89"]), "sm_86 code runs on an RTX 40 but is not its image")
self.assertFalse(ec.arch_native(["sm_86", "compute_89"], ["sm_89"]), "PTX is not machine code")
self.assertFalse(ec.arch_native(["sm_89"], []))
self.assertTrue(ec.arch_native(["sm_75", "sm_89"], ["sm_75", "sm_120"]))
def test_the_deepseek_package_lists_89_and_an_rtx_40_card_is_accepted(self):
"""#3935: the build scripts and the CMake default name sm_89, the manifest list a build of them gets covers an sm_89 card
with its own image, and the engine picker takes it for an RTX 4090 with no refusal and prefers it to a package without it."""
import re
from strata_control import feed
def package_archs(spec):
"""CMAKE_CUDA_ARCHITECTURES to the package's archs list: N-real = sm_N, N = sm_N + compute_N."""
out = []
for item in spec.split(";"):
number, _, kind = item.partition("-")
out.append(f"sm_{number}")
if not kind:
out.append(f"compute_{number}")
return out
sh = (ROOT / "packaging" / "build_dsv41_cuda.sh").read_text(encoding="utf-8")
bat = (ROOT / "packaging" / "build_dsv41_windows.bat").read_text(encoding="utf-8")
cmake = (ROOT / "CMakeLists.txt").read_text(encoding="utf-8")
linux = re.search(r"^ARCH=\$\{ARCH:-([^}]+)\}", sh, re.M).group(1)
windows = re.search(r'set "DSV41_ARCH=([^"]+)"', bat).group(1)
self.assertEqual(linux, windows, "Windows and Linux ship the same DeepSeek architectures")
self.assertEqual(package_archs(linux), ["sm_86", "sm_89", "sm_120", "compute_120"])
self.assertIn('set(CMAKE_CUDA_ARCHITECTURES "86-real;89-real;120" CACHE', cmake)
def package(archs):
return feed.EnginePackage(version="0.1.50", platform="linux-x86_64", backend="cuda", variant="cuda13", archs=tuple(archs),
min_driver={}, min_runtime=None, build_id="b", url="u", format="tar.gz", size=1, sha256="a" * 64,
manifest_sha256="b" * 64, installed_bytes=1)
hw = {"platform": "linux-x86_64", "backend": "cuda", "cuda_archs": ["sm_89"], "nvidia_driver": None}
old, new = package(["sm_86", "sm_120", "compute_120"]), package(package_archs(linux))
self.assertFalse(feed.engine_fit_reasons(new, hw), "an RTX 4090 is accepted")
self.assertFalse(feed.engine_fit_reasons(old, hw), "the old package still fits through sm_86 (no refusal)")
for order in ((old, new), (new, old)):
best, _ = feed.select_engine(list(order), hw)
self.assertIs(best, new, "the package with sm_89 machine code wins an otherwise equal choice")
best, _ = feed.select_engine([old, new], {**hw, "cuda_archs": ["sm_86"]})
self.assertIsNotNone(best)
def test_the_packages_of_each_engine(self):
"""The Qwen engine (sm_86 + PTX 89) and the DeepSeek engine (sm_86 + sm_120 + PTX 120) on the RTX 20 to 50 families."""
from strata_control import feed