Key terms for this tutorial
Here are the words that matter most in this tutorial. Come back here if a term feels fuzzy.
- epoch
- One full pass through the entire training dataset.
- inference
- Using a trained model to make predictions on new inputs.
- loss
- A number that measures how wrong the model is. Training tries to minimize loss.
- model
- A function with learnable parameters that maps inputs to outputs.
- tensor
- A multi-dimensional array of numbers, the basic data type in deep learning.
- weight
- A learnable number inside a model that is adjusted during training.
- checkpoint
- A saved copy of model weights at a specific step. Checkpoints let you resume training or roll back.
- MLOps
- Machine-learning operations: the tools and practices that move models from experiments to production.
Experiment tracking
Tools like Weights & Biases and MLflow log hyperparameters, metrics, and model artifacts. Without logs you cannot compare runs or reproduce results.
import wandb
wandb.init(project='ai-engineer-demo', config={'lr': 1e-3, 'epochs': 3})
for epoch in range(3):
wandb.log({'epoch': epoch, 'loss': 0.7 - 0.05 * epoch})
wandb.finish()
print('logged')
logged
Line-by-line: tracking.py
Read this slowly. Each line does one small, concrete thing.
import wandb— Import thewandblibrary so we can use its built-in tools.for epoch in range(3):— Start the training loop. Each epoch is one full pass through the dataset.print('logged')— Print a result so we can see what the model learned.
Pop-in: You are seeing the same loop again
Almost every deep-learning script repeats the same four steps: predict, compute loss, backpropagate, update weights. Once you can spot that pattern, the rest is just details.
Stuck or curious? Explain this to me on ChatGPT
Prompt: I am a beginner AI engineer working through the CodeHS tutorial 'AI Engineer: MLOps and Deployment'. Explain the section 'Experiment tracking' in plain English. Include simple analogies, vocabulary definitions, and a short example. Also walk through the code example in this section step by step.
Quantisation and ONNX
Quantisation reduces weight precision from 32-bit floats to 8-bit or 4-bit integers. This shrinks model size and speeds up inference. ONNX is a standard format that lets models run in many runtimes.
import torch
import torch.onnx
model = torch.nn.Linear(10, 1)
dummy = torch.randn(1, 10)
torch.onnx.export(model, dummy, 'model.onnx', input_names=['x'], output_names=['y'])
print('exported to model.onnx')
exported to model.onnx
Line-by-line: onnx.py
Read this slowly. Each line does one small, concrete thing.
import torch— Import thetorchlibrary so we can use its built-in tools.import torch.onnx— Import thetorchlibrary so we can use its built-in tools.model = torch.nn.Linear(10, 1)— Add a linear layer that multiplies inputs by a weight matrix and adds a bias.dummy = torch.randn(1, 10)— Create a tensor filled with random numbers to use as fake data or initial weights.print('exported to model.onnx')— Print a result so we can see what the model learned.
Pop-in: Models are useless if no one can call them
Training is only half the job. Deployment wraps the model in an API or a compact file so applications can use it.
Stuck or curious? Explain this to me on ChatGPT
Prompt: I am a beginner AI engineer working through the CodeHS tutorial 'AI Engineer: MLOps and Deployment'. Explain the section 'Quantisation and ONNX' in plain English. Include simple analogies, vocabulary definitions, and a short example. Also walk through the code example in this section step by step.
Serve with FastAPI
A deployed model is just an HTTP endpoint that loads a checkpoint, runs inference, and returns a result. FastAPI is a common choice because it is fast and auto-documents the API.
from fastapi import FastAPI
import torch
app = FastAPI()
model = torch.nn.Linear(10, 1)
@app.post('/predict')
def predict(x: list[float]):
with torch.no_grad():
tensor = torch.tensor([x], dtype=torch.float32)
out = model(tensor)
return {'prediction': out.item()}
print('endpoint defined')
endpoint defined
Line-by-line: serve.py
Read this slowly. Each line does one small, concrete thing.
from fastapi import FastAPI— Import tools from thefastapipackage.import torch— Import thetorchlibrary so we can use its built-in tools.app = FastAPI()— Create a web API with FastAPI so other programs can call the model over HTTP.model = torch.nn.Linear(10, 1)— Add a linear layer that multiplies inputs by a weight matrix and adds a bias.def predict(x: list[float]):— Define thepredictfunction, which describes a step in the data or model pipeline.with torch.no_grad():— Disable gradient computation during evaluation to save memory and speed.tensor = torch.tensor([x], dtype=torch.float32)— Create a PyTorch tensor from raw Python numbers.print('endpoint defined')— Print a result so we can see what the model learned.
Pop-in: Models are useless if no one can call them
Training is only half the job. Deployment wraps the model in an API or a compact file so applications can use it.
Stuck or curious? Explain this to me on ChatGPT
Prompt: I am a beginner AI engineer working through the CodeHS tutorial 'AI Engineer: MLOps and Deployment'. Explain the section 'Serve with FastAPI' in plain English. Include simple analogies, vocabulary definitions, and a short example. Also walk through the code example in this section step by step.
Check yourself
Why log experiments?
What is the benefit of tools like WandB or MLflow?
They capture hyperparameters, metrics, and artifacts so you can compare runs, reproduce results, and collaborate.
Stuck or curious? Explain this to me on ChatGPT
Prompt: I am a beginner AI engineer studying 'AI Engineer: MLOps and Deployment'. The practice question 'Why log experiments?' asks: What is the benefit of tools like WandB or MLflow? The answer is: They capture hyperparameters, metrics, and artifacts so you can compare runs, reproduce results, and collaborate.. Explain the concept behind this in simple terms.
Stuck or curious? Explain this to me on ChatGPT
Prompt: I am a beginner AI engineer working through the CodeHS tutorial 'AI Engineer: MLOps and Deployment'. Explain the section 'Check yourself' in plain English. Include simple analogies, vocabulary definitions, and a short example.
Three questions
1. What is ONNX?
Stuck or curious? Explain this question to me on ChatGPT
Prompt: I am a beginner AI engineer studying 'AI Engineer: MLOps and Deployment'. The quiz asks: What is ONNX? The correct answer is: A portable model exchange format for inference runtimes. Explain why that answer is right and why the other choices are wrong, using a simple example.
2. What does quantisation do?
Stuck or curious? Explain this question to me on ChatGPT
Prompt: I am a beginner AI engineer studying 'AI Engineer: MLOps and Deployment'. The quiz asks: What does quantisation do? The correct answer is: Reduces weight precision to shrink models and speed inference. Explain why that answer is right and why the other choices are wrong, using a simple example.
3. Why use experiment tracking?
Stuck or curious? Explain this question to me on ChatGPT
Prompt: I am a beginner AI engineer studying 'AI Engineer: MLOps and Deployment'. The quiz asks: Why use experiment tracking? The correct answer is: To reproduce and compare training runs. Explain why that answer is right and why the other choices are wrong, using a simple example.
Keep learning
Next: build AI agents that use tools.
Part of the CodeHS tutorial library.