401 error with fine-grained token from Kaggle but not from Colab

#280
by GeethikaV16 - opened

Hello,

I am getting a 401 error when trying to load meta-llama/Meta-Llama-3-8B-Instruct from Kaggle using a fine-grained access token, even though the same token works in Google Colab and my account shows “You have been granted access” on the model page.

My account:

  • Username: GeethikaV16

Token:

  • Type: fine-grained access token

  • Display name: Kaggle_LIama3

  • Permissions (from whoami in Python):

    {
    'type': 'user',
    'id': '6a579032b70c4e2a44b14c44',
    'name': 'GeethikaV16',
    'fullname': 'Geethika Vardhineni',
    'isPro': False,
    'avatarUrl': '/avatars/a840dc7df4122e4219fb6be7b62c481e.svg',
    'orgs': [],
    'auth': {
    'type': 'access_token',
    'accessToken': {
    'displayName': 'Kaggle_LIama3',
    'role': 'fineGrained',
    'fineGrained': {
    'canReadGatedRepos': True,
    'global': [],
    'scoped': [
    {
    'entity': {
    '_id': '6a579032b70c4e2a44b14c44',
    'type': 'user',
    'name': 'GeethikaV16'
    },
    'permissions': ['repo.content.read']
    }
    ]
    }
    }
    }
    }

In Google Colab:

I run:

!pip install -q huggingface_hub

from huggingface_hub import HfApi

hf_token = "hf_kgSTL..."  # Kaggle_LIama3 token
api = HfApi(token=hf_token)

print(api.whoami())
info = api.model_info("meta-llama/Meta-Llama-3-8B-Instruct")
print("Model id:", info.id)

This outputs:

  • whoami: name = 'GeethikaV16', with canReadGatedRepos = True and repo.content.read
  • Model id: meta-llama/Meta-Llama-3-8B-Instruct

So from Colab, the token is valid and authorized to read the gated model.

In Kaggle:

I store the same token as a secret HF_TOKEN and run:

!pip install -q "transformers>=4.40.0" "huggingface_hub>=0.23.0"

from kaggle_secrets import UserSecretsClient
from transformers import AutoTokenizer

user_secrets = UserSecretsClient()
HF_TOKEN = user_secrets.get_secret("HF_TOKEN")

print("HF_TOKEN is None:", HF_TOKEN is None)
print("HF_TOKEN length:", len(HF_TOKEN) if HF_TOKEN else None)
print("HF_TOKEN prefix:", HF_TOKEN[:8] if HF_TOKEN else None)

tokenizer = AutoTokenizer.from_pretrained(
    "meta-llama/Meta-Llama-3-8B-Instruct",
    use_auth_token=HF_TOKEN,
)

This prints:

  • HF_TOKEN is None: False
  • HF_TOKEN length: 37
  • HF_TOKEN prefix: hf_kgSTL

But fails with:

Example request ID from the Kaggle error:

Root=1-6a6d916c-4976c974055593e406a27b15;ad057711-61fa-433d-82a0-5fe6ed9dd339

My question:

Why does this fine-grained token with canReadGatedRepos=True and repo.content.read work from Colab (HfApi.model_info), but the same token gets 401 Unauthorized when used via AutoTokenizer.from_pretrained(..., use_auth_token=HF_TOKEN) from Kaggle?

Is there any extra restriction (IP, environment, client) for gated models that would explain this? How can I use this token from Kaggle to download Meta-Llama-3-8B-Instruct?

Thank you,
Geethika (GeethikaV16)

Sign up or log in to comment