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", 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]:])) - 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
Replicating AUPRC of 0.624 in ToxiChat: Understanding Model Inference
Hello! π
I've been working on replicating the AUPRC score of 0.62 achieved in ToxiChat using the LlamaGuard-7b model, and I'm seeking some guidance on the specifics of the process. I would greatly appreciate insights from anyone familiar with the model or the dataset.
Prompt Configuration: Could someone shed light on the ideal prompt used for the ToxiChat model? What kind of inputs or context tend to yield optimal results?
Dataset Handling: How is the ToxiChat dataset treated during inference? Any special preprocessing steps or considerations that contribute to the model's success?
Probability for "safe" and "unsafe": Could someone share insights on how to extract the probabilities associated with the predictions of the words "safe" and "unsafe" from the model's output? Right now, I obtain the logits of the words "safe" and "unsafe" and pass them through a softmax to obtain the probabilities that add up to 1.
Probability Thresholds for AUPRC: In calculating the AUPRC, which probability thresholds are used to determine positive and negative predictions?
Looking forward to a fruitful discussion!
Thank you! π
Same boat here, any progress?