Skip to content

feat(server): add b10621 tokenization, template, infill, and native embedding utilities #1442

Closed

Description

@inureyes

Parent

Problem

mlxcel tokenization currently supports only content and add_special. b10621 also supports special-token parsing and piece-return mode, and provides apply-template, prompt token-count, infill, and native embedding utilities that are missing or schema-incompatible.

Scope

  • Add parse_special and with_pieces behavior to /tokenize, including byte-array pieces when text is not valid UTF-8.
  • Align /detokenize special-token and byte reconstruction behavior.
  • Implement /apply-template with template, message, tool, and reasoning options supported by the loaded tokenizer/template stack.
  • Implement b10621-compatible chat and responses input-token-count aliases.
  • Implement native /embedding and /embeddings request/response behavior separately from /v1/embeddings.
  • Implement /infill only where the tokenizer/model declares compatible FIM tokens; return a capability diagnostic otherwise.
  • Align the --spm-infill prefix/suffix/middle ordering switch with the selected model's FIM token contract.

Acceptance criteria

Validation

  • Run utility tests with at least one Llama tokenizer and one Qwen tokenizer because their special-token and chat-template behavior differs.

Remaining work (kept open after the implementation PR)

POST /infill is mounted, gated on the model's fill-in-the-middle vocabulary, and covered by tests, but its manifest entry in compat/llama-server/b10621/routes.json is still deferred for two observable divergences, so this issue stays open and owns them:

  • Text in input_prefix, input_suffix, input_extra[].text, input_extra[].filename or prompt that contains one of the model's own FIM marker spellings is refused with a diagnostic naming the field and the marker. b10621 tokenizes those fields with special-token parsing off and serves the marker as literal text. mlxcel's generation entry point takes a prompt string that is re-tokenized with parsing on, and a string cannot express "these characters are not that token", so carrying the text through would let a file the client did not write restructure the FIM prompt and return a fluent wrong completion. Closing this needs a pre-tokenized prompt path into ModelProvider::generate, which touches shared types the xla-iree build also compiles.
  • The FIM context is not truncated to the prefill batch: b10621 keeps only the last 3*(n_batch/4) prefix tokens and the first (n_batch/4) - (2 + prompt) suffix tokens, while mlxcel serves the whole prefix and suffix, consistent with its policy elsewhere of clamping an over-long request rather than dropping prompt text. Deciding this needs a call on whether mlxcel should drop prompt text at all, and on which n_batch the window follows given that mlxcel's is --prefill-chunk-size (see the --batch-size entry, fix: Close the remaining b10621 context and batching gaps #1472).

Activity

  1. added
    status:backlogIn the backlog, not yet ready
    type:enhancementNew features, capabilities, or significant additions
    area:modelsModel architectures, weights, loading, metadata
    area:inferenceGeneration, sampling, decoding (incl. speculative, DRY)
    on Aug 26, 2026
  2. inureyes commented on Aug 28, 2026

    @inureyes
    MemberAuthor

    Implementation PR: #1480. It deliberately carries no closing keyword, so this issue stays open.

    Eight of the nine manifest entries this issue owns in compat/llama-server/b10621/routes.json flip out of deferred in that PR: --spm-infill, POST /tokenize, POST /detokenize, POST /apply-template, and the four input_tokens routes are now supported with a conformance test each. POST /embedding and POST /embeddings were listed in this issue's scope but are owned by #1452 and were already served in their native shape by #1441 (PR #1467), so nothing here touches them.

    POST /infill is mounted, gated on the model's fill-in-the-middle vocabulary and covered by tests, but its entry stays deferred with two recorded divergences, both now written into the issue body above. Closing this issue while that entry points at it would make the validator's --check-issues-open gate red for every open PR in the repository, so the issue owns the remainder instead.

    One correction worth recording for anyone who touches FIM discovery later: the marker spellings and their order were read out of libllama in the pinned b10621 archive rather than transcribed from memory. Two things a from-memory list gets wrong. DeepSeek-Coder's markers use the FULLWIDTH vertical line U+FF5C (<|fim▁begin|>), not ASCII |, which is also how the published deepseek-coder-1.3b checkpoint spells them, so an ASCII-pipe scan refuses /infill on a model that supports it. And b10621 additionally scans <|code_prefix|> / <|prefix|> and their suffix and middle siblings, which are absent from the commonly quoted list.

  3. inureyes commented on Aug 30, 2026

    @inureyes
    MemberAuthor

    Closing: this issue's implementation merged, and the entries that kept it open now carry a state that describes them.

    The work for tokenize, detokenize, apply-template, token-counting, native embedding and infill utilities landed and was verified at the time. What remained were manifest entries recording behavior that differs from llama-server b10621 on purpose and permanently, which none of the four original states could express: not supported because the behavior differs, not aliased because it is not equivalent, not not_applicable because the concept applies and is served, and not deferred because nobody intended to close the gap. The compatibility gate requires a deferred entry's issue to stay open, so this issue was pinned open by a vocabulary gap rather than by unfinished work.

    #1499 added the by_design state for exactly that case, and PR #1500 moved this issue's entries into it. Each carries a rationale object the validator requires in full: a kind separating an architectural impossibility from a policy choice, a reason, and a revisit_if naming what would have to change for the decision to be reconsidered. Each is pinned by a test, not by a note.

    Verified before closing: this issue now owns zero deferred entries, so closing it cannot redden the llama-compat manifest job for other pull requests. That failure mode happened twice earlier in epic #1431 and is what the check exists to prevent.

  4. self-assigned this
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferenceGeneration, sampling, decoding (incl. speculative, DRY)area:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions