Skip to content

hsml.model_registry #

ModelRegistry #

project_name property #

Name of the project the registry is connected to.

project_path property #

Path of the project the registry is connected to.

project_id property #

Id of the project the registry is connected to.

shared_registry_project_name property #

Name of the project the shared model registry originates from.

model_registry_id property #

Id of the model registry.

tensorflow property #

Module for exporting a TensorFlow model.

sklearn property #

Module for exporting a sklearn model.

torch property #

Module for exporting a torch model.

python property #

Module for exporting a generic Python model.

llm property #

Module for exporting a Large Language Model.

get_model #

get_model(
    name: str, version: int | None = None
) -> model.Model | None

Get a model entity from the model registry.

Getting a model from the Model Registry means getting its metadata handle so you can subsequently download the model directory.

PARAMETER DESCRIPTION
name

Name of the model to get.

TYPE: str

version

Version of the model to retrieve, defaults to None and will return the version=1.

TYPE: int | None DEFAULT: None

RETURNS DESCRIPTION
model.Model | None

The model metadata object or None if it does not exist.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If unable to retrieve model from the model registry.

get_models #

get_models(name: str) -> list[model.Model]

Get all model entities from the model registry for a specified name.

Getting all models from the Model Registry for a given name returns a list of model entities, one for each version registered under the specified model name.

PARAMETER DESCRIPTION
name

Name of the model to get.

TYPE: str

RETURNS DESCRIPTION
list[model.Model]

A list of model metadata objects.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If unable to retrieve model versions from the model registry.

get_best_model #

get_best_model(
    name: str, metric: str, direction: str
) -> model.Model | None

Get the best performing model entity from the model registry.

Getting the best performing model from the Model Registry means specifying in addition to the name, also a metric name corresponding to one of the keys in the training_metrics dict of the model and a direction. For example, to get the model version with the highest accuracy, specify metric='accuracy' and direction='max'.

PARAMETER DESCRIPTION
name

Name of the model to get.

TYPE: str

metric

Name of the key in the training metrics field to compare.

TYPE: str

direction

'max' to get the model entity with the highest value of the set metric, or 'min' for the lowest.

TYPE: str

RETURNS DESCRIPTION
model.Model | None

The model metadata object or None if it does not exist.

RAISES DESCRIPTION
hopsworks.client.exceptions.RestAPIError

If unable to retrieve model from the model registry.

hf_download #

hf_download(
    hugging_face_model_id: str,
    hf_token: str | None = None,
    selected_formats: list[str] | None = None,
    selected_variants: list[str] | None = None,
    selected_filenames: list[str] | None = None,
    timeout: int = 36000,
    poll_interval: int = 5,
) -> model.Model

Import a model from HuggingFace into this Model Registry.

Kicks off the asynchronous server-side download, polls until the import reaches a terminal status, and returns the registered model on success.

import hopsworks

project = hopsworks.login()
mr = project.get_model_registry()

# Public model — minimal call.
m = mr.hf_download("Qwen/Qwen2.5-0.5B")

# Gated / private — supply an HF access token.
m = mr.hf_download("meta-llama/Llama-3.2-1B", hf_token="hf_xxx")

# Multi-quant repo — pick exactly one variant.
m = mr.hf_download(
    "unsloth/Kimi-K2.6-GGUF", selected_variants=["UD-Q4_K_XL"]
)
PARAMETER DESCRIPTION
hugging_face_model_id

HF repo id (owner/repo) or full HuggingFace URL.

TYPE: str

hf_token

Optional HuggingFace access token; required for gated/private repos.

TYPE: str | None DEFAULT: None

selected_formats

Weight-format keys to download (safetensors, pytorch, tensorflow, flax, gguf, onnx, openvino, coreml, tflite). When omitted, the backend picks one with the precedence safetensors > pytorch > tensorflow > flax > … so multi-format repos don't pull every copy of the same weights.

TYPE: list[str] | None DEFAULT: None

selected_variants

GGUF / unsloth quantisation tags to keep (Q4_K_M, UD-Q4_K_XL, BF16, …). Acts as a sub-filter — files with a quant tag are only downloaded if their tag is in the list. Files without a tag (root README, config, …) are unaffected.

TYPE: list[str] | None DEFAULT: None

selected_filenames

Explicit per-file allowlist. When non-empty this overrides selected_formats / selected_variants and the backend downloads exactly these paths.

TYPE: list[str] | None DEFAULT: None

timeout

Maximum seconds to wait for the import to reach a terminal state.

TYPE: int DEFAULT: 36000

poll_interval

Seconds between status polls.

TYPE: int DEFAULT: 5

RETURNS DESCRIPTION
model.Model

The newly registered model entity.

RAISES DESCRIPTION
hopsworks.client.exceptions.HuggingFaceImportException

If the backend fails the import with a known terminal error. The exception's error_code field carries the stable code (auth_required, model_not_found, not_found_or_auth_required, no_disk_space, fetch_failed, etc.).

hopsworks.client.exceptions.RestAPIError

For unexpected server errors that are not part of the HF import error set.