Skip to content

Commit

Permalink
Improve typing and reuse variable for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dudeperf3ct committed Jan 16, 2024
1 parent 466f638 commit b7aa875
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
16 changes: 11 additions & 5 deletions zencoder/huggingface/hf_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@
from typing import Tuple, Optional
from zenml.services import ServiceType, ServiceState
from zenml.services.service import BaseDeploymentService
from huggingface_hub import InferenceClient, InferenceEndpointError
from huggingface_hub import (
InferenceClient,
InferenceEndpointError,
InferenceEndpoint,
)

logger = get_logger(__name__)


class HuggingFaceModelService(BaseDeploymentService):
"""HuggingFace model deployment service."""

SERVICE_TYPE = ServiceType(
name="hf-endpoint-deployment",
type="model-serving",
flavor="hfendpoint",
description="Huggingface inference endpoint service",
)

def __init__(self, endpoint):
"""_summary_
def __init__(self, endpoint: InferenceEndpoint):
"""_summary_.
Args:
endpoint (_type_): _description_
endpoint (InferenceEndpoint): _description_
"""
self.endpoint = endpoint

def wait_for_startup(self, timeout=300) -> bool:
def wait_for_startup(self, timeout: int = 300) -> bool:
"""_summary_
Args:
Expand Down
14 changes: 11 additions & 3 deletions zencoder/huggingface/hf_model_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,32 @@
from zenml.services import BaseService, ServiceConfig
from huggingface_hub import create_inference_endpoint
from huggingface.hf_deployment import HuggingFaceModelService
from zenml.model_deployers.base_model_deployer import BaseModelDeployerFlavor
from zenml.model_deployers.base_model_deployer import (
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT,
BaseModelDeployerFlavor,
)

logger = get_logger(__name__)


class HFEndpointModelDeployer(BaseModelDeployer):
"""Huggingface endpoint model deployer."""

NAME: ClassVar[str] = "HFEndpoint"
FLAVOR: ClassVar[Type[BaseModelDeployerFlavor]] = HFModelDeployerFlavor

def deploy_model(
self, config: ServiceConfig, replace: bool = False, timeout: int = 300
self,
config: ServiceConfig,
replace: bool = False,
timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT,
) -> BaseService:
"""_summary_.
Args:
config (ServiceConfig): _description_
replace (bool, optional): _description_. Defaults to False.
timeout (int, optional): _description_. Defaults to 300.
timeout (int, optional): _description_. Defaults to DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT.
Raises:
ValueError: _description_
Expand Down
4 changes: 2 additions & 2 deletions zencoder/huggingface/hf_model_deployer_flavor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class HFInferenceEndpointConfig(BaseModelDeployerConfig):


class HFModelDeployerFlavor(BaseModelDeployerFlavor):
"""Seldon Core model deployer flavor."""
"""Huggingface Endpoint model deployer flavor."""

@property
def name(self) -> str:
Expand All @@ -35,7 +35,7 @@ def name(self) -> str:

@property
def config_class(self):
"""Returns `SeldonModelDeployerConfig` config class.
"""Returns `HFInferenceEndpointConfig` config class.
Returns:
The config class.
Expand Down

0 comments on commit b7aa875

Please sign in to comment.