core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common#

Module Contents#

Functions#

generation_finish_reason

Use the engine’s termination cause, including stops at the token budget.

abort_requests

Tell the coordinator to stop generating the given requests.

validate_offload_params

Return an error message if client-supplied offload_params are malformed, else None.

collect_stage_metadata

Fold one reply’s payload_stage_metadata into the response-level dict.

attach_stage_metadata

Merge the stager’s response metadata into the top-level response body.

send_do_generate

Broadcasts a message to perform a generation to all tensor parallel ranks.

apply_optional_sampling_default

Set app_config[config_key] only when value was actually provided.

resolve_sampling_default

Resolve one sampling default: app config > generation_config > hardcoded.

generation_config_sampling_defaults

Sampling defaults declared by the model’s generation_config.json.

log_sampling_defaults_once

Log the resolved sampling defaults once per process.

sampling_params_for_choice

Assign stable distinct seeds to choices without mutating shared parameters.

Data#

API#

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.GENERATE_NUM#

0

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.LOCK#

‘Lock(…)’

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.logger#

‘getLogger(…)’

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.generation_finish_reason(result: dict) → str#

Use the engine’s termination cause, including stops at the token budget.

The length fallback supports replies from engines predating finish metadata.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.abort_requests(
client: megatron.core.inference.inference_client.InferenceClient,
request_ids: Iterable[int],
reason: str,
) → None#

Tell the coordinator to stop generating the given requests.

Best-effort and never raises: it runs on paths that are already unwinding (a cancelled handler, or an error response), where letting a second failure escape would replace the real one. A request that has already finished is not an error to abort – abort_request returns without recording an id it no longer holds local state for.

Parameters:
  • client – The InferenceClient the requests were submitted through.

  • request_ids – Ids from add_request_with_id.

  • reason – Logged so the abort can be told apart from a normal completion.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.validate_offload_params(offload_params) → Optional[str]#

Return an error message if client-supplied offload_params are malformed, else None.

Top-level keys starting with _ are engine-owned control fields (for example the prompt-preparation error the engine stamps on MP rank 0), so a client is not allowed to supply them. Called on the raw request value, so the dict check lives here too.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.collect_stage_metadata(response_metadata: dict, result: dict) → None#

Fold one reply’s payload_stage_metadata into the response-level dict.

Every request in a batch goes through the same stager, so a key that already exists must carry the same value; a mismatch means the stager returned per-request metadata that cannot be represented once at the top level.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.attach_stage_metadata(response: dict, response_metadata: dict) → dict#

Merge the stager’s response metadata into the top-level response body.

The OpenAI-shaped fields already in response are reserved; a stager key that collides with one is a bug rather than something to overwrite silently.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.send_do_generate()#

Broadcasts a message to perform a generation to all tensor parallel ranks.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.apply_optional_sampling_default(app_config, config_key, value) → None#

Set app_config[config_key] only when value was actually provided.

Startup passes default_temperature/default_top_p/default_top_k through as Optional, None when the operator didn’t configure one. Setting the key unconditionally (even to a hardcoded fallback like 1.0) would make resolve_sampling_default’s config_key in app_config check always true, permanently hiding the model’s own generation_config.json tier behind a value nobody actually asked for.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.resolve_sampling_default(
app_config,
gen_defaults,
key,
config_key,
hardcoded,
)#

Resolve one sampling default: app config > generation_config > hardcoded.

Precedence for a field the request omits:

  1. an explicitly configured server default (config_key present in the app config) – an operator who set it should not be overridden by a model file;

  2. the model’s own generation_config.json declaration;

  3. the previous hardcoded fallback, so a model without a generation_config and a server without configured defaults behave exactly as before.

Key presence is what distinguishes “operator set 1.0” from “unset”, so .get(config_key, default) is deliberately not used here.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.generation_config_sampling_defaults(tokenizer)#

Sampling defaults declared by the model’s generation_config.json.

HF models ship sampling defaults (temperature, top_p, top_k, do_sample) in generation_config.json, and vLLM applies them when a request omits the field. These endpoints did not consult that file, so a client that omitted top_p got 1.0 here but the model-declared value (e.g. 0.95) under vLLM – a silent per-engine difference in the sampling tail.

Returns a dict with only the keys the config actually declares, so callers can fall back to their own defaults for the rest. Request values always win; this only supplies defaults.

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common._LOGGED_SAMPLING_DEFAULTS#

False

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.log_sampling_defaults_once(tokenizer, resolved)#

Log the resolved sampling defaults once per process.

Mirrors the startup log for the EOS token set: it makes it possible to confirm from the server log that generation_config.json was found and applied, rather than inferring it from sampled output (which is hopeless on peaked distributions, where top_p barely truncates).

core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common.sampling_params_for_choice(
params: megatron.core.inference.sampling_params.SamplingParams,
index: int,
) → megatron.core.inference.sampling_params.SamplingParams#

Assign stable distinct seeds to choices without mutating shared parameters.