Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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
41 changes: 40 additions & 1 deletion atom/mesh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,43 @@ 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.

## 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 prompt 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 and a
1 MiB text. A model that fails the probe keeps HuggingFace, with a warning, or
under `--fastokens-strict` its tokenizer fails to register. Tokens that only
`tokenizer_config.json` declares are the exception. fastokens encodes them as
the tokens they declare, as `transformers`, and so the engine, does, where
HuggingFace `tokenizers` encodes them as text. `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: 64 MiB, or `--prepare-max-tokenize-bytes` if that is larger), and so
do their `/v1/tokenize` batches. `--fastokens-segment-cache-mb` sizes
fastokens' cache of the text between special tokens, per tokenizer (default:
`FASTOKENS_SEGMENT_CACHE`, off when unset). 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. It tokenizes the
DeepSeek-V4.1-Flash requests of `tests/fixtures/atom_tokens/deepseek_v41_flash.json`
with the tokenizer files of the revision recorded there, which it downloads from
HuggingFace, or `$HF_ENDPOINT`. `scripts/atom_token_parity.py` records the tokens
ATOM's own chat and completion endpoints run a set of requests with: the fixture,
or, for `$ATOM_TOKEN_PARITY`, another checkpoint's or recorded requests. The
script's docstring shows how to run both.

## Reliability

- **Request preparation**: Parsing, template rendering and tokenization use a fixed
Expand All @@ -287,7 +324,8 @@ 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 by `--fastokens-max-tokenize-bytes` for the models fastokens encodes.
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 +361,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