Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
8f929e0
feat(mesh): encode the prompts of listed models with fastokens
wanzhenchn Nov 19, 2026
0827639
fix(mesh): check fastokens' ids for config-only tokens, and probe more
wanzhenchn Nov 20, 2026
11ca1b8
fix(mesh): decode fastokens' config-only tokens, and retry downloads
wanzhenchn Nov 20, 2026
f56b46c
feat(mesh): render DeepSeek-V4.1 chats under ATOM's reasoning controls
wanzhenchn Nov 19, 2026
6849317
test(mesh): check token parity against ATOM in CI, not a recorded fix…
wanzhenchn Nov 21, 2026
f9809aa
Merge branch 'zwan/mesh-fastokens-encode' into zwan/mesh-deepseek-v41…
wanzhenchn Nov 21, 2026
9d881d8
perf(mesh): turn fastokens' segment cache on by default
wanzhenchn Nov 21, 2026
e2f4b0b
Merge remote-tracking branch 'origin/zwan/mesh-fastokens-encode' into…
wanzhenchn Nov 21, 2026
cfc168a
refactor(mesh): load fastokens from tokenizer.json alone
wanzhenchn Nov 21, 2026
51ad82f
Merge remote-tracking branch 'origin/zwan/mesh-fastokens-encode' into…
wanzhenchn Nov 21, 2026
5446339
docs(mesh): fastokens' segment cache is on by default
wanzhenchn Nov 23, 2026
725d90f
Merge branch 'zwan/mesh-fastokens-encode' into zwan/mesh-deepseek-v41…
wanzhenchn Nov 23, 2026
7da8f2b
fix(mesh): retry a registration whose tokenizer cannot be downloaded …
wanzhenchn Nov 23, 2026
c872a6d
Merge remote-tracking branch 'origin/main' into zwan/mesh-deepseek-v4…
wanzhenchn Nov 23, 2026
a655d0b
fix(mesh): take DeepSeek-V4.1 reasoning efforts as ATOM does
wanzhenchn Nov 23, 2026
4c421bc
Merge remote-tracking branch 'origin/main' into zwan/mesh-deepseek-v4…
wanzhenchn Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/atomesh-mocker-benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Set up build environment
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler python3-dev
sudo apt-get install -y protobuf-compiler python3-dev python3-venv
# pyo3 caches the detected Python in the restored target dir and only
# re-detects when an env var changes, so a runner-image Python upgrade
# would keep linking the old -lpython3.X. Key the detection on it.
Expand Down Expand Up @@ -112,6 +112,27 @@ jobs:
--target-dir atom/mesh/mocker/target/mesh \
--profile ci --lib --features atom-engine

# The token parity test compares the router's tokens with the ones ATOM's
# own endpoints give, here on CPU, for a DeepSeek-V4.1-Flash revision whose
# tokenizer files and chat encoder the script downloads from HuggingFace.
# So the unit tests leave it out and it runs here, once.
- name: Test token parity with ATOM
timeout-minutes: 20
run: |
set -euo pipefail
python3 -m venv "${RUNNER_TEMP}/atom"
"${RUNNER_TEMP}/atom/bin/pip" install -q torch --index-url https://download.pytorch.org/whl/cpu
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_ATOM=0.0.0+cpu.ci \
"${RUNNER_TEMP}/atom/bin/pip" install -q -e . httpx
"${RUNNER_TEMP}/atom/bin/python" atom/mesh/scripts/atom_token_parity.py \
deepseek-ai/DeepSeek-V4.1-Flash@314113f8a7dadb388215396ba5fbee2c610a04d6 \
--out "${RUNNER_TEMP}/atom_tokens.json"
ATOM_TOKEN_PARITY="${RUNNER_TEMP}/atom_tokens.json" cargo test \
--manifest-path atom/mesh/Cargo.toml \
--target-dir atom/mesh/mocker/target/mesh \
--profile ci --lib --features atom-engine -- \
--ignored routers::ingress::token_parity

