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.
| Model | Params | Context | Key Features |
|---|---|---|---|
| Llama 2 | 7B/13B/70B | 4096 | Chat + base; 2023 |
| Llama 3 | 8B/70B | 8192 | Strong instruction following; 2024 |
| Llama 3.1 | 8B/70B/405B | 128k | Long context; 405B near frontier |
| Llama 3.2 | 1B/3B/11B/90B | 128k | Includes vision models |
| Llama 3.3 | 70B | 128k | Last dense Llama; still a strong 70B |
| Llama 4 Scout/Maverick | 109B/400B MoE (17B active) | 10M/1M | Natively 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.
| Model | Architecture | Key Feature |
|---|---|---|
| Mistral 7B | Dense | Sliding window attention, fast |
| Mixtral 8×7B | Sparse MoE | 8 experts, uses 2 per token; ~46B params, runs as 13B |
| Mixtral 8×22B | Sparse MoE | Near GPT-4 quality |
| Mistral Small/Medium | Dense | API-only |
| Codestral | Dense | Code-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.
| Model | Params | Specialization |
|---|---|---|
| Qwen2.5 / Qwen2.5-Coder | 0.5B–72B | Previous generation, still widely deployed |
| Qwen3 | 0.6B–32B dense; 30B-A3B, 235B-A22B MoE | Hybrid thinking/non-thinking modes (2025) |
| Qwen3-Coder | 480B-A35B (+ 30B) | Agentic coding, 256k context |
| Qwen3-Embedding / Reranker | 0.6B–8B | Top of MTEB multilingual |
| QwQ-32B | 32B | Long-form reasoning / CoT |
DeepSeek
Strong reasoning models from a Chinese lab; some of the most efficient architectures.
| Model | Params | Notes |
|---|---|---|
| DeepSeek-V2 | 236B (MoE) | Very efficient MoE (MLA attention) |
| DeepSeek-V3 | 671B (MoE) | GPT-4-class open weights (Dec 2024) |
| DeepSeek-R1 (+ R1-0528) | 671B (MoE) | Open reasoning model, RL-trained (2025) |
| DeepSeek-R1-Distill | 7B–70B | Distilled reasoning into dense models |
| DeepSeek-V3.1 | 671B (MoE) | Hybrid thinking mode; merges V3 + R1 (2025) |
Gemma (Google)
Small, efficient, open models from Google DeepMind.
| Model | Params | Notes |
|---|---|---|
| Gemma 2 | 9B/27B | Solid previous generation |
| Gemma 3 | 1B/4B/12B/27B | Multimodal (SigLIP), 128k context (2025) |
| Gemma 3n | ~2B/4B effective | On-device, audio + vision input |
| PaliGemma 2 | 3B–28B | Vision-language |
Microsoft Phi
"Textbook quality" training data enables strong performance at tiny scale.
| Model | Params | Notes |
|---|---|---|
| Phi-3 mini/small/medium | 3.8B/7B/14B | Very efficient |
| Phi-3.5-MoE | 16B active/42B total | MoE efficiency |
| Phi-4 | 14B | Synthetic-data pretraining, strong math (Dec 2024) |
| Phi-4-mini / multimodal | 3.8B/5.6B | Small, audio + vision variants (2025) |
Other Notable Open Releases (2025)
| Model | Params | Notes |
|---|---|---|
| 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 MoE | Hybrid reasoning + agentic |
| OLMo 2 (AI2) | 7B/13B/32B | Fully open: weights + data + code |
Code Models
| Model | Params | License | Notes |
|---|---|---|---|
| CodeLlama | 7B–70B | Llama 2 | Meta's code-specialized Llama |
| DeepSeek-Coder-V2 | 236B (MoE) | Permissive | SOTA open code model |
| Qwen2.5-Coder 32B | 32B | Permissive | Strong all-around |
| Qwen3-Coder | 480B-A35B / 30B | Apache 2 | Agentic coding, 256k context |
| StarCoder2 | 3B/7B/15B | BigCode | Permissive, transparent training |
| WizardCoder | 33B | Llama 2 | Evol-Instruct fine-tune |
| Codestral | 22B | Mistral MNPL | Code + fill-in-the-middle |
Vision-Language Models (Open)
| Model | Backbone | Context | Notes |
|---|---|---|---|
| Qwen2.5-VL | Qwen2.5 + ViT | 128k | Video + images, doc parsing, grounding |
| InternVL3 | InternViT + Qwen2.5 | 32k | Strong benchmarks |
| Gemma 3 | Gemma 3 + SigLIP | 128k | Small, multilingual |
| Llama 4 | Early-fusion MoE | 1M+ | Natively multimodal |
| Pixtral | Mistral + ViT | 128k | Multi-image |
| LLaVA-OneVision | Qwen2 + SigLIP | 32k | Research-friendly, video |
Embedding Models (Open)
| Model | Dim | License | Notes |
|---|---|---|---|
BAAI/bge-large-en-v1.5 | 1024 | MIT | Top English retrieval |
BAAI/bge-m3 | 1024 | MIT | Multilingual, multi-task |
nomic-embed-text-v1.5 | 768 | Apache 2 | Long context (8k) |
intfloat/multilingual-e5-large | 1024 | MIT | 100+ languages |
Alibaba-NLP/gte-large-en-v1.5 | 1024 | Apache 2 | Strong all-around |
Image Generation (Open)
| Model | Type | Notes |
|---|---|---|
| Stable Diffusion 1.5 | Latent diffusion | Classic baseline |
| SDXL | Latent diffusion | Higher quality, 1024px |
| Stable Diffusion 3.5 | Flow matching | Better text rendering |
| Flux.1 / Flux.1 Kontext | Flow matching, DiT | Top open image gen; Kontext adds editing |
| Qwen-Image | MMDiT | Strong text rendering (2025) |
| SDXL-Turbo / LCM | Distilled SD | 1–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
| Format | Size (7B) | Quality vs. FP16 | Use When |
|---|---|---|---|
| Q8_0 | 7.7 GB | Near identical | High-end GPU |
| Q6_K | 5.9 GB | Excellent | 8 GB VRAM |
| Q5_K_M | 5.1 GB | Very good | 8 GB VRAM |
| Q4_K_M | 4.4 GB | Good | 6–8 GB VRAM |
| Q3_K_M | 3.5 GB | Acceptable | 4–6 GB VRAM |
| Q2_K | 2.9 GB | Degraded | CPU 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
| Resource | URL | Purpose |
|---|---|---|
| HuggingFace Hub | huggingface.co | Model hosting, datasets, spaces |
| LMSYS Chatbot Arena | lmarena.ai | Human preference leaderboard |
| Artificial Analysis | artificialanalysis.ai | Quality/speed/price comparisons |
| MTEB Leaderboard | huggingface.co/spaces/mteb/leaderboard | Embedding model ranking |
| Ollama | ollama.com | Local model runner |
| LM Studio | lmstudio.ai | GUI for local models |
| bartowski / unsloth | HF profiles | GGUF 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
| Priority | Recommended |
|---|---|
| Best quality, any size | DeepSeek-V3.1 / R1, Kimi K2, or Qwen3-235B-A22B |
| Fits one 80 GB GPU | gpt-oss-120b (MoE) or Qwen3-32B |
| Best ~70B / 32B class | Llama 3.3 70B (dense) or Qwen3-32B |
| Best small (~8B) | Qwen3-8B, Llama 3.1 8B, or Gemma 3 12B |
| Run on CPU / laptop | Gemma 3 4B, Qwen3-4B, or Phi-4-mini (Q4 GGUF) |
| Code generation | Qwen3-Coder or DeepSeek-V3.1 |
| Math / reasoning | DeepSeek-R1 (or its distills), Qwen3 thinking mode, gpt-oss |
| Vision-language | Qwen2.5-VL, InternVL3, or Gemma 3 27B |
| Embeddings | Qwen3-Embedding or BGE-M3 |
| Image generation | Flux.1-schnell / Kontext or SD 3.5 |