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

EOSTracker

EOSTracker​

class max.pipelines.context.EOSTracker(*, eos_token_ids=<factory>, eos_sequences=<factory>, eos_stop_strings=<factory>)

source

Bases: BaseModel

Centralized EOS tracking: single-ID, sequence-ID, and stop-sequence checks.

Used by Context and sampling to decide when generation stops and which token IDs to mask during min_tokens. Built once (e.g. by tokenizer from request params) and passed into context, so eos fields are immutable; Server and Context both use this type.

Three kinds of checks:

  1. EOS Single ID: token in eos_token_ids
  2. EOS Sequence ID: suffix of generated_tokens matches any eos_sequences
  3. EOS String Stop Sequence: decoded text contains a stop string.

Parameters:

eos_sequences​

eos_sequences: Sequence[Sequence[int]]

source

eos_stop_strings​

eos_stop_strings: Sequence[str]

source

eos_token_ids​

eos_token_ids: set[int]

source

is_eos_from_string()​

is_eos_from_string(next_token_decoded)

source

Register an incremental decoded str into the continuation buffer.

If a stop sequence is detected, return the matched sequence. Else, return None.

Parameters:

next_token_decoded (str)

Return type:

str | None

is_eos_from_tokens()​

is_eos_from_tokens(generated_tokens)

source

Checks for end-of-sequence conditions.

This function performs two checks:

  1. Whether the newly generated token is in the set of eos_token_ids.
  2. Whether appending the new token results in a sequence that matches any per-request stop sequence. Note: If called with a span of multiple newly generated tokens, EOS occurring before the final token in that span may not be detected by this method.

Parameters:

generated_tokens (ndarray[tuple[Any, ...], dtype[int64]])

Return type:

bool

model_config​

model_config: ClassVar[ConfigDict] = {}

source

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init()​

model_post_init(_EOSTracker__context)

source

Post-initialization hook to set the maximum stop length and continuation tail.

Parameters:

_EOSTracker__context (Any)

Return type:

None