AI & Machine Learning Cheatsheet

Open-Source Models

Use this AI & Machine Learning reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

The Open-Source AI Ecosystem

Open-source AI models have closed the gap with proprietary frontier models. Open-weight releases (DeepSeek, Qwen, Llama, gpt-oss, Kimi) now trail the closed frontier by months, not years, and beat it on cost for most production tasks. Open-source enables:

  • Local deployment: no API costs, privacy, offline capability
  • Fine-tuning: adapt to specific domains
  • Research: reproducibility, study internals
  • Edge deployment: run on-device (phones, laptops)

Important distinction: - Open weights: model weights released (Llama, Mistral, Qwen) — can run and fine-tune, but training data and code may not be public - Fully open source: weights + training code + data (OLMo, Pythia)

Language Models

Llama Family (Meta)

The most influential open-weight family. Set the standard for community adoption.

ModelParamsContextKey Features
Llama 27B/13B/70B4096Chat + base; 2023
Llama 38B/70B8192Strong instruction following; 2024
Llama 3.18B/70B/405B128kLong context; 405B near frontier
Llama 3.21B/3B/11B/90B128kIncludes vision models
Llama 3.370B128kLast dense Llama; still a strong 70B
Llama 4 Scout/Maverick109B/400B MoE (17B active)10M/1MNatively multimodal MoE (2025)
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto"
)

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Explain gradient descent."}
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
output = model.generate(input_ids, max_new_tokens=500, temperature=0.7, do_sample=True)
response = tokenizer.decode(output[0][input_ids.shape[-1]:], skip_special_tokens=True)

Mistral / Mixtral

European startup with some of the best efficiency-to-quality ratios.

ModelArchitectureKey Feature
Mistral 7BDenseSliding window attention, fast
Mixtral 8×7BSparse MoE8 experts, uses 2 per token; ~46B params, runs as 13B
Mixtral 8×22BSparse MoENear GPT-4 quality
Mistral Small/MediumDenseAPI-only
CodestralDenseCode-specialized

Mixture of Experts (MoE): each token is routed to a subset of "expert" FFN layers by a learned router. Increases model capacity (total parameters) without proportionally increasing compute per token.

# Mixtral with transformers
model = AutoModelForCausalLM.from_pretrained(
    "mistralai/Mixtral-8x7B-Instruct-v0.1",
    torch_dtype=torch.float16,
    device_map="auto"
)

Qwen (Alibaba)

Strong multilingual and coding capabilities; the most complete open model family.

ModelParamsSpecialization
Qwen2.5 / Qwen2.5-Coder0.5B–72BPrevious generation, still widely deployed
Qwen30.6B–32B dense; 30B-A3B, 235B-A22B MoEHybrid thinking/non-thinking modes (2025)
Qwen3-Coder480B-A35B (+ 30B)Agentic coding, 256k context
Qwen3-Embedding / Reranker0.6B–8BTop of MTEB multilingual
QwQ-32B32BLong-form reasoning / CoT

DeepSeek

Strong reasoning models from a Chinese lab; some of the most efficient architectures.

ModelParamsNotes
DeepSeek-V2236B (MoE)Very efficient MoE (MLA attention)
DeepSeek-V3671B (MoE)GPT-4-class open weights (Dec 2024)
DeepSeek-R1 (+ R1-0528)671B (MoE)Open reasoning model, RL-trained (2025)
DeepSeek-R1-Distill7B–70BDistilled reasoning into dense models
DeepSeek-V3.1671B (MoE)Hybrid thinking mode; merges V3 + R1 (2025)

Gemma (Google)

Small, efficient, open models from Google DeepMind.

ModelParamsNotes
Gemma 29B/27BSolid previous generation
Gemma 31B/4B/12B/27BMultimodal (SigLIP), 128k context (2025)
Gemma 3n~2B/4B effectiveOn-device, audio + vision input
PaliGemma 23B–28BVision-language

