Documentation
¶
Index ¶
- type Config
- type MultiModalFeatures
- type Pooldeprecated
- type Task
- type Tokenizer
- type UdsTokenizer
- func (u *UdsTokenizer) Close() error
- func (u *UdsTokenizer) Encode(prompt string, addSpecialTokens bool) ([]uint32, []types.Offset, error)
- func (u *UdsTokenizer) Render(prompt string) ([]uint32, []types.Offset, error)
- func (u *UdsTokenizer) RenderChat(renderReq *types.RenderChatRequest) ([]uint32, *MultiModalFeatures, error)
- func (u *UdsTokenizer) Type() string
- type UdsTokenizerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Base model name for the tokenizer.
ModelName string `json:"modelName"`
// Number of worker goroutines for processing tokenization tasks.
WorkersCount int `json:"workersCount"`
UdsTokenizerConfig *UdsTokenizerConfig `json:"uds,omitempty"`
}
Config holds the configuration for the TokenizationPool.
func DefaultConfig ¶
DefaultConfig returns a default configuration for the TokenizationPool.
type MultiModalFeatures ¶ added in v0.7.0
type MultiModalFeatures struct {
// MMHashes maps modality (e.g. "image") to per-item content hashes.
MMHashes map[string][]string
// MMPlaceholders maps modality to per-item placeholder token ranges.
MMPlaceholders map[string][]kvblock.PlaceholderRange
}
MultiModalFeatures holds multimodal metadata produced by the tokenizer. Decoupled from proto types so callers don't depend on generated code.
type Pool
deprecated
type Pool struct {
// contains filtered or unexported fields
}
Pool encapsulates the queue and worker pool for tokenization tasks.
Deprecated: tokenize externally and call kvcache.Indexer.ScoreTokens.
func NewTokenizationPool ¶
NewTokenizationPool initializes a TokenizationPool with the specified number of workers and the provided configuration.
func (*Pool) EnqueueTokenization ¶
EnqueueTokenization enqueues a new tokenization task. This method only enqueues the task and does not start processing it.
func (*Pool) Run ¶
Run launches worker goroutines that process tasks until the context is cancelled.
func (*Pool) SetTokenizer ¶
func (*Pool) Tokenize ¶
func (pool *Pool) Tokenize(renderReq *types.RenderChatRequest, prompt string) ([]uint32, *MultiModalFeatures)
Tokenize queues a task and blocks until the final result is available.
type Task ¶
type Task struct {
RenderReq *types.RenderChatRequest
Prompt string
ModelName string
ResultCh chan<- tokenizationResponse // nil => fire-and-forget
}
Task represents a unit of work for tokenizing a prompt.
type Tokenizer ¶
type Tokenizer interface {
RenderChat(*types.RenderChatRequest) ([]uint32, *MultiModalFeatures, error)
Render(string) ([]uint32, []types.Offset, error)
Type() string
}
Tokenizer interface defines the methods for tokenization.
type UdsTokenizer ¶
type UdsTokenizer struct {
// contains filtered or unexported fields
}
UdsTokenizer communicates with a Unix Domain Socket server for tokenization. It implements the Tokenizer interface and manages a gRPC connection to the tokenizer service. The connection must be closed when the tokenizer is no longer needed by calling Close().
func NewUdsTokenizer ¶
func NewUdsTokenizer(ctx context.Context, config *UdsTokenizerConfig, modelName string) (*UdsTokenizer, error)
NewUdsTokenizer creates a new UDS-based tokenizer client with connection pooling.
func (*UdsTokenizer) Close ¶
func (u *UdsTokenizer) Close() error
Close closes the underlying gRPC connection to the tokenizer service.
func (*UdsTokenizer) Encode ¶
func (u *UdsTokenizer) Encode(prompt string, addSpecialTokens bool) ([]uint32, []types.Offset, error)
Encode tokenizes the input string and returns the token IDs and offsets.
func (*UdsTokenizer) Render ¶ added in v0.5.1
Render tokenizes a plain-text prompt via the UDS renderer service.
func (*UdsTokenizer) RenderChat ¶ added in v0.5.1
func (u *UdsTokenizer) RenderChat( renderReq *types.RenderChatRequest, ) ([]uint32, *MultiModalFeatures, error)
RenderChat renders a chat completion request using the UDS renderer service. It calls the RenderChatCompletion RPC which runs vLLM's OpenAIServingRender on the CPU, returning token IDs and optional multimodal features.
func (*UdsTokenizer) Type ¶
func (u *UdsTokenizer) Type() string
type UdsTokenizerConfig ¶
type UdsTokenizerConfig struct {
SocketFile string `json:"socketFile"` // UDS socket path (production) or host:port for TCP (testing only)
UseTCP bool `json:"useTCP"` // If true, use TCP instead of UDS (for testing only, default: false)
// ModelTokenizerMap maps a model name to the location of its tokenizer data.
//
// Each value may be either:
// 1) A directory path that contains tokenizer files for the model (preferred), or
// 2) A full path to a tokenizer.json file.
//
// Examples:
// {
// "model-a": "/mnt/models/model-a", // directory containing tokenizer.json, vocab, merges, etc.
// "model-b": "/opt/tokenizers/model-b/tokenizer.json" // explicit tokenizer.json path
// }
ModelTokenizerMap map[string]string `json:"modelTokenizerMap,omitempty"`
}
UdsTokenizerConfig represents the configuration for the UDS-based tokenizer, including the socket file path or TCP address (for testing only).
func (*UdsTokenizerConfig) IsEnabled ¶
func (cfg *UdsTokenizerConfig) IsEnabled() bool