Hugging Face
Create a Hugging Face registry, generate an identity token, then host and retrieve private models and datasets with huggingface_hub client libraries.
Use a Hugging Face registry to host private models and datasets for use with Hugging Face Hub client libraries, such as huggingface_hub, transformers, and datasets.
What you will learn from this topic
By the end of this quickstart guide, you will be able to:
Create a registry in Harness Artifacts.
Publish a package to the registry.
Install the package from the registry, and confirm the working.
Before you begin
Install the Hugging Face CLI. Running
pip install -U huggingface_hubinstalls thehfcommand and thehuggingface_hubPython library used throughout this quickstart.
Make sure you have access to a Harness account with permission to create registries and generate identity tokens.
Create a Hugging Face Registry
To create a Huggingface Registry, perform the following steps:
In Artifact Registry, select Registries.
Select + Create Registry.
Specify the Registry name.
Optionally, add a Description.
Choose visibility between Public and Private. The default is Private.
Select Huggingface as the Registry type.
Select Save.
Select Create to finalize.
Huggingface client setup
In your Hugging Face Artifact, select the registry, then select Set Up Client. The dialog gives you an identity token, then setup instructions for publishing and using models and datasets with the huggingface_hub library.
Generate an identity token
An identity token serves as the password for authenticating with the registry.
In your Hugging Face Artifact, select Set Up Client.
Select Generate Token.
Select an Expiration for the token:
30 Days
90 Days
180 Days
Custom
Copy the token. You use it in the following steps in place of
<IDENTITY_TOKEN>.
Configure the client
Select Models or Datasets for what you want to publish or use. In the code samples, replace the values in angle brackets with your own values.
1. Configure environment variables
Set the following environment variables:
2. Publish the model
Upload a model to the registry using the huggingface_hub library:
3. Use the model
Download the model from the registry:
1. Configure environment variables
Set the following environment variables:
2. Publish the dataset
Upload a dataset to the registry using the huggingface_hub library:
3. Use the dataset
Load the dataset directly with the datasets library, or download the full dataset repository:
Setup verification
Confirm that your registry serves the model or dataset you published. To verify your setup, perform the following steps:
In a new environment with no cached Hugging Face files (clear
HF_HOME, or point it to an empty directory), use thehuggingface_hubordatasetslibrary to resolve the model or dataset you published.Confirm that the client downloaded the model or dataset from your Harness registry endpoint, which is shown in Set Up Client.
In Harness, open your registry and confirm that the model or dataset, and the revision you published, appear in the package list.
If a step fails, go to Troubleshooting to resolve common authentication and resolution issues before you retry.
Pipeline automation (optional)
Publishing from a pipeline gives you a repeatable release process. Run the publish step when you create a version tag, so each release maps to one revision in the registry.
The following Run step uploads a model folder to your registry using the huggingface_hub library, with the revision sourced from the pipeline's codebase tag. Store the identity token as a Harness secret, and do not write it into the pipeline YAML.
Troubleshooting
Next steps
To add a pipeline that publishes a new version for every release tag, go to Harness CI.
To control who can publish and consume packages in your registry, go to RBAC and permissions.
To set retention and lifecycle rules for old versions, go to Lifecycle Management overview.
Last updated
Was this helpful?