RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
Glossary / Frameworks & tools / PyTorch
Frameworks & tools

PyTorch

PyTorch is an open-source machine learning framework developed by Meta. It provides tensor computation with GPU acceleration and automatic differentiation, making it the primary framework for training and running many local AI models. Operators encounter PyTorch when loading models in Hugging Face Transformers or when using tools like vLLM that depend on PyTorch for model inference. PyTorch's dynamic computation graph allows flexible model building, but its memory usage can be high—a typical 7B model in FP16 requires ~14 GB of VRAM, often necessitating quantization for consumer GPUs.

Deeper dive

PyTorch is the backbone of most modern local AI workflows. It manages tensors (multi-dimensional arrays) on CPU or GPU and records operations for automatic gradient computation, which is essential for training. For inference, PyTorch executes the model's forward pass. Operators often use PyTorch indirectly: Hugging Face Transformers loads models into PyTorch by default, and vLLM uses PyTorch for its inference engine. PyTorch's memory footprint is a key concern—model weights, activations, and optimizer states all consume VRAM. Quantization (e.g., using bitsandbytes or GPTQ) reduces memory by converting weights to lower precision (INT4/INT8), trading off some accuracy for speed and fit. PyTorch also supports torch.compile, which can optimize inference speed by fusing operations, though it may increase compilation time.

Practical example

A rig with an RTX 3090 (24 GB VRAM) can run Llama 3.1 8B in FP16 (16 GB) with a 2K context. But running the same model in FP32 (32 GB) would exceed VRAM. Using PyTorch's built-in quantization (torch.quantization) or loading a 4-bit quantized version via bitsandbytes reduces memory to ~5 GB, leaving room for larger contexts or other tasks.

Workflow example

When you run from transformers import AutoModelForCausalLM; model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B", torch_dtype=torch.float16, device_map="auto"), Hugging Face loads the model into PyTorch tensors. The device_map="auto" tells PyTorch to split layers across GPU and CPU if VRAM is insufficient. You'll see PyTorch allocate memory and, if VRAM is tight, offload some layers to system RAM—slowing inference from ~40 tok/s to ~5 tok/s.

Reviewed by Fredoline Eruo. See our editorial policy.

Buyer guides
  • Best GPU for local AI →
  • Best laptop for local AI →
  • Best Mac for local AI →
When it doesn't work
  • CUDA out of memory →
  • Ollama running slowly →
  • ROCm not detected →