IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

PixelGenerationTokenizer

PixelGenerationTokenizer​

class max.pipelines.lib.PixelGenerationTokenizer(model_path, pipeline_config, subfolder, *, subfolder_2=None, revision=None, max_length=None, secondary_max_length=None, trust_remote_code=False, default_num_inference_steps=50, scheduler_config_overrides=None, **unused_kwargs)

source

Bases: PipelineTokenizer[PixelContext, tuple[ndarray[tuple[Any, …], dtype[int64]], ndarray[tuple[Any, …], dtype[bool]]], OpenResponsesRequest]

Encapsulates creation of PixelContext and specific token encode/decode logic.

Parameters:

  • model_path (str) – Path to the model/tokenizer.
  • pipeline_config (PipelineConfig) – Pipeline configuration with ModelManifest metadata.
  • subfolder (str) – Subfolder within the model path for the primary tokenizer.
  • subfolder_2 (str | None) – Optional subfolder for a second tokenizer (e.g. text encoder).
  • revision (str | None) – Git revision/branch to use.
  • max_length (int | None) – Maximum sequence length for the primary tokenizer.
  • secondary_max_length (int | None) – Maximum sequence length for the secondary tokenizer, if used.
  • trust_remote_code (bool) – Whether to trust remote code from the model.
  • default_num_inference_steps (int)
  • scheduler_config_overrides (dict[str, Any] | None)

decode()​

async decode(encoded, **kwargs)

source

Decodes token arrays to text (not implemented for this tokenizer).

Parameters:

encoded (tuple[ndarray[tuple[Any, ...], dtype[int64]], ndarray[tuple[Any, ...], dtype[bool]]])

Return type:

str

encode()​

async encode(prompt, add_special_tokens=True, *, use_secondary=False, images=None)

source

Transforms the provided prompt into a token array.

Parameters:

  • prompt (str)
  • add_special_tokens (bool)
  • use_secondary (bool)
  • images (list[Image] | None)

Return type:

tuple[ndarray[tuple[Any, …], dtype[int64]], ndarray[tuple[Any, …], dtype[bool]]]

eos​

property eos: int

source

Returns the end-of-sequence token ID.

expects_content_wrapping​

property expects_content_wrapping: bool

source

Returns whether this tokenizer expects content wrapping.

new_context()​

async new_context(request, input_image=None)

source

Creates a new PixelContext object, leveraging necessary information from OpenResponsesRequest.

Parameters:

Return type:

PixelContext

postprocess()​

async postprocess(output)

source

Post-processes pipeline output.

Accepts either a raw numpy array or a GenerationOutput. For raw numpy arrays, denormalizes from [-1, 1] to [0, 1]. For GenerationOutput, returns as-is (denormalization is handled in the pipeline variant before encoding to OutputImageContent).

Parameters:

output (Any)

Return type:

Any