agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/ai-ml/llama/SKILL.md

llama

Skill15 starsChanged 44 days agoMITView on GitHub

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.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use GGUF 4-bit (Q4_K_M) or 5-bit (Q5_K_M) quantization for optimal balance of speed and perplexity.

    line 118
  2. Very specific:

    Use Meta Llama 3 prompt template formatting (<|start_header_id|>...<|end_header_id|>) for accurate instruction following.

    line 120
  3. Distinctive:

    Run unquantized 16-bit models on consumer GPUs if memory capacity causes swap thrashing.

    line 125
  4. Distinctive:

    Use chat models without supplying system prompts specifying constraints and formatting rules.

    line 127

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  • Local & On-Premise LLM Deployment: Running Meta Llama 3.1/3.2/3.3 locally without data leaving the private perimeter.
  • High-Efficiency Quantized Inference: Utilizing GGUF (via llama.cpp) and AWQ/GPTQ on consumer and enterprise GPUs.
  • Fine-Tuning on Custom Domain Data: Training LoRA/QLoRA adapters with Unsloth or Axolotl.
  • Embedded & Mobile Edge AI: Running lightweight Llama 3.2 1B and 3B models directly on laptops and mobile devices.

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:

  • Use GGUF 4-bit (Q4_K_M) or 5-bit (Q5_K_M) quantization for optimal balance of speed and perplexity.
  • Offload all layers (n_gpu_layers=-1) to GPU memory whenever VRAM capacity allows.
  • Use Meta Llama 3 prompt template formatting (<|start_header_id|>...<|end_header_id|>) for accurate instruction following.
  • Pin model versions and test against specific release tags (e.g. Llama-3.1-8B-Instruct).

Don't:

  • Run unquantized 16-bit models on consumer GPUs if memory capacity causes swap thrashing.
  • Forget to configure appropriate context lengths (n_ctx); exceeding default context degrades performance.
  • Use chat models without supplying system prompts specifying constraints and formatting rules.

Troubleshooting

ErrorCauseSolution
403 Client Error: Cannot access repositoryMissing access approval for Llama model on Hugging Face.Request model access on Meta/HuggingFace and provide Hugging Face token.
Model generating endless repetition tokensMissing stop tokens in inference generation config.Configure explicit stop tokens: <|eot_id|> and <|end_of_text|>.
CUDA out of memory during vLLM serveKV cache memory allocation exceeds available VRAM.Lower --gpu-memory-utilization or reduce --max-model-len.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.