Microsoft Phi

"Textbook quality" training data enables strong performance at tiny scale.

ModelParamsNotes
Phi-3 mini/small/medium3.8B/7B/14BVery efficient
Phi-3.5-MoE16B active/42B totalMoE efficiency
Phi-414BSynthetic-data pretraining, strong math (Dec 2024)
Phi-4-mini / multimodal3.8B/5.6BSmall, audio + vision variants (2025)

Other Notable Open Releases (2025)

ModelParamsNotes
gpt-oss (OpenAI)20B / 120B (MoE)First open OpenAI weights since GPT-2; Apache-2.0, reasoning effort levels
Kimi K2 (Moonshot)1T MoE (32B active)Agentic tool use, strong coding
GLM-4.5 (Zhipu)355B MoEHybrid reasoning + agentic
OLMo 2 (AI2)7B/13B/32BFully open: weights + data + code

Code Models

ModelParamsLicenseNotes
CodeLlama7B–70BLlama 2Meta's code-specialized Llama
DeepSeek-Coder-V2236B (MoE)PermissiveSOTA open code model
Qwen2.5-Coder 32B32BPermissiveStrong all-around
Qwen3-Coder480B-A35B / 30BApache 2Agentic coding, 256k context
StarCoder23B/7B/15BBigCodePermissive, transparent training
WizardCoder33BLlama 2Evol-Instruct fine-tune
Codestral22BMistral MNPLCode + fill-in-the-middle

Vision-Language Models (Open)

ModelBackboneContextNotes
Qwen2.5-VLQwen2.5 + ViT128kVideo + images, doc parsing, grounding
InternVL3InternViT + Qwen2.532kStrong benchmarks
Gemma 3Gemma 3 + SigLIP128kSmall, multilingual
Llama 4Early-fusion MoE1M+Natively multimodal
PixtralMistral + ViT128kMulti-image
LLaVA-OneVisionQwen2 + SigLIP32kResearch-friendly, video

Embedding Models (Open)

ModelDimLicenseNotes
BAAI/bge-large-en-v1.51024MITTop English retrieval
BAAI/bge-m31024MITMultilingual, multi-task
nomic-embed-text-v1.5768Apache 2Long context (8k)
intfloat/multilingual-e5-large1024MIT100+ languages
Alibaba-NLP/gte-large-en-v1.51024Apache 2Strong all-around

Image Generation (Open)

ModelTypeNotes
Stable Diffusion 1.5Latent diffusionClassic baseline
SDXLLatent diffusionHigher quality, 1024px
Stable Diffusion 3.5Flow matchingBetter text rendering
Flux.1 / Flux.1 KontextFlow matching, DiTTop open image gen; Kontext adds editing
Qwen-ImageMMDiTStrong text rendering (2025)
SDXL-Turbo / LCMDistilled SD1–4 step sampling
from diffusers import FluxPipeline
import torch

pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell",
                                     torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()  # save VRAM

image = pipe(
    "A serene mountain lake at dusk, photorealistic",
    guidance_scale=0.0,   # Flux.1-schnell uses 0 guidance
    num_inference_steps=4,
    max_sequence_length=256
).images[0]
image.save("mountain.png")

Running Models Locally

Ollama (Easiest)

Download and run models with one command. Automatically handles quantization and CPU/GPU:

# Install: https://ollama.com
ollama pull llama3.1:8b
ollama run llama3.1:8b
ollama pull nomic-embed-text
ollama pull qwen3:8b
import ollama

response = ollama.chat(
    model="llama3.1:8b",
    messages=[{"role": "user", "content": "What is backpropagation?"}]
)
print(response["message"]["content"])

# Embeddings
emb = ollama.embeddings(model="nomic-embed-text", prompt="Hello world")

llama.cpp + GGUF

Quantized models in GGUF format run efficiently on CPU (and GPU with llama.cpp):

from llama_cpp import Llama

