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

huggingface

Skill15 starsChanged 43 days agoMITView on GitHub

Expert Hugging Face assistance covering Transformers, datasets, pipelines, Hub model loading, and tokenizers. Use when downloading, fine-tuning, and deploying open-source machine learning models.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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 BitsAndBytesConfig (nf4) or AWQ quantization to run open-weight LLMs with low memory consumption.

    line 131
  2. Very specific:

    Use datasets.load_dataset(..., streaming=True) for datasets that exceed local storage capacity.

    line 133
  3. Distinctive:

    Run unquantized 70B+ parameter models on consumer hardware.

    line 140

≈ “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

Hugging Face

Hugging Face is the central platform and ecosystem for open-source machine learning, hosting models, datasets, Spaces, and foundational libraries like Transformers, Accelerate, and PEFT.

When to Use

  • Pretrained Model Discovery & Inference: Utilizing thousands of open-source vision, NLP, and audio models via transformers.
  • Parameter-Efficient Fine-Tuning (PEFT): Fine-tuning LLMs with LoRA / QLoRA using peft and bitsandbytes.
  • Dataset Management & Streaming: Accessing multi-gigabyte datasets without memory exhaustion via datasets.
  • Production Model Deployment: Deploying containerized endpoints with Hugging Face Text Generation Inference (TGI).

Quick Start

from transformers import pipeline

# One-line inference with modern pre-trained models
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

result = classifier("This framework makes NLP development seamless and fast!")
print(result) # [{'label': 'POSITIVE', 'score': 0.9998}]

Core Concepts

Inference Pipeline with Transformers & PyTorch

Loading state-of-the-art transformer models with automatic tokenization:

from transformers import pipeline
import torch

# Create accelerated text-classification pipeline
classifier = pipeline(
    task="text-classification",
    model="distilbert/distilbert-base-uncased-finetuned-sst-2-english",
    device=0 if torch.cuda.is_available() else -1
)

results = classifier([
    "This new AI development platform accelerates productivity significantly.",
    "The legacy system crashed repeatedly under moderate load."
])

for res in results:
    print(f"Label: {res['label']}, Score: {res['score']:.4f}")

4-Bit Model Quantization with BitsAndBytes

Loading large LLMs on consumer hardware using 4-bit NormalFloat (NF4):

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

model_id = "meta-llama/Llama-3.2-3B-Instruct"

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
    bnb_4bit_use_double_quant=True
)

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=bnb_config,
    device_map="auto"
)

inputs = tokenizer("Explain quantum computing in one sentence:", return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Streaming Massive Datasets with Datasets Library

Iterating over terabyte-scale datasets without downloading all files upfront:

from datasets import load_dataset

# Stream dataset lazily without full disk download
dataset = load_dataset('allenai/c4', 'en', split='train', streaming=True)

# Iterate through samples
for i, sample in enumerate(dataset.take(3)):
    print(f"Sample {i+1}: {sample['text'][:100]}...\n")

Common Patterns

Quantized Model Loading with BitsAndBytes (4-bit / 8-bit)

Problem: 7B-70B parameter models exceed single-GPU VRAM limits in FP16 precision.

Solution: Load with 4-bit NF4 quantization using BitsAndBytesConfig:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16
)

model_id = "meta-llama/Llama-3.2-3B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    quantization_config=bnb_config,
    device_map="auto"
)

Best Practices

Do:

  • Use BitsAndBytesConfig (nf4) or AWQ quantization to run open-weight LLMs with low memory consumption.
  • Set device_map="auto" when loading large models to distribute layers automatically across available GPUs and RAM.
  • Use datasets.load_dataset(..., streaming=True) for datasets that exceed local storage capacity.
  • Pass torch_dtype=torch.bfloat16 when running inference on modern Ampere/Hopper GPU architectures.

Don't:

  • Load entire models onto CPU before moving to GPU; instantiate directly with device_map.
  • Hardcode Hugging Face access tokens in code; authenticate via huggingface-cli login or HF_TOKEN.
  • Run unquantized 70B+ parameter models on consumer hardware; use quantized GGUF, EXL2, or 4-bit NF4.

Troubleshooting

ErrorCauseSolution
Gated repo error / 403 ForbiddenAccessing gated model (e.g. Llama/Mistral) without accepting license on Hub.Accept license on HuggingFace and run huggingface-cli login.
CUDA Out of Memory in from_pretrainedModel weights exceed GPU memory in FP32.Use device_map="auto", torch_dtype=torch.float16, or 4-bit quantization.
KeyError in tokenizer outputMismatched tokenizer and model configurations.Always load tokenizer and model from the identical model_id.

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.