diff --git a/deploy/sdk/src/dynamo/sdk/cli/build.py b/deploy/sdk/src/dynamo/sdk/cli/build.py index 6fe5d5a38a6..14e8c14a715 100644 --- a/deploy/sdk/src/dynamo/sdk/cli/build.py +++ b/deploy/sdk/src/dynamo/sdk/cli/build.py @@ -101,7 +101,7 @@ class ServiceConfig(BaseModel): service: str = "" # Fully qualified service name models: t.List[str] = Field(default_factory=list) dependencies: t.List[str] = Field(default_factory=list) - resource: t.Dict[str, t.Any] = Field(default_factory=dict) + resources: t.Dict[str, t.Any] = Field(default_factory=dict) workers: t.Optional[int] = None image: str = "dynamo:latest" dynamo: t.Dict[str, t.Any] = Field(default_factory=dict) @@ -138,7 +138,7 @@ def from_service(cls, service: ServiceInterface[T]) -> ServiceInfo: config = ServiceConfig( name=name, service="", - resource=service.config.resources.model_dump(), + resources=service.config.resources.model_dump(), workers=service.config.workers, image=image, dynamo=service.config.dynamo.model_dump(), @@ -212,7 +212,7 @@ def to_dict(self) -> t.Dict[str, t.Any]: "name": service["name"], "service": service["config"]["service"], "config": { - "resource": service["config"]["resource"], + "resources": service["config"]["resources"], "workers": service["config"]["workers"], "image": service["config"]["image"], "dynamo": service["config"]["dynamo"], diff --git a/deploy/sdk/src/dynamo/sdk/core/protocol/interface.py b/deploy/sdk/src/dynamo/sdk/core/protocol/interface.py index 857ce6e157c..bad1204e803 100644 --- a/deploy/sdk/src/dynamo/sdk/core/protocol/interface.py +++ b/deploy/sdk/src/dynamo/sdk/core/protocol/interface.py @@ -17,10 +17,10 @@ from abc import ABC, abstractmethod from collections import defaultdict from enum import Enum, auto -from typing import Any, Dict, Generic, List, Optional, Set, Tuple, Type, TypeVar, Union +from typing import Any, Dict, Generic, List, Optional, Set, Tuple, Type, TypeVar from fastapi import FastAPI -from pydantic import BaseModel, Field, field_validator +from pydantic import BaseModel, ConfigDict, Field from dynamo.sdk.core.protocol.deployment import Env @@ -59,16 +59,13 @@ class DynamoTransport(Enum): class ResourceConfig(BaseModel): """Configuration for Dynamo resources""" + # auto convert gpu and cpu values to string from int + model_config = ConfigDict(coerce_numbers_to_str=True) + cpu: str = Field(default="1") memory: str = Field(default="500Mi") gpu: str = Field(default="0") - @field_validator("gpu", mode="before") - @classmethod - def convert_gpu_to_string(cls, v: Union[str, int]) -> str: - """Convert gpu value to string if it's an integer""" - return str(v) - class ServiceConfig(BaseModel): """Base service configuration that can be extended by adapters""" diff --git a/examples/hello_world/hello_world.py b/examples/hello_world/hello_world.py index b219069738c..3e58f2c52e7 100644 --- a/examples/hello_world/hello_world.py +++ b/examples/hello_world/hello_world.py @@ -67,7 +67,7 @@ class ResponseType(BaseModel): dynamo={ "namespace": "inference", }, - resource={"cpu": 1, "memory": "500Mi"}, + resources={"cpu": 1, "memory": "500Mi"}, workers=2, image=DYNAMO_IMAGE, )