Instructions to use meta-llama/Meta-Llama-3-8B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use meta-llama/Meta-Llama-3-8B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct") model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use meta-llama/Meta-Llama-3-8B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "meta-llama/Meta-Llama-3-8B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "meta-llama/Meta-Llama-3-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/meta-llama/Meta-Llama-3-8B-Instruct
- SGLang
How to use meta-llama/Meta-Llama-3-8B-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "meta-llama/Meta-Llama-3-8B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "meta-llama/Meta-Llama-3-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "meta-llama/Meta-Llama-3-8B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "meta-llama/Meta-Llama-3-8B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use meta-llama/Meta-Llama-3-8B-Instruct with Docker Model Runner:
docker model run hf.co/meta-llama/Meta-Llama-3-8B-Instruct
401 error with fine-grained token from Kaggle but not from Colab
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:
- 401 Unauthorized
- GatedRepoError: Cannot access gated repo for url https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct/resolve/main/config.json
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)