Python module
interfaces
Interfaces for different pipeline behaviors.
PipelineTokenizer
class max.pipelines.interfaces.PipelineTokenizer(*args, **kwargs)
Interface for LLM tokenizers.
decode()
async decode(context: TokenGeneratorContext, encoded: TokenizerEncoded) → str
Decodes response tokens to text.
-
Parameters:
- context (TokenGeneratorContext) – Current generation context.
- encoded (TokenizerEncoded) – Encoded response tokens.
-
Returns:
Un-encoded response text.
-
Return type:
encode()
async encode(prompt: str) → TokenizerEncoded
Encodes text prompts as tokens.
-
Parameters:
prompt (str) – Un-encoded prompt text.
-
Raises:
ValueError – If the prompt exceeds the configured maximum length.
-
Returns:
Encoded prompt tokens.
-
Return type:
TokenizerEncoded
eos
property eos*: int*
new_context()
async new_context(request: TokenGeneratorRequest) → TokenGeneratorContext
Creates a new context from a request object. This is sent to the worker process once and then cached locally.
-
Parameters:
request (TokenGeneratorRequest) – Incoming request.
-
Returns:
Initialized context.
-
Return type:
TokenGeneratorContext