IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Python module

max.pipelines.lib.registration_encoder

Serves embedding architectures that register an ENCODER.

An encoder-only architecture registers its encoder module for the ENCODER role, and encoder_pipeline_model() builds the pipeline model: it finalizes the config, constructs the encoder as encoder_cls(config), loads the checkpoint, builds the graph from encoder_input_types(), and batches and executes it. The encoder takes EncoderInputs and returns the embeddings: a graph-API (max.nn.legacy.Module) encoder in its __call__, over graph values, and a ModuleV3 (max.nn.Module) encoder in its forward, over tensors.

An encoder takes its batch in one of two layouts, which its class picks:

  • padded (the default): tokens and an attention_mask, both [batch_size, seq_len];
  • ragged, when it sets ragged_batch = True: tokens, input_row_offsets and return_n_logits, as a ragged decoder takes them but with no KV cache.

A registered encoder class can also set graph_name, the name its graph compiles under. A graph-API encoder can set strict_state_dict_loading, override_quantization_encoding and weight_alignment, the options it loads the checkpoint with, which an instance may also set from its config. A graph-API encoder whose graph predates registration with input types other than its layout’s defines legacy_input_types(), which returns them in field order, so its precompiled MEFs keep their key.

A ModuleV3 encoder is built under the pipeline’s dtype and moved to its device, and the checkpoint’s float32 and bfloat16 weights are cast to the dtypes its parameters declare.

Pipeline models​

EncoderPipelineModelServes a registered ENCODER module.
GraphApiEncoderPipelineModelServes a registered graph-API ENCODER module.
ModuleV3EncoderPipelineModelServes a registered ModuleV3 ENCODER module.
encoder_pipeline_modelReturns the pipeline model that serves an ENCODER registration.

Encoder inputs​

EncoderInputsThe inputs of an ENCODER module's __call__.
PaddedEncoderInputsThe prepared inputs of a padded ENCODER.
RaggedEncoderInputsThe prepared inputs of a ragged ENCODER.

Batch processors​

PaddedEncoderProcessorPads a batch of text for a registered padded ENCODER.
RaggedEncoderProcessorBatches ragged text for a registered ragged ENCODER.

Graph input types​

encoder_input_typesReturns an ENCODER graph's input types, keyed by field, in order.