Free self-study · No account needed · Progress stays in this browser. Back it up before clearing site data or changing devices.

← Week 22: Fine-Tuning and Adaptation

Week 22 / Lesson 3

Evaluating specialization and forgetting

Compare the adapted model with its base on target tasks and preserved capabilities.

Section 3.1 1 of 7

Overview

Focus

Compare the adapted model with its base on target tasks and preserved capabilities.

Your route through the lesson

  • 3.2 Overfitting and validation behavior
  • 3.3 Catastrophic forgetting and regression slices
  • 3.4 Adapter compatibility, release records, and rollback
  • 3.5 Put it into practice
  • 3.6 Guided comparison
  • 3.7 Target-task gains with lost general capability

All required teaching is included here. Review selections are saved. Choose a correct answer for every question to continue; retries are unlimited. Study time and personal notes are optional.

Section 3.2 2 of 7

Overfitting and validation behavior

Focus

Detect overfitting by separating training improvement from reserved behavior.

Overfitting occurs when optimization captures training-specific patterns that do not transfer to the intended unseen cases. Training loss can keep falling while validation loss rises. This does not mean optimization failed to reduce the objective; it means the objective's training examples no longer represent generalization well enough.

Compare the base and adapted models on identical reserved inputs using the same decoding or numeric evaluation settings. Record per-case results and sample counts. Do not select the best checkpoint using the final test and then call that score untouched. Use validation for checkpoint selection and reserve testing for the final declared comparison.

In the tiny numeric lab, training uses coordinate magnitudes one. Reserved cases use magnitudes two, which were never training rows. That checks a limited form of extrapolation for a linear mapping. It does not establish language generalization, robustness to arbitrary input distributions, or deployment readiness. The baseline identity matrix provides a measurable starting error on the changed coordinate, so the adapted model's gain can be computed rather than assumed from a lower training loss.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Training loss falls while validation error rises. What is a likely concern?
2. A checkpoint is chosen using final test scores repeatedly. What was lost?
3. Training magnitudes are one and reserved magnitudes are two in a linear lab. What is tested?

Section 3.3 3 of 7

Catastrophic forgetting and regression slices

Focus

Evaluate preserved capabilities separately from the specialization target.

Catastrophic forgetting describes a substantial loss of previously useful behavior after adaptation. Even with a frozen base, an enabled adapter can change outputs enough to harm earlier capabilities. Frozen storage does not mean preserved deployed behavior because prediction uses the base plus the learned update.

Define a target slice and a preservation slice before training. A target slice might require doubling the first coordinate; a preservation slice might require leaving the second coordinate unchanged. For a language system, target cases could check a narrow document format while preservation cases check factual summaries, refusals, and tool argument validity. Keep their metrics separate.

A candidate that gains ten target points but loses all permission denials should fail its security gate. Averaging slices can hide that tradeoff. Report both absolute scores and changes from the same base release. If an adapter is optional per request, verify that disabling it restores the actual base path and does not leave merged weights or stale cache behavior active. The absence of one observed regression does not prove all general capabilities were preserved.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Base weights are frozen but an enabled adapter harms a prior task. Is that possible?
2. Target quality rises but required denial quality collapses. What should happen?
3. Disabling an adapter should restore what?

Section 3.4 4 of 7

Adapter compatibility, release records, and rollback

Focus

Tie evaluation and rollback to the exact adapter, base, schema, and release record.

An adapter release record links dataset revision, source split, training configuration, random seed, base identity, factor checkpoint, and evaluation results. Reproducibility needs both configuration and executed evidence. A seed helps control randomness but does not guarantee bitwise equality across every hardware and library version.

Compatibility checks run before evaluation. Compare the recorded base and input schema, load factors into a fresh model, and verify a known output. Then evaluate target and preservation slices. If the checkpoint is incompatible, the correct result is rejected loading, not a low quality score from an unintended model combination.

Rollback may disable the adapter or restore a compatible previous base-adapter pair. Verify both outputs and active manifest. In language applications, also check tokenizer, template, target modules, and whether factors were merged into base weights. Removing a file does not necessarily remove an already loaded update. The local numeric lab makes rollback visible through an enabled argument that chooses base-only computation. That is a deliberate design contract, not a universal property of every adapter runtime.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. A seed is fixed but hardware and library versions differ. What is still needed?
2. A checkpoint fails base compatibility. How should evaluation proceed?
3. An adapter file is deleted while a service keeps loaded factors. What has removal proved?

