Module 7 cheat sheet: Pretrained Models & LLMs

Use pretrained models from the Hugging Face Hub, control their output with decoding settings, shrink them with quantization, and measure them properly.

All modules๐Ÿ“– Glossary

Key ideas

  • Autoregressive models predict the next token (GPT); autoencoding models fill blanks (BERT). S23 โ†’
  • Read the model card: task, size, licence and limits. S23 โ†’
  • pipeline() is the fastest start; AutoTokenizer + AutoModel give full control. S23 โ†’
  • Choose closed APIs or open weights by quality, cost, privacy and control. S24 โ†’
  • Adaptation ladder: prompting โ†’ RAG โ†’ PEFT โ†’ full fine-tuning. S25 โ†’

Memory rule of thumb

GPU memory โ‰ˆ parameters ร— bytes per parameter
PrecisionBytes7B model
FP324~28 GB
FP16 / BF162~14 GB
INT81~7 GB
INT4 (GGUF, AWQ, GPTQ)0.5~3.5โ€“4 GB

Add extra for the KV cache and activations.

Decoding settings

SettingWhat it doesUse for
GreedyAlways the top tokenShort factual answers
Beam searchKeeps several candidate sentencesTranslation
TemperatureLow = focused, high = varied0โ€“0.3 facts/code; 0.7โ€“1 creative
Top-k / top-pLimit choices to the likeliest tokensCreative text without nonsense
Repetition penaltyDiscourages repeatingStops loops

Evaluation metrics

MetricMeasuresWatch out
PerplexityHow surprised the model is by real text (lower = better)Says nothing about truth
BLEUWord overlap with a reference (translation)Misses correct paraphrases
ROUGEOverlap focused on recall (summaries)Same as BLEU
Human / LLM judgeHelpfulness, correctness, toneNeeds clear rubric

Code: three lines with Hugging Face

# pip install transformers torch
from transformers import pipeline
sentiment = pipeline("sentiment-analysis")
print(sentiment("The new UPI app is super fast and easy to use!"))

No API key needed: the model downloads from the Hub.

Common mistakes

  • High temperature for facts or code: more random, more mistakes.
  • Judging a model on BLEU/ROUGE alone.
  • Ignoring the licence on the model card before using it at work.
  • Estimating memory from parameters only and forgetting the KV cache.

Created by Ajeetkumar ยท EasyLearnSpace