tokenizer

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

README

Token Producer Plugin

Type: token-producer

DataProducer plugin that tokenizes the request prompt and publishes TokenIDs (and a flat sorted MultiModalFeatures list) on InferenceRequestBody.TokenizedPrompt for downstream consumers (scorers, filters, other data producers).

Implements requestcontrol.DataProducer and runs in the PrepareRequestData phase, before filters and scorers. The plugin is idempotent: if InferenceRequestBody.TokenizedPrompt is already populated by an earlier producer, tokenization is skipped. Multi-modal features are flattened into the upstream list shape, sorted by placeholder offset.

[!NOTE] Legacy alias tokenizer is still accepted but logs a deprecation warning at instantiation. Prefer token-producer in new configs.

Backend

Backend selection:

  • estimate (default): tokenizer-free byte-packing — no model, no service. Selected when no backend is set, and auto-created by the framework for any config whose plugins consume TokenizedPrompt (prefix cache, context-length, P/D routing) without declaring a token-producer.
  • vllm (or modelName): calls vLLM's /v1/completions/render and /v1/chat/completions/render over plain HTTP (TLS is not supported). Future protocol fields (e.g. grpc) can be added alongside url under the same vllm block.
  • udsTokenizerConfig: deprecated gRPC-over-UDS sidecar (see warning below).

[!WARNING] The estimate backend approximates token boundaries (≈4 bytes/token); its token IDs do not correspond to engine tokens. The precise prefix-cache scorer requires real tokens — configure a vllm token-producer explicitly for it. If omitted, the auto-created estimate producer satisfies the dependency but silently degrades precise cache correlation.

[!WARNING] The udsTokenizerConfig backend (gRPC-over-UDS sidecar) is deprecated and will be removed in a future release. Existing configs continue to work but emit a deprecation warning at startup. Migrate to vllm.url. See Migration below.

Config

Parameter Default Description
modelName – (required for vllm) Model whose tokenizer should be loaded / sent in render requests.
vllm.url http://localhost:8000 Base URL of the vLLM render endpoint (no trailing slash).
vllm.timeout 5s Per-request timeout for text-only requests.
vllm.mmTimeout 30s Per-request timeout for multimodal requests.

The estimate backend tunes multimodal image placeholder estimation (empty uses the defaults below):

Parameter Default Description
estimate.image.mode dynamic dynamic (width×height/factor) or static (a constant per-image count).
estimate.image.defaultResolution 640×360 Dynamic-mode fallback when an image's dimensions can't be decoded.
estimate.image.dynamic.factor 1024 Dynamic-mode pixels-per-placeholder-token divisor.
estimate.image.static.staticToken Static-mode per-image placeholder count.

Failure mode

Per-request errors are returned to the Director, which currently logs and continues; downstream scorers fall back to their own paths.

Deployment

The plugin calls POST {http}/v1/completions/render and POST {http}/v1/chat/completions/render, both of which are exposed by vllm serve <model> and by the GPU-less vllm launch render <model>. Any reachable HTTP endpoint serving the same model the scheduler tokenizes for will work — sidecar in the EPP pod (loopback) or a dedicated Service shared by multiple EPP replicas.

# EPP pod spec
containers:
- name: vllm-render
  image: vllm/vllm-openai:latest          # any image shipping `vllm launch render`
  command: ["vllm", "launch", "render"]
  args: ["${MODEL_NAME}", "--port=8000"]
  ports: [{name: render-http, containerPort: 8000}]
  readinessProbe: {httpGet: {path: /health, port: 8000}, periodSeconds: 5}

Plugin config — sidecar (loopback):

- type: token-producer
  parameters:
    modelName: "${MODEL_NAME}"
    vllm:
      url: "http://localhost:8000"       # optional; this is the default

Plugin config — dedicated render Service:

- type: token-producer
  parameters:
    modelName: "${MODEL_NAME}"
    vllm:
      url: "http://vllm-render.default.svc.cluster.local:8000"

A complete sample config that pairs this with precise-prefix-cache-producer and prefix-cache-scorer is at deploy/config/sim-epp-tokenizer-vllm-http-config.yaml.

Migration from udsTokenizerConfig

