Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deepspeed/inference/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ def validate_dtype(cls, field_value, values):
return field_value
raise TypeError(f"Invalid type for dtype: {type(field_value)}")

@field_validator("max_out_tokens")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Run pre-commit on every modified file

The commit records pre-commit run --files only for __init__.py and test_inference_import.py, but it also changes deepspeed/inference/config.py and test_inference_config.py. Run the required pre-commit command over all four modified files before merging.

AGENTS.md reference: AGENTS.md:L10-L10

Useful? React with 👍 / 👎.

def validate_max_out_tokens(cls, field_value, values):
if field_value <= 0:
raise ValueError(f"max_out_tokens must be a positive integer, got {field_value}")
return field_value

@field_validator("moe")
def moe_backward_compat(cls, field_value, values):
if isinstance(field_value, bool):
Expand Down
20 changes: 19 additions & 1 deletion deepspeed/ops/transformer/inference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@
# DeepSpeed Team

from .config import DeepSpeedInferenceConfig
from ....model_implementations.transformers.ds_transformer import DeepSpeedTransformerInference
from .moe_inference import DeepSpeedMoEInferenceConfig, DeepSpeedMoEInference

__all__ = [

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required Signed-off-by trailer

This non-merge commit has no Signed-off-by trailer in its commit metadata. Add the required sign-off using the configured author identity before merging.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

"DeepSpeedInferenceConfig",
"DeepSpeedMoEInferenceConfig",
"DeepSpeedMoEInference",
"DeepSpeedTransformerInference",
]


def __getattr__(name: str):
# Lazy import breaks the circular dependency between this package and
# `deepspeed.model_implementations.transformers.ds_transformer`, which
# imports `deepspeed.ops.transformer.inference.triton.*` at module load
# time when Triton is installed. Accessing the symbol on demand keeps the
# package import path acyclic.
if name == "DeepSpeedTransformerInference":
from ....model_implementations.transformers.ds_transformer import DeepSpeedTransformerInference
return DeepSpeedTransformerInference
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
24 changes: 24 additions & 0 deletions tests/unit/inference/test_inference_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,27 @@ def test_moe_backward_compat_bool(self):
config = DeepSpeedInferenceConfig(moe=value)
assert isinstance(config.moe, DeepSpeedMoEConfig)
assert config.moe.enabled == value


@pytest.mark.inference
class TestInferenceConfigValidation:
"""CPU-only validation tests for DeepSpeedInferenceConfig."""

def test_negative_max_out_tokens_rejected(self):
# Regression test for https://github.com/deepspeedai/DeepSpeed/issues/8339
from deepspeed.inference.config import DeepSpeedInferenceConfig

with pytest.raises(ValueError, match="max_out_tokens must be a positive integer"):
DeepSpeedInferenceConfig(max_out_tokens=-1)

def test_zero_max_out_tokens_rejected(self):
from deepspeed.inference.config import DeepSpeedInferenceConfig

with pytest.raises(ValueError, match="max_out_tokens must be a positive integer"):
DeepSpeedInferenceConfig(max_out_tokens=0)

def test_positive_max_out_tokens_accepted(self):
from deepspeed.inference.config import DeepSpeedInferenceConfig

config = DeepSpeedInferenceConfig(max_out_tokens=128)
assert config.max_out_tokens == 128
22 changes: 22 additions & 0 deletions tests/unit/inference/test_inference_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

import pytest


@pytest.mark.inference
class TestInferenceImport:
"""CPU-only tests for the public inference package import surface."""

def test_transformer_inference_is_lazy_imported(self):
# Regression test for https://github.com/deepspeedai/DeepSpeed/issues/7159
# Importing the inference package must not trigger a circular import even
# when Triton is installed, and the legacy public symbol must stay reachable.
from deepspeed.model_implementations.transformers.ds_transformer import (
DeepSpeedTransformerInference as DirectTransformerInference, )
from deepspeed.ops.transformer.inference import (
DeepSpeedTransformerInference as OpsTransformerInference, )

assert OpsTransformerInference is DirectTransformerInference
Loading