core.inference.text_generation_server.dynamic_text_gen_server.endpoints.common#
Module Contents#
Functions#
Use the engine’s termination cause, including stops at the token budget. |
|
Tell the coordinator to stop generating the given requests. |
|
Return an error message if client-supplied |
|
Fold one reply’s |
|
Merge the stager’s response metadata into the top-level response body. |
|
Broadcasts a message to perform a generation to all tensor parallel ranks. |
|
Set |
|
Resolve one sampling default: app config > generation_config > hardcoded. |
|
Sampling defaults declared by the model’s |
|
Log the resolved sampling defaults once per process. |
|
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,
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_paramsare 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 thedictcheck 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_metadatainto 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
responseare 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 whenvaluewas actually provided.Startup passes
default_temperature/default_top_p/default_top_kthrough asOptional,Nonewhen the operator didn’t configure one. Setting the key unconditionally (even to a hardcoded fallback like1.0) would makeresolve_sampling_default’sconfig_key in app_configcheck always true, permanently hiding the model’s owngeneration_config.jsontier 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:
an explicitly configured server default (
config_keypresent in the app config) – an operator who set it should not be overridden by a model file;the model’s own
generation_config.jsondeclaration;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) ingeneration_config.json, and vLLM applies them when a request omits the field. These endpoints did not consult that file, so a client that omittedtop_pgot 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.jsonwas 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,
Assign stable distinct seeds to choices without mutating shared parameters.