@@ -462,13 +462,13 @@ def max_seq_length(self) -> int:
462462 rsf = self .rope_scaling .factor
463463 return int ((self .base_max_seq_length or DEFAULT_MAX_SEQ_LENGTH ) * rsf )
464464
465- def generation_max_tokens_for (self , prompt_len : int ) -> int :
465+ def generation_max_tokens_for (self , prompt_len : int , multiplier : float | None = None ) -> int :
466466 """Per-sample ``max_tokens`` ceiling, prompt-aware.
467467
468468 Returns the smaller of:
469469
470- 1. ``int(max_tokens_per_example * GENERATION_MAX_TOKENS_SAFETY_MULTIPLIER )``
471- when the assembler stat is populated, else ``max_seq_length``.
470+ 1. ``int(max_tokens_per_example * multiplier )`` when the assembler stat
471+ is populated, else ``max_seq_length``.
472472 2. ``max_seq_length - prompt_len`` -- vLLM raises when
473473 ``len(prompt) + max_tokens > max_model_len``
474474 (`vllm#33418 <https://github.com/vllm-project/vllm/issues/33418>`_).
@@ -480,15 +480,29 @@ def generation_max_tokens_for(self, prompt_len: int) -> int:
480480 clamp is a defensive belt for legacy adapters where the assembler
481481 stat is missing and for prompts longer than those seen in training.
482482
483+ The default ``multiplier`` (``GENERATION_MAX_TOKENS_SAFETY_MULTIPLIER``)
484+ adds only a small jitter margin, which is enough for most tables but
485+ too tight for long, unbounded free-text columns: a model that
486+ over-generates slightly past the longest training example truncates
487+ mid-JSON and yields no parseable record. Callers wire the user-facing
488+ ``generation.max_tokens_multiplier`` knob through here to widen the
489+ budget (bounded by the context window) for such datasets.
490+
483491 Args:
484492 prompt_len: Tokenized length of the prompt this sample will
485493 run against. Pass ``0`` to disable the prompt clamp.
494+ multiplier: Margin applied to ``max_tokens_per_example``. Defaults
495+ to ``GENERATION_MAX_TOKENS_SAFETY_MULTIPLIER`` when ``None`` so
496+ non-generation callers (e.g. the training eval callback) keep
497+ the legacy sizing.
486498
487499 Returns:
488500 Non-negative ``max_tokens`` value safe to feed to ``SamplingParams``.
489501 """
502+ if multiplier is None :
503+ multiplier = GENERATION_MAX_TOKENS_SAFETY_MULTIPLIER
490504 if self .max_tokens_per_example and self .max_tokens_per_example > 0 :
491- sized = int (self .max_tokens_per_example * GENERATION_MAX_TOKENS_SAFETY_MULTIPLIER )
505+ sized = int (self .max_tokens_per_example * multiplier )
492506 else :
493507 sized = self .max_seq_length
494508 return max (0 , min (sized , self .max_seq_length - prompt_len ))
0 commit comments