Skip to content

fix(inference): reject non-positive max_out_tokens at config validation - #8454

Open
chakshu-dhannawat wants to merge 1 commit into
deepspeedai:masterfrom
chakshu-dhannawat:fix/max-out-tokens-positive-validation
Open

fix(inference): reject non-positive max_out_tokens at config validation#8454
chakshu-dhannawat wants to merge 1 commit into
deepspeedai:masterfrom
chakshu-dhannawat:fix/max-out-tokens-positive-validation

Conversation

@chakshu-dhannawat

@chakshu-dhannawat chakshu-dhannawat commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #8339

DeepSpeed currently accepts a negative (or zero) value for max_out_tokens during inference config parsing. The failure only surfaces later at generation time with a confusing "Input with size N exceeds maximum length of -1" message.

This PR adds a small pydantic field validator on max_out_tokens so that non-positive values raise a clear ValueError when the config is constructed.

Changes:

  • deepspeed/inference/config.py: add validate_max_out_tokens field validator.
  • tests/unit/inference/test_inference_config.py: add CPU-only regression tests for -1, 0, and positive values.

Verified:

  • CUDA_VISIBLE_DEVICES="" python -m pytest tests/unit/inference/test_inference_config.py -m inference -k TestInferenceConfigValidation -v passes (3/3).
  • pre-commit run --files deepspeed/inference/config.py tests/unit/inference/test_inference_config.py passes (yapf, flake8, license, codespell, check-torchdist, etc.).

Values <= 0 for max_out_tokens were accepted during config parsing and only failed at generation time with a confusing 'input size exceeds maximum length of -1' error. Add a field validator so DeepSpeedInferenceConfig raises a clear ValueError immediately.

Signed-off-by: Chakshu Dhannawat <chakshu.dhannawat1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DeepSpeed accepts negative max_out_tokens and fails generation requests at runtime

1 participant