Llama

From G1Joshi/Agent-Skills · View interactive version

Llama is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Meta Llama (Llama 3 / 3.2 / 3.3) assistance covering fine-tuning (LoRA/QLoRA), vLLM deployment, and prompt templates. Use when deploying open-weight foundation models locally or in the cloud.

How to use this skill

Skill file

Llama

Meta Llama is the foundation standard for open-weight language models, providing dense and Mixture-of-Experts architectures optimized for fine-tuning, quantization, and local deployment.

When to Use

Quick Start

# Serve Llama 3 with vLLM for high-throughput OpenAI-compatible inference
vLLM serve meta-llama/Llama-3.2-3B-Instruct \
  --port 8000 \
  --max-model-len 8192 \
  --gpu-memory-utilization 0.90

Core Concepts

Local GGUF Inference with llama-cpp-python

Fast, low-latency CPU/GPU inference with zero external network calls:

from llama_cpp import Llama

# Load GGUF model with GPU layer offloading
llm = Llama(
    model_path="./models/Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
    n_gpu_layers=-1, # Offload all layers to GPU (Metal / CUDA)
    n_ctx=8192,      # Context window
    verbose=False
)

# Chat completion with standard Llama 3 instruction prompt format
response = llm.create_chat_completion(
    messages=[
        {"role": "system", "content": "You are a concise Unix systems administrator."},
        {"role": "user", "content": "How do I find processes holding open deleted files?"}
    ],
    temperature=0.2,
    max_tokens=256
)

print(response["choices"][0]["message"]["content"])

Serving Llama via vLLM with OpenAI API Compatibility

Deploying Llama 3.1 as an enterprise production endpoint:

# Launch vLLM server with tensor parallelism and 16k context window
vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --dtype bfloat16 \
  --max-model-len 16384 \
  --port 8000

Parameter-Efficient Fine-Tuning with LoRA & PEFT

Adapting Llama to domain specific instructions:

from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B-Instruct", device_map="auto")

lora_config = LoraConfig(
    r=16,
    lora_alpha=32,
    target_modules=["q_proj", "v_proj", "k_proj", "o_proj"],
    lora_dropout=0.05,
    bias="none",
    task_type="CAUSAL_LM"
)

peft_model = get_peft_model(model, lora_config)
peft_model.print_trainable_parameters()

Common Patterns

Official Llama 3 Chat Template Formatting

Problem: Incorrect header formatting degrades instruction following and triggers repetition loops.

Solution:

Apply tokenizer chat template:

from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B-Instruct")
messages = [
    {"role": "system", "content": "You are a concise programming assistant."},
    {"role": "user", "content": "Write a quicksort function in Python."}
]

prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# Formats into: <|begin_of_text|><|start_header_id|>system<|end_header_id|>...

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------------------------------- | :------------------------------------------------------- | :----------------------------------------------------------------------- |

| 403 Client Error: Cannot access repository | Missing access approval for Llama model on Hugging Face. | Request model access on Meta/HuggingFace and provide Hugging Face token. |

| Model generating endless repetition tokens | Missing stop tokens in inference generation config. | Configure explicit stop tokens: <\|eot_id\|> and <\|end_of_text\|>. |

| CUDA out of memory during vLLM serve | KV cache memory allocation exceeds available VRAM. | Lower --gpu-memory-utilization or reduce --max-model-len. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.