hsml.deployment #
Deployment #
NOT_FOUND_ERROR_CODE class-attribute instance-attribute #
NOT_FOUND_ERROR_CODE = 240000
Metadata object representing a deployment in Model Serving.
api_protocol property writable #
API protocol enabled in the deployment (e.g., HTTP or GRPC).
artifact_files_path property #
Path of the artifact files deployed by the predictor.
artifact_path property #
Path of the model artifact deployed by the predictor.
Deprecated
Artifact versions are deprecated in favor of deployment versions.
artifact_version property writable #
Artifact version deployed by the predictor.
Deprecated
Artifact versions are deprecated in favor of deployment versions.
config_file property writable #
Model server configuration file passed to the model deployment.
It can be accessed via CONFIG_FILE_PATH environment variable from a predictor or transformer script. For LLM deployments without a predictor script, this file is used to configure the vLLM engine.
created_at property #
Created at date of the predictor.
creator property #
Creator of the predictor.
description property writable #
Description of the deployment.
env_vars property writable #
Environment variables of the predictor.
environment property writable #
Name of inference environment.
feature_view_name property #
feature_view_name: str | None
Name of the feature view served by a feature view deployment.
feature_view_version property #
feature_view_version: int | None
Version of the feature view served by a feature view deployment.
has_feature_view property #
has_feature_view: bool
Whether this deployment serves a feature view without a model.
has_model property #
Whether the deployment has a model associated.
id property #
Id of the deployment.
inference_batcher property writable #
Configuration of the inference batcher attached to this predictor.
inference_logger property writable #
Configuration of the inference logger attached to this predictor.
knative_mode property writable #
Whether the deployment runs in KServe Knative mode.
True selects Knative mode, False selects Standard mode and None lets the backend decide on creation or keeps the stored mode on an update. See Predictor.knative_mode for the full mode semantics.
Adds Knative mode selection, ~=5.1.0
Deployments can now select between KServe Knative and Standard mode.
missing_mandatory_tags property #
Mandatory tags configured for deployments that this deployment is missing.
Populated from the backend response. Empty when all mandatory deployment tags are set.
model_name property writable #
Name of the model deployed by the predictor.
model_path property writable #
Model path deployed by the predictor.
model_registry_id property writable #
Model Registry Id of the deployment.
model_server property writable #
Model server ran by the predictor.
model_version property writable #
Model version deployed by the predictor.
name property writable #
Name of the deployment.
predictor property writable #
Predictor used in the deployment.
project_name property writable #
Name of the project the deployment belongs to.
project_namespace property writable #
Name of the Kubernetes namespace the project is in.
requested_instances property #
Total number of requested instances in the deployment.
resources property writable #
Resource configuration for the predictor.
scaling_configuration property writable #
Scaling configuration for the deployment.
schema property writable #
Deployment schema, or None; see Predictor.schema.
script_file property writable #
Script file used by the predictor.
serving_tool property writable #
Serving tool used to run the model server.
tracing property writable #
Tracing configuration attached to this deployment.
training_dataset_version property #
training_dataset_version: int | None
Training dataset version whose statistics the deployment's transformations use.
transformer property writable #
Transformer configured in the predictor.
version property #
Version of the deployment.
add_tag #
Attach a tag to a deployment.
A tag consists of a
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the tag to be added. TYPE: |
value | Value of the tag to be added. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | in case the backend fails to add the tag. |
create_feature_monitoring #
create_feature_monitoring(
name: str,
description: str | None = None,
start_date_time: int | str | None = None,
end_date_time: int | str | None = None,
cron_expression: str | None = "0 0 12 ? * * *",
) -> Any
Create a feature monitoring config on the logging feature group of a feature view deployment.
Model deployments use create_model_monitoring() instead. Finish the returned builder with a detection window, a reference window or value, a comparison, and save().
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the feature monitoring configuration. TYPE: |
description | Description of the feature monitoring configuration. TYPE: |
start_date_time | Start date and time from which to start computing statistics. |
end_date_time | End date and time at which to stop computing statistics. |
cron_expression | Cron expression scheduling the job (UTC, Quartz). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Any | A |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.ModelServingException | If this is a model deployment, or the feature view has no logging enabled. |
create_model_monitoring #
create_model_monitoring(
name: str,
description: str | None = None,
start_date_time: int | str | None = None,
end_date_time: int | str | None = None,
cron_expression: str | None = "0 0 12 ? * * *",
) -> FeatureMonitoringConfig
Create a model monitoring config bound to this deployment's model.
Resolves the model's parent feature view from the registered provenance and delegates to feature_view.create_model_monitoring with this deployment's model_name and model_version already filled in. The resulting config targets the FV's logging feature group, filters by this model+version, and defaults the reference training dataset to the version that was used to train the model.
Experimental
Public API is subject to change, this feature is not suitable for production use-cases.
Example
my_deployment = ms.get_deployment(name="my_deployment")
my_deployment.create_model_monitoring(
name="psi_drift",
).with_detection_window(
time_offset="1d", window_length="1d",
).with_reference_training_dataset( # defaults to model's TD version
).compare_on_distribution(
feature_name="amount", metric="PSI", threshold=0.2,
).save()
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the feature monitoring configuration. TYPE: |
description | Description of the feature monitoring configuration. TYPE: |
start_date_time | Start date and time from which to start computing statistics. |
end_date_time | End date and time at which to stop computing statistics. |
cron_expression | Cron expression scheduling the FM job (UTC, Quartz). TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.ModelServingException | If the deployment's model has no parent feature view recorded in its provenance. |
| RETURNS | DESCRIPTION |
|---|---|
FeatureMonitoringConfig | A |
FeatureMonitoringConfig |
|
FeatureMonitoringConfig |
|
delete #
delete(force: bool = False)
Delete the deployment.
| PARAMETER | DESCRIPTION |
|---|---|
force | Force the deletion of the deployment. If the deployment is running, it will be stopped and deleted automatically. TYPE: |
Warning
A call to this method does not ask for a second confirmation.
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
delete_tag #
delete_tag(name: str)
Delete a tag attached to a deployment.
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the tag to be removed. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | in case the backend fails to delete the tag. |
download_artifact_files #
download_artifact_files(local_path: str | None = None)
Download the artifact files served by the deployment.
| PARAMETER | DESCRIPTION |
|---|---|
local_path | Path where to download the artifact files in the local filesystem. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
download_logs #
Download the archived logs of this deployment from HopsFS.
Each running instance archives its own output to the project's Logs dataset without being asked: the container copies its log to Logs/Serving/<deployment_name>/ when it exits, is restarted, or is stopped, so a pod removed by scale-to-zero still leaves its output behind. Files are named <UTC yyyyMMdd-HHmmss>_<pod>_<component>.log, one per instance run.
Downloading the most recent archives
local_paths = deployment.download_logs(latest=True)
for local_path in local_paths:
print(open(local_path).read())
| PARAMETER | DESCRIPTION |
|---|---|
path | Local directory to download the archives into; the current working directory is used when unset. TYPE: |
latest | Download only the most recent archives instead of all of them. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list[str] | The local paths of the downloaded archive files. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.ModelServingException | If |
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
get_endpoint_url #
get_endpoint_url() -> str | None
Get the base endpoint URL for this deployment.
Returns the base URL that can be used with external HTTP clients. This is the path-based routing base endpoint without any protocol-specific suffixes like :predict or /v1.
If Istio client is not available, returns None.
| RETURNS | DESCRIPTION |
|---|---|
str | None | Base endpoint URL, or |
Examples:
deployment = ms.get_deployment("my_deployment")
url = deployment.get_endpoint_url()
# url = "https://host:port/v1/project/name"
get_feature_view #
Retrieve the feature view this deployment serves, or None.
A feature view deployment names its view in the deployment env vars; a model deployment resolves it through the model's provenance.
| PARAMETER | DESCRIPTION |
|---|---|
init | Whether to initialise the view for serving with the deployment's training dataset version. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Any | The feature view, or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.FeatureStoreException | If no project connection is available to reach the feature store. |
get_inference_url #
get_inference_url() -> str | None
Get the KServe inference URL for standard model deployments.
Returns the full URL with :predict suffix for KServe inference protocol. This method only returns a URL for standard model deployments (non-vLLM, with a model attached).
If Istio client is not available, falls back to Hopsworks REST API path.
| RETURNS | DESCRIPTION |
|---|---|
str | None | Inference URL with |
Examples:
deployment = ms.get_deployment("my_deployment")
url = deployment.get_inference_url()
# Use with any HTTP client
import requests
response = requests.post(url, json={"instances": [[1, 2, 3]]})
get_logs #
Prints the deployment logs of the predictor or transformer.
Only the live pods of a running deployment are read. Logs of a stopped deployment are whatever was saved to HopsFS beforehand, retrieved with meth:
download_logs or the "Log history" section in the UI.
.. note:: Legacy: this method prints to stdout and returns None. New code (and any agent / scripted use) should call meth:
read_logs for a string return value or meth:
tail_logs for incremental streaming.
| PARAMETER | DESCRIPTION |
|---|---|
component | Deployment component to get the logs from (e.g., predictor or transformer). TYPE: |
tail | Number of most recent lines to retrieve from the logs. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
get_model #
get_model()
Retrieve the metadata object for the model being used by this deployment, or None when it has no model.
get_monitoring_configs #
get_monitoring_configs() -> list[FeatureMonitoringConfig]
Get the feature monitoring configurations for the model deployed by this deployment.
For a model deployment these are the configs filtered by the model version; for a feature view deployment the configs on the feature view's logging feature group. Delegates to the underlying model's get_monitoring_configs method.
Example
import hopsworks
project = hopsworks.login()
ms = project.get_model_serving()
my_deployment = ms.get_deployment("my_deployment")
fm_configs = my_deployment.get_monitoring_configs()
| RETURNS | DESCRIPTION |
|---|---|
list[FeatureMonitoringConfig] | List of |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
get_openai_url #
get_openai_url() -> str | None
Get the OpenAI-compatible API URL for vLLM deployments.
Returns the URL for OpenAI-compatible API endpoints (e.g., /v1/chat/completions). This method only returns a URL for LLM (vLLM) deployments.
| RETURNS | DESCRIPTION |
|---|---|
str | None | OpenAI-compatible URL (base URL + "/v1"), or |
Examples:
deployment = ms.get_deployment("my_llm_deployment")
url = deployment.get_openai_url()
# url = "https://host:port/v1/project/name/v1"
# Then use: url + "/chat/completions"
get_state #
get_state() -> PredictorState
Get the current state of the deployment.
| RETURNS | DESCRIPTION |
|---|---|
PredictorState | The state of the deployment. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
get_tag #
Get the value of a tag attached to a deployment.
| PARAMETER | DESCRIPTION |
|---|---|
name | Name of the tag to get. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Any | None | tag value, or |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | in case the backend fails to retrieve the tag. |
get_tags #
Retrieve all tags attached to a deployment.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any] | Dictionary of tag name/values. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | in case the backend fails to retrieve the tags. |
is_created #
is_created() -> bool
Check whether the deployment is created.
| RETURNS | DESCRIPTION |
|---|---|
bool | Whether the deployment is created or not. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
is_running #
Check whether the deployment is ready to handle inference requests.
| PARAMETER | DESCRIPTION |
|---|---|
or_idle | Whether the idle state is considered as running (default is True). TYPE: |
or_updating | Whether the updating state is considered as running (default is True). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bool | Whether the deployment is ready or not. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
is_stopped #
Check whether the deployment is stopped.
| PARAMETER | DESCRIPTION |
|---|---|
or_created | Whether the creating and created state is considered as stopped (default is True). TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
bool | Whether the deployment is stopped or not. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
predict #
predict(
data: dict | InferInput = None,
inputs: list | dict = None,
validate: bool = True,
) -> dict
Send inference requests to the deployment.
One of data or inputs parameters must be set. Setting both raises ModelServingException. When the deployment has a schema and the protocol is REST, the rows are encoded and validated against it before the request is sent; the pod validates again regardless.
| PARAMETER | DESCRIPTION |
|---|---|
data | Payload dictionary for the inference request including the model input(s). TYPE: |
inputs | Model inputs used in the inference requests. |
validate | Whether to validate the rows against TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
dict | Inference response. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
Examples:
# login into Hopsworks using hopsworks.login()
# get Hopsworks Model Serving handle
ms = project.get_model_serving()
# retrieve deployment by name
my_deployment = ms.get_deployment("my_deployment")
# (optional) retrieve model input example
my_model = project.get_model_registry() .get_model(my_deployment.model_name, my_deployment.model_version)
# make predictions using model inputs (single or batch)
predictions = my_deployment.predict(inputs=my_model.input_example)
# or using more sophisticated inference request payloads
data = { "instances": [ my_model.input_example ], "key2": "value2" }
predictions = my_deployment.predict(data)
read_logs #
read_logs(
component: str = "predictor",
tail: int = 100,
source: str = "kubernetes",
since: str | None = None,
until: str | None = None,
pod: str | None = None,
) -> str
Return deployment logs as a single plain-text string.
Programmatic counterpart to meth:
get_logs. Suitable for agents and scripts: never prints, never short-circuits on deployment state. The default source="kubernetes" reads the live pods only; logs of a stopped deployment are whatever was saved beforehand and are archived to HopsFS and retrieved with meth:
download_logs or the "Log history" section in the UI.
| PARAMETER | DESCRIPTION |
|---|---|
component |
TYPE: |
tail | Most-recent lines to retrieve. Capped server-side. TYPE: |
source |
TYPE: |
since | ISO-8601 lower bound on log timestamp. Ignored on the Kubernetes path. TYPE: |
until | ISO-8601 upper bound on log timestamp. Ignored on the Kubernetes path. TYPE: |
pod | Restrict to one instance / container name. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
str | The joined logs as plain text. Empty string when there are no |
str | matching lines; |
str | multiple instances are present. |
reinfer_schema #
reinfer_schema() -> DeploymentSchema
Re-infer the deployment schema from the current feature view and mark it pending.
Use after enabling logging or changing the view; save() then publishes the new schema as a new revision. Passed features are kept.
Example
feature_view.enable_logging(extra_log_columns={"channel": "string"})
deployment = ms.get_deployment("fraud")
deployment.reinfer_schema() # `channel` becomes an optional request field
deployment.save() # publishes the schema as a new revision
| RETURNS | DESCRIPTION |
|---|---|
DeploymentSchema | The re-inferred schema, also set on the deployment. |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.ModelServingException | If the deployment is not served by the default predictor and has no schema to refine. |
restart #
Restart the deployment so it picks up the latest code and environment state.
If the deployment is already stopped, it is started in place.
| PARAMETER | DESCRIPTION |
|---|---|
await_stopped | Awaiting time (seconds) for the deployment to stop. TYPE: |
await_running | Awaiting time (seconds) for the deployment to start again. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
save #
save(await_update: int | None = 600)
Persist this deployment including the predictor and metadata to Model Serving.
| PARAMETER | DESCRIPTION |
|---|---|
await_update | If the deployment is running, awaiting time (seconds) for the running instances to be updated. If the running instances are not updated within this timespan, the call to this method returns while the update in the background. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
start #
start(await_running: int | None = 600)
Start the deployment.
| PARAMETER | DESCRIPTION |
|---|---|
await_running | Awaiting time (seconds) for the deployment to start. If the deployment has not started within this timespan, the call to this method returns while it deploys in the background. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
stop #
stop(await_stopped: int | None = 600)
Stop the deployment.
| PARAMETER | DESCRIPTION |
|---|---|
await_stopped | Awaiting time (seconds) for the deployment to stop. If the deployment has not stopped within this timespan, the call to this method returns while it stopping in the background. TYPE: |
| RAISES | DESCRIPTION |
|---|---|
hopsworks.client.exceptions.RestAPIError | In case the backend encounters an issue. |
tail_logs #
tail_logs(
component: str = "predictor",
interval: float = 2.0,
source: str = "kubernetes",
since: str | None = "now",
timeout: float | None = None,
stop_on_status: str | None = None,
pod: str | None = None,
) -> Iterator[str]
Yield only newly observed log chunks as plain text.
Client-side polling, not server-streaming: each tick calls meth:
read_logs with a moving cursor and yields the portion not already seen. The Kubernetes path dedups per pod by overlapping the previous and current tail windows; the OpenSearch path (old backends) uses the timestamp + doc_id pair. Only the live pods are followed; the archived logs of a stopped deployment are retrieved with meth:
download_logs.
Following a deployment's live logs
for chunk in deployment.tail_logs(timeout=120):
print(chunk, end="")
| PARAMETER | DESCRIPTION |
|---|---|
component |
TYPE: |
interval | Seconds between polls. TYPE: |
source |
TYPE: |
since |
TYPE: |
timeout | Stop after this many seconds. TYPE: |
stop_on_status | Stop when TYPE: |
pod | Follow one specific instance by name. The backend reads the first eight replicas of a component per request, so a deployment scaled beyond that needs the later instances tailed one by one. TYPE: |
| YIELDS | DESCRIPTION |
|---|---|
str | Plain-text log chunks containing only newly observed content. |