Section 3.5 5 of 7

Put it into practice

Focus

Run real base-versus-adapter checks on reserved numeric inputs and verify removal.

After explicit processor PyTorch installation, save week22.py and run python week22.py --lesson 3 --train in that environment. The script performs a real small training run, saves and reloads the factors, and evaluates reserved magnitudes. Without --train, it prints that real evaluation remains pending instead of returning prerecorded scores.

torch.no_grad() disables gradient tracking during evaluation, reducing unnecessary training bookkeeping. Mean squared error is computed on target and preservation arrays separately. The target cases ask for first-coordinate doubling; the preservation cases keep the second coordinate unchanged. Expected assertions require target error below one hundredth of base target error and preservation error below 0.001.

Finally, model(target_x, False) bypasses the adapter. Its outputs must exactly equal the identity base's outputs. The printed record labels the run as real reserved numeric evaluation and states that it is not language-model quality evidence. Extend the same artifact with an intentionally harmful rank-one update on the preserved coordinate, then verify that a preservation gate rejects it. Keep the original reserved cases unchanged.

Download this week’s Python lab ↓

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. What does torch.no_grad do during evaluation?
2. A script computes adapted reserved scores only inside its --train branch and otherwise reports them pending. The command omits --train. Were those scores measured?
3. A bypassed identity base returns the original input exactly. What does that check?

Section 3.6 6 of 7

Guided comparison

Focus

Read separate task gains, preservation errors, and reload evidence.

The worked base maps each numeric input to itself. For an input [2,0], its prediction [2,0] differs from the target [4,0]. The adapted model learns an update that approximately doubles the first coordinate. Target error therefore has a meaningful nonzero baseline and should decrease after actual training.

For a preservation input [0,2], the desired output remains [0,2]. The adapter must avoid changing this direction appreciably. The assertion uses a small tolerance rather than requiring every learned floating-point value to be mathematically exact. Reload equality separately confirms that the saved factors reproduce the trained model under the same base and schema.

The report should not collapse these results into one triumphant average. Low target error, bounded preservation error, reload agreement, and base-only restoration answer different questions. A candidate can pass any three and fail the fourth. Keep initial and final training losses as training evidence, reserved errors as generalization evidence, and exact base equality as a frozen-parameter invariant. That separation makes failures diagnosable and prevents one successful number from standing in for the entire adaptation workflow.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. The identity base sees [2,0] with target [4,0]. Why is there baseline error?
2. A model reloads exactly but harms preservation cases. What passed?
3. Why use a tolerance for learned preservation error?

Section 3.7 7 of 7

Target-task gains with lost general capability

Focus

Reject specialization gains that destroy a previously required capability.

A support classifier improves its target label accuracy from seventy to ninety percent after adaptation. On a reserved permission slice, correct refusals fall from one hundred to sixty percent. The target gain is real, but the candidate now violates a mandatory boundary. Reporting only the target score would misrepresent deployment suitability.

The release record presents both slices with counts, fixed cases, and the same base reference. The security gate rejects the adapter. The operator disables it, verifies base-only predictions on known cases, and reruns the refusal slice through the actual executor. If the adapter had been merged into weights, restoration would require loading the clean base artifact rather than merely changing an enable flag.

Failure analysis asks whether the training data rewarded over-compliance, omitted denial examples, or changed the input contract. Those are hypotheses to test on development data. Do not tune directly against the reserved slice until it becomes an undeclared training signal. The next candidate needs fresh reserved evidence or an explicit evaluation revision. A good adaptation result improves the intended behavior while preserving the requirements that made the original system safe to operate.

// Quick review

Check your understanding.

Choose an answer for immediate feedback. Retry freely; a correct answer for every question unlocks the next section.

1. Target accuracy rises to 90 percent but required refusals fall to 60 percent. What is justified?
2. An adapter was merged into base weights. What rollback may be necessary?
3. A team repeatedly fixes errors from the reserved refusal slice. What must be acknowledged?

Your personal notes

Optional, ungraded, and saved only in this browser. Export a backup from the Academy homepage to keep them.

References and further reading
Ask your own AI assistant

Copy this prompt into an assistant you already use. Nothing is sent automatically, and your personal notes are not included.

Next lesson: Designing an authorized request path →