Skip to main content

Running locally

This guide provides step-by-step instructions for running Ai2 models locally. It is aimed at software developers familiar with Python, but not necessarily experienced with machine learning or large language models.


Prerequisites​

Before running any models, ensure your system meets the following requirements:

Minimum Hardware Requirements​

While most models will run well on an 80G GPU (e.g. NVIDIA A100 or H100), there's a wide range of requirements across the various models as demonstrated by the following minimum requirements.

Software Requirements​

macOS Requirements

  • Python 3.8 or newer (install via python.org or Homebrew)
  • pip (included with Python)
  • Virtual environment tool: python -m venv (built-in)

For detailed Python installation instructions, see the macOS-specific Python installation guide.

Hello, world​

Below is a minimal example that loads a model and generates a short text completion.

Install packages

pip install torch transformers

Code example

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "allenai/OLMo-2-0425-1B"
device = "cuda" if torch.cuda.is_available() else "cpu"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id).to(device)

prompt = "The future of AI is"
inputs = tokenizer(prompt, return_tensors="pt").to(device)

outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

GPU acceleration with vLLM​

vLLM is a high-performance inference engine that significantly improves the runtime performance of Hugging Face models through several key optimizations:

  • Continuous Batching: Batches requests dynamically, maximizing GPU utilization
  • PagedAttention: Manages GPU memory via paging like virtual memory
  • Kernel Fusion: Combines operations into single kernels to reduce bandwidth
  • Quantization Support: Enables 4-bit and 8-bit quantization for memory savings
  • Tensor Parallelism: Distributes layers across GPUs for faster inference

Follow these three steps to get it running with any Ai2 model (e.g., Olmo):

  1. Install

    pip install vllm
  2. Launch an OpenAI‑compatible server

    vllm serve allenai/OLMo-2-0425-1B --served-model-name olmo
    # Server now listens on http://localhost:8000/v1
  3. Query the model

    curl http://localhost:8000/v1/completions \
    -H "Content-Type: application/json" \