Instructions to use meta-llama/LlamaGuard-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use meta-llama/LlamaGuard-7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="meta-llama/LlamaGuard-7b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("meta-llama/LlamaGuard-7b") model = AutoModelForCausalLM.from_pretrained("meta-llama/LlamaGuard-7b") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use meta-llama/LlamaGuard-7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "meta-llama/LlamaGuard-7b" # 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/LlamaGuard-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/meta-llama/LlamaGuard-7b
- SGLang
How to use meta-llama/LlamaGuard-7b 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/LlamaGuard-7b" \ --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/LlamaGuard-7b", "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/LlamaGuard-7b" \ --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/LlamaGuard-7b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use meta-llama/LlamaGuard-7b with Docker Model Runner:
docker model run hf.co/meta-llama/LlamaGuard-7b
[READ IF YOU DO NOT HAVE ACCESS] Getting access to the model
Hey all! If you do not have access to the model yet, please follow the next steps
- Go to Meta's official form at https://ai.meta.com/resources/models-and-libraries/llama-downloads/
- Fill the form - use the same email as your Hugging Face account
- Click
Submitat https://huggingface.co/meta-llama/LlamaGuard-7b - After 1-2 hours, you should have access.
Thanks!
Hi @osanseviero
I submitted the request to access the model few days ago and haven't got the access yet. I have followed the steps mentioned above. Can you please approve the access request. Thanks !
-Hema
Hello, I also submitted the request to access the model few days ago. and I filled out the form on Meta website today. Can you please approve the access to the model. Thank you.
Did you follow step-by-step the instructions above? Were both forms filled with the same email?
Yes, I received an email with this subject "[Access granted] Your request to access model meta-llama/LlamaGuard-7b has been accepted".
I believe the issue is resolved. I'll let you know if I still see issues. Thank you very much!
no access yet,
Hi @osanseviero , I submitted the request while ago and haven’t got the access yet.
I have followed the steps mention on above.
I submitted for access two days, but no any answer
Hello @osanseviero ,
I submitted a request from the huggingface page a few weeks ago, and just submitted a request via the link provided in step 1 above. Wondering if that's fine to get access to the model or I'll need to start over.
Thanks
I have applied a while ago and filled the form one more time today got the access from meta but not from HF
Hi, @osanseviero ,
I submitted a request to HF a few days ago, just filled out the form today. I received access permission from meta, but the permission from HF has not been approved yet. Can you help approve the access request? Thanks!
Hi, @osanseviero ,
I submitted a request to HF a few days ago too, and also just filled out the form today.
I received [Get started with Meta Llama 3] notification e-mail, but the permission from HF has not been approved yet. Can you help approve the access request?
Thanks!
Hello, @osanseviero ,
A few days ago, I sent a request from the huggingface page. Please share the access
Thanks!
I followed Step 1. There is no response after I clicked "accept and continue" on https://www.llama.com/llama-downloads/.
Hello, @osanseviero
There is no response after I clicked "Accept and Continue" at https://www.llama.com/llama-downloads/.
And after I clicked "Submit" at https://huggingface.co/meta-llama/LlamaGuard-7b, I had been rejected.
Any suggestions? Could you please help to grant the access?
Thanks!
Hello @osanseviero ,
My initial request was declined.
I'm building a private moderation pipeline using Llama Guard to filter unsafe prompts before inference with Mistral 7B.
Happy to provide more info. Could I please request reconsideration?