Skip to main content

Python class

SamplingParamsGenerationConfigDefaults

SamplingParamsGenerationConfigDefaults

class max.interfaces.SamplingParamsGenerationConfigDefaults(temperature=None, top_p=None, top_k=None, repetition_penalty=None, max_new_tokens=None, min_new_tokens=None, do_sample=None, eos_token_id=None)

source

Bases: object

Default sampling parameter values extracted from a model’s GenerationConfig.

This class encapsulates sampling parameter defaults that come from a HuggingFace model’s GenerationConfig. These defaults have middle priority when creating SamplingParams instances:

Priority order (highest to lowest):

  1. User-provided values (SamplingParamsInput)
  2. Model’s GenerationConfig values (this class)
  3. SamplingParams class defaults

All fields default to None, indicating that the model’s GenerationConfig does not explicitly set that parameter. When None, SamplingParams will fall back to its own class defaults.

defaults = SamplingParamsGenerationConfigDefaults(
    temperature=0.7,
    top_k=50,
    max_new_tokens=512,
)
params = SamplingParams.from_input_and_generation_config(
    SamplingParamsInput(),
    sampling_params_defaults=defaults,
)

Parameters:

  • temperature (float | None)
  • top_p (float | None)
  • top_k (int | None)
  • repetition_penalty (float | None)
  • max_new_tokens (int | None)
  • min_new_tokens (int | None)
  • do_sample (bool | None)
  • eos_token_id (int | list[int] | None)

do_sample

do_sample: bool | None = None

source

If False, uses greedy sampling.

eos_token_id

eos_token_id: int | list[int] | None = None

source

EOS token ID from the model’s GenerationConfig, if explicitly set.

max_new_tokens

max_new_tokens: int | None = None

source

Maximum number of new tokens from the model’s GenerationConfig, if explicitly set.

min_new_tokens

min_new_tokens: int | None = None

source

Minimum number of new tokens from the model’s GenerationConfig, if explicitly set.

repetition_penalty

repetition_penalty: float | None = None

source

Repetition penalty value from the model’s GenerationConfig, if explicitly set.

temperature

temperature: float | None = None

source

Temperature value from the model’s GenerationConfig, if explicitly set.

top_k

top_k: int | None = None

source

Top-k sampling value from the model’s GenerationConfig, if explicitly set.

top_p

top_p: float | None = None

source

Top-p (nucleus sampling) value from the model’s GenerationConfig, if explicitly set.

values_to_update

property values_to_update: dict[str, float | int | list[int]]

source

Non-None field values as a dictionary.

Returns:

A dictionary mapping field names to their values, excluding any fields that are None. This dictionary can be used to update SamplingParams default values.

defaults = SamplingParamsGenerationConfigDefaults(
    temperature=0.7,
    top_k=50,
)
defaults.values_to_update