# The vendored ext-proc protos must match the checksums pinned in
# manifest.json; offline, so a drifted file or manifest fails here.
- name: Check vendored ext-proc protos
Expand Down
2 changes: 2 additions & 0 deletions atom/mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ openai-protocol = { version = "=1.0.0", features = ["axum"] }
num-traits = "0.2"
rustpython-parser = "0.4.0"
llm-tokenizer = "=1.4.2"
# Without `hf-hub`, with which fastokens fetches models itself: mesh gives it the `tokenizer.json` it loaded.
fastokens = { version = "=0.3.6", default-features = false }
wfaas = "=1.0.0"
data-connector = "=1.0.0"
openmetrics-parser = "0.4.4"
Expand Down
66 changes: 65 additions & 1 deletion atom/mesh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,67 @@ chat template, such as DeepSeek V3.2 and V4
([#3377](https://github.com/ROCm/ATOM/issues/3377)). Use a policy that does not
need tokens, such as `cache_aware` or `round_robin`, for these models and APIs.

The router renders a chat it tokenizes with the model's chat template and the
request's `chat_template_kwargs` and `reasoning_effort`. For a checkpoint whose
`config.json` has a `model_type` with reasoning controls of its own in ATOM,
DeepSeek-V4.1's `deepseek_v41`, it renders the chat as ATOM does instead. Under
V4.1's rules, the request's `thinking`, `reasoning_effort` and
`chat_template_kwargs` set the template's `thinking_mode` and
`reasoning_effort`: a `minimal` effort is `low`, `medium` and `xhigh` are
`high`, a `none` effort or a disabled `thinking` is chat mode, and
`thinking.effort` may be a budget from 1 to 100. Only the kwargs V4.1's encoder
takes reach the template. Controls ATOM refuses get `400`, and a chat after a
`context` kwarg, which the template does not render, gets
`501 token_routing_unsupported`. The router does not know a worker's
`--default-chat-template-kwargs`.

## Tokenization

The router tokenizes requests with their model's HuggingFace tokenizer, or with
[fastokens](https://github.com/crusoecloud/fastokens) for the models listed in
`--fastokens-models`, by the name or source their tokenizer registers under, or
`*` for every model. fastokens encodes a `tokenizer.json` BPE faster than
HuggingFace `tokenizers`, and splits a long text between special tokens across
a pool of its own threads (one per logical core up to 32;
`FASTOKENS_BPE_THREADS` sets the number). Decoding, chat templates and vocabulary lookups stay with the
HuggingFace tokenizer.

A model encodes with fastokens only if fastokens encodes a set of probe texts
exactly as its HuggingFace tokenizer does, with special tokens and without. The
probe covers added tokens, digits, whitespace, several scripts, a chat, a 1 MiB
text and a 256 KiB one with no newline. A model that fails the probe keeps
HuggingFace, with a warning, or under `--fastokens-strict` its tokenizer fails
to register, with no retries. A `tokenizer.json` that fastokens cannot find or
download fails no probe: the model keeps HuggingFace, with a warning, or under
`--fastokens-strict` its registration fails and is retried.

fastokens loads `tokenizer.json` alone, as HuggingFace `tokenizers` does, so
both encode the tokens only `tokenizer_config.json` declares (Qwen3.5's audio
tokens, for one) as text, where `transformers`, and so the engine, encodes them
as tokens. With gRPC workers the router sends
the ids it encodes as the prompt, so the model runs on fastokens' ids, not only
routes by them. `mesh_fastokens_tokenizers_total{outcome}` counts tokenizers as
`loaded`, `fallback` or `refused`.

The prompts of these models tokenize up to `--fastokens-max-tokenize-bytes`
(default: the larger of 64 MiB and the other models' limit), and so do their
`/v1/tokenize` batches. `--fastokens-segment-cache-mb` sizes
fastokens' cache of the ids of the text between special tokens, per tokenizer
(default: 1024; 0 turns it off). An agent re-sends its history with each
request, and the cache keeps the router from encoding it again. It replaces
`--tokenizer-cache-*`, which does not apply to these models.

`test_requests_tokenize_as_on_atom` checks that requests tokenize for routing as
on ATOM, with either backend, and times encoding. `scripts/atom_token_parity.py`
tokenizes a set of requests, or recorded ones, with ATOM's own chat and
completion endpoints, in process and without a GPU, and the test compares the
router's tokens with those, in the file `$ATOM_TOKEN_PARITY` names, so it runs
only when asked for. CI's mesh unit tests run the two for a DeepSeek-V4.1-Flash
revision, whose tokenizer files and chat encoder the script downloads from
HuggingFace, or `$HF_ENDPOINT`, and the test with
`cargo test --lib -- --ignored routers::ingress::token_parity`. The script's
docstring shows how to run them for another checkpoint.

## Reliability

- **Request preparation**: Parsing, template rendering and tokenization use a fixed
Expand All @@ -287,7 +348,9 @@ need tokens, such as `cache_aware` or `round_robin`, for these models and APIs.
`--prepare-queue-timeout-ms` deadline (default: 250 ms); canceled waiters release
their slot immediately. All request parsing runs on this pool. Each request's
preparation shares one `--prepare-timeout-ms` deadline (default: 5000 ms), and
tokenization input is limited by `--prepare-max-tokenize-bytes` (default: 1 MiB).
tokenization input is limited by `--prepare-max-tokenize-bytes` (default: 1 MiB),
or for the models fastokens encodes by `--fastokens-max-tokenize-bytes`
(default: the larger of that limit and 64 MiB).
When ext-proc is enabled, the legacy `--ext-proc-parser-concurrency` and
`--ext-proc-max-tokenize-bytes` options apply only if the corresponding
`--prepare-*` option is unset; neither has a default of its own. On shutdown,
Expand Down Expand Up @@ -323,6 +386,7 @@ changing worker metric names.
| Routing | `mesh_route_*`, `mesh_session_*` | Policy decisions, session worker changes, engine-reported cached tokens against the router estimate |
| Circuit breaker | `mesh_worker_cb_*` | State, transitions, outcomes |
| Retry | `mesh_worker_retries_*` | Attempts, exhaustion, backoff |
| Tokenization | `mesh_fastokens_*` | Tokenizers that encode with fastokens, keep HuggingFace or fail to register |

[Routing metrics](docs/metrics.md) covers each routing metric's labels, the
policies and branches that record it, how to read the values, and example
Expand Down
Loading
Loading