# Download from HuggingFace: TheBloke/*.GGUF or bartowski/*.GGUF
llm = Llama.from_pretrained(
    repo_id="bartowski/Meta-Llama-3.1-8B-Instruct-GGUF",
    filename="Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf",
    n_gpu_layers=-1,   # use all GPU layers
    n_ctx=8192
)
output = llm.create_chat_completion(
    messages=[{"role": "user", "content": "Explain transformers"}],
    max_tokens=512, temperature=0.7
)

GGUF Quantization Levels

FormatSize (7B)Quality vs. FP16Use When
Q8_07.7 GBNear identicalHigh-end GPU
Q6_K5.9 GBExcellent8 GB VRAM
Q5_K_M5.1 GBVery good8 GB VRAM
Q4_K_M4.4 GBGood6–8 GB VRAM
Q3_K_M3.5 GBAcceptable4–6 GB VRAM
Q2_K2.9 GBDegradedCPU only

HuggingFace Transformers

Standard API for loading and running any open model:

from transformers import pipeline

# Text generation
generator = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3",
                      torch_dtype=torch.bfloat16, device_map="auto")
result = generator("Explain the attention mechanism", max_new_tokens=300)

# Text embeddings
extractor = pipeline("feature-extraction", model="BAAI/bge-large-en-v1.5",
                      device="cuda")
embedding = extractor("Hello world", return_tensors="pt")

Key Repositories and Resources

ResourceURLPurpose
HuggingFace Hubhuggingface.coModel hosting, datasets, spaces
LMSYS Chatbot Arenalmarena.aiHuman preference leaderboard
Artificial Analysisartificialanalysis.aiQuality/speed/price comparisons
MTEB Leaderboardhuggingface.co/spaces/mteb/leaderboardEmbedding model ranking
Ollamaollama.comLocal model runner
LM Studiolmstudio.aiGUI for local models
bartowski / unslothHF profilesGGUF quantized model files

Fine-Tuning Open Models

The most common workflow with open models is fine-tuning for domain adaptation:

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import LoraConfig, get_peft_model, TaskType
from trl import SFTTrainer, SFTConfig
from datasets import load_dataset

# 4-bit quantization
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16
)

model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Meta-Llama-3.1-8B",
    quantization_config=bnb_config,
    device_map="auto"
)

# LoRA config
lora = LoraConfig(
    r=16, lora_alpha=32, lora_dropout=0.05,
    target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"],
    task_type=TaskType.CAUSAL_LM
)
model = get_peft_model(model, lora)

dataset = load_dataset("json", data_files="train.jsonl")["train"]

trainer = SFTTrainer(
    model=model,
    train_dataset=dataset,
    args=SFTConfig(
        output_dir="./fine_tuned",
        per_device_train_batch_size=4,
        gradient_accumulation_steps=4,
        learning_rate=2e-4,
        num_train_epochs=3,
        fp16=False, bf16=True,
        logging_steps=10,
        save_strategy="epoch"
    )
)
trainer.train()
trainer.save_model()

Choosing an Open Model

PriorityRecommended
Best quality, any sizeDeepSeek-V3.1 / R1, Kimi K2, or Qwen3-235B-A22B
Fits one 80 GB GPUgpt-oss-120b (MoE) or Qwen3-32B
Best ~70B / 32B classLlama 3.3 70B (dense) or Qwen3-32B
Best small (~8B)Qwen3-8B, Llama 3.1 8B, or Gemma 3 12B
Run on CPU / laptopGemma 3 4B, Qwen3-4B, or Phi-4-mini (Q4 GGUF)
Code generationQwen3-Coder or DeepSeek-V3.1
Math / reasoningDeepSeek-R1 (or its distills), Qwen3 thinking mode, gpt-oss
Vision-languageQwen2.5-VL, InternVL3, or Gemma 3 27B
EmbeddingsQwen3-Embedding or BGE-M3
Image generationFlux.1-schnell / Kontext or SD 3.5