2025-06-05 13:18:14 +00:00
|
|
|
# Running Gated Huggingface Models with Token Authentication
|
2023-01-03 10:21:07 +00:00
|
|
|
|
2025-06-05 13:18:14 +00:00
|
|
|
Some models have restrictions and may require some sort of approval or agreement
|
|
|
|
|
process, which, by consequence, **requires token-authentication with Huggingface**.
|
2023-01-03 10:21:07 +00:00
|
|
|
|
2025-06-05 13:18:14 +00:00
|
|
|
The easiest way might be to use the `huggingface-cli login` command.
|
2023-01-03 10:21:07 +00:00
|
|
|
|
2025-06-05 13:18:14 +00:00
|
|
|
Alternatively, here is how you can generate a **"read-only public repositories"**
|
|
|
|
|
access token to log into your account on Huggingface, directly from `bazel`, in order to download models.
|
2023-01-03 10:21:07 +00:00
|
|
|
|
|
|
|
|
* log in at [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens).
|
|
|
|
|
* click on "Create new token"
|
2025-06-05 13:18:14 +00:00
|
|
|
* give the token a name, eg `zml_public_repos`,
|
|
|
|
|
* under _Repositories_, grant the following permission: "Read access to contents of all public gated repos you can access".
|
|
|
|
|
* at the bottom click on "Create token".
|
2023-01-03 10:21:07 +00:00
|
|
|
* copy the token by clicking `Copy`. **You won't be able to see it again.**
|
|
|
|
|
* the token looks something like `hf_abCdEfGhijKlM`.
|
2025-06-05 13:18:14 +00:00
|
|
|
* store the token on your machine (replace the placeholder with your actual token):
|
2023-01-03 10:21:07 +00:00
|
|
|
|
2023-03-14 15:28:03 +00:00
|
|
|
You can use the `HUGGINGFACE_TOKEN` environment variable to store the token or use
|
|
|
|
|
its standard location:
|
2023-01-03 10:21:07 +00:00
|
|
|
```
|
2023-03-14 15:28:03 +00:00
|
|
|
mkdir -p $HOME/.cache/huggingface/; echo <hf_my_token> > "$HOME/.cache/huggingface/token"
|
2023-01-03 10:21:07 +00:00
|
|
|
```
|
|
|
|
|
|
2025-06-05 13:18:14 +00:00
|
|
|
Now you're ready to download a gated model like `Meta-Llama-3.2-1b`!
|
2023-01-03 10:21:07 +00:00
|
|
|
|
|
|
|
|
**Example:**
|
|
|
|
|
|
|
|
|
|
```
|
2023-03-14 15:28:03 +00:00
|
|
|
# requires token in $HOME/.cache/huggingface/token, as created by the
|
|
|
|
|
# `huggingface-cli login` command, or the `HUGGINGFACE_TOKEN` environment variable.
|
2023-01-03 10:21:07 +00:00
|
|
|
cd examples
|
2025-06-05 13:18:14 +00:00
|
|
|
bazel run @zml//tools:hf -- download meta-llama/Llama-3.2-1B-Instruct --local-dir $HOME/Llama-3.2-1B-Instruct --exclude='*.pth'
|
|
|
|
|
bazel run --config=release //llama -- --hf-model-path=$HOME/Llama-3.2-1B-Instruct --prompt="What is the capital of France?"
|
2023-01-03 10:21:07 +00:00
|
|
|
```
|
|
|
|
|
|