The legacy UDS backend ran a per-pod tokenizer sidecar and connected over a shared Unix domain socket. Replace it with the vLLM HTTP /render backend, which calls the same model-serving pods (or a co-located vllm launch render sidecar) and removes the dedicated tokenizer image.

Before:

- type: token-producer
  parameters:
    modelName: "${MODEL_NAME}"
    udsTokenizerConfig:
      socketFile: /tmp/tokenizer/tokenizer-uds.socket

After:

- type: token-producer
  parameters:
    modelName: "${MODEL_NAME}"
    vllm:
      url: "http://localhost:8000"   # or a shared render Service

See the Deployment section above for sidecar vs shared-Service options.


Documentation

Overview

Package tokenizer provides a DataProducer plugin that tokenizes the request prompt and publishes the result on InferenceRequestBody.TokenizedPrompt for downstream consumers (scorers, filters, other data producers).

Index

Constants

View Source
const (
	// PluginType is the canonical type name used to register the plugin.
	PluginType = "token-producer"

	// LegacyPluginType is the previous type name. Existing YAML configs that
	// reference it continue to work. Will be removed in a future release.
	//
	// Deprecated: use PluginType ("token-producer") instead.
	LegacyPluginType = "tokenizer"
)

Variables

View Source
var TokenizedPromptDataKey = plugin.NewDataKey(tokenizedPromptKeyID, PluginType)

Functions

func CacheSaltFromBody

func CacheSaltFromBody(body *fwkrh.InferenceRequestBody) string

CacheSaltFromBody returns the cache salt from whichever protocol is populated. The protocol switch lives here so producers populate TokenizedPrompt.CacheSalt from one place and consumers read only that field.

func ChatCompletionsToRenderChatRequest

func ChatCompletionsToRenderChatRequest(chat *fwkrh.ChatCompletionsRequest) *tokenizerTypes.RenderChatRequest

ChatCompletionsToRenderChatRequest converts a ChatCompletionsRequest to a tokenization RenderChatRequest, including multimodal content blocks.

func ConvertMMFeaturesFromUpstream

func ConvertMMFeaturesFromUpstream(features []fwkrh.MultiModalFeature) (map[string][]string, map[string][]kvblock.PlaceholderRange)

ConvertMMFeaturesFromUpstream regroups the flat list of multimodal features back into the kv-cache map-shape expected by kvblock.ComputeBlockExtraFeatures.

func LegacyPluginFactory deprecated

func LegacyPluginFactory(name string, rawParameters *json.Decoder, handle plugin.Handle) (plugin.Plugin, error)

LegacyPluginFactory wraps PluginFactory for the deprecated `tokenizer` type name. It logs a one-time-per-instantiation deprecation warning and delegates to PluginFactory. Will be removed when LegacyPluginType is removed.

Deprecated: register PluginType ("token-producer") instead.

func PluginFactory

func PluginFactory(name string, rawParameters *json.Decoder, handle plugin.Handle) (plugin.Plugin, error)

PluginFactory is the factory function for the tokenizer plugin.

Types

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin tokenizes the prompt in the incoming request and writes the result to InferenceRequestBody.TokenizedPrompt for downstream DataProducer / scoring plugins.

func NewPlugin

func NewPlugin(ctx context.Context, name string, config *tokenizerPluginConfig) (*Plugin, error)

NewPlugin constructs the configured backend: udsTokenizerConfig (deprecated), vllm /render (selected by 'vllm' or 'modelName'), or estimate byte-packing (the default when no backend is set).

func (*Plugin) Produce

func (p *Plugin) Produce(ctx context.Context, request *scheduling.InferenceRequest, _ []scheduling.Endpoint) error

Produce derives the request's TokenizedPrompt via the configured backend and stores it on the body. Skips when one is already present; errors propagate to the Director, which logs and continues.

func (*Plugin) ProduceTimeout

func (p *Plugin) ProduceTimeout() time.Duration

ProduceTimeout surfaces the backend's render timeout when it manages one, so the director extends the data-producer budget past its default. Returns 0 to keep the default (e.g. the estimate backend, which is in-memory).

func (*Plugin) Produces

func (p *Plugin) Produces() map[plugin.DataKey]any

Produces returns the data keys this plugin produces.

func (*Plugin) TypedName

func (p *Plugin) TypedName() plugin.TypedName

TypedName returns the typed name of the plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL