MRS Spring 2026, Part I of III

Foundation Models Adaptation I: prompting, features, and fine-tuning

From zero-shot prompting to few-shot examples, frozen features, and LoRA fine-tuning: a map of the adaptation strategies, what they change, and what they cost. Adapted from MRS Spring 26 MT01 tutorial materials.

01

Where foundation models fit in

Foundation models are deep-learning models trained broadly once, then adapted many times for specific tasks.

Artificial intelligence
systems that perform useful tasks
Machine learning
models that learn from data
Deep learning
models that learn representations
Foundation models
broad pretraining reused for many tasks
language
vision
multimodal
reasoning
generation
science
02

What foundation models can do

A pretrained model can help with routine analysis, natural-language interfaces, and discovery workflows when the task is well defined.

Automate routine tasks

Summarize, classify, extract, write code, and check repeated analysis steps.

Create natural interfaces

Let scientists ask for analysis, metadata, and visual explanations in normal language.

Accelerate discovery

Combine search, simulation, and experiment loops around measured outputs.

03

Pretraining is done once. Adaptation happens in the lab.

Model providers usually handle broad pretraining. Scientific users decide how the model is adapted, tested, and used.

Provider
Pretrain

model learns broad patterns from large datasets

Lab
Adapt

choose prompts, examples, features, or adapters

Workflow
Deploy

use only after behavior has been measured

Risks
  • Domain mismatch
  • Hallucinations
  • Hidden failure modes
Strategy
  • Benchmark first
  • Adapt if needed
  • Scaffold with workflows
04

The adaptation landscape

This map compares strategies by how much they change the input, how much they change the model, and how much work they require.

less task data
more task data
less trainable compute
more trainable compute

Describe the task and ask the model. Model weights do not change. Useful as a baseline even when you expect it to fail.

labels
0
compute
API or local CPU
iteration
seconds
Good for
  • fast triage
  • format testing
  • early prototyping
Weak points
  • unstable formats
  • hallucinated labels
  • weaker domain grounding

Click a strategy to compare its costs. More expensive is not automatically better: move to heavier methods only when simpler ones stop making real progress.

Figure 1 The adaptation landscape. Click a strategy; the detail panel reports what changes (input, weights, or both) and roughly what it costs.
05

Compute and memory trade-offs

Labels, compute, and iteration time change quickly as you move from prompting to adapters and full fine-tuning.

01
Zero-shot prompt (API)
labels
0
compute
remote API, no local compute
iteration
seconds
02
Zero-shot prompt (local)
labels
0
compute
GPU not necessary, CPU works
iteration
seconds
03
Few-shot prompt (API)
labels
5–50
compute
remote API, no local compute
iteration
seconds / minutes
04
Few-shot prompt (local)
labels
5–50
compute
GPU not necessary, CPU works
iteration
seconds / minutes
05
Frozen features
labels
100 – 10k
compute
encoder needs GPU for forward pass
iteration
minutes
06
LoRA fine-tune (bf16)
labels
1k – 100k
compute
multi-GPU for 7B+ in bf16
iteration
hours
07
QLoRA fine-tune (int4)
labels
1k – 100k
compute
single GPU (int4 quantized base)
iteration
hours
08
Full fine-tune
labels
10k – millions
compute
multi-GPU cluster (all weights)
iteration
days
06

Strategy 0: zero-shot prompting

A good prompt states the task, goal, context, and constraints clearly. Start simple before adding fragile prompt tricks.

Simple baseline

Given this diffraction image, identify every anomaly that applies.

01
Task

What should the model do?

02
Goal

What counts as a useful answer?

03
Context

What domain facts or label definitions matter?

04
Specs

What constraints, units, or format should be respected?

Good for
  • Fast triage
  • Format testing
  • Early prototyping
weak points
  • Unstable formats
  • Hallucinated labels
  • Weaker domain grounding
Prompt engineering is useful when it clarifies the interface. Newer reasoning models may be less sensitive to highly engineered prompts, so extra prompt details should earn their place.
07

Ask for structured outputs

For automation, the answer needs to be easy to parse and check. A schema helps downstream code trust what it receives.

JSON mode
response_format={"type": "json_object"}

{
  "wavelength_A": 0.9763,
  "detector_distance_mm": 250.0,
  "beam_center_px": [1024, 1024],
  "exposure_s": 0.5
}

Simple and low-boilerplate, but you still need to validate the fields.

Structured outputs
class XRDMetadata(BaseModel):
    wavelength_A: float
    detector_distance_mm: float
    beam_center_px: tuple[int, int]
    exposure_s: float | None = None

response_format=XRDMetadata

More setup, but the response is easier to check and use in Python.

Gate 1
schema
Gate 2
parser
Gate 3
validator
08

Few-shot prompting

Few-shot prompting puts worked examples in the prompt. The model weights do not change.

support image for multimodal few-shot prompting
support image
blurry; losing features
support image for multimodal few-shot prompting
support image
major features; low contrast
support image for multimodal few-shot prompting
support image
dark halo artifacts
query image for multimodal few-shot prompting
query image
model predicts labels
Multimodal few-shot pattern
Each support example pairs an image with the answer format you want. The query image comes after the examples, and the weights do not change.
teaches
  • Allowed label set
  • Expected answer format
  • Multi-label edge cases
cannot fix
  • A model that cannot read the pattern
  • Data leakage
  • An evaluation split that does not match the task
09

Frozen features

A scientific image becomes an embedding vector. A small classifier then works on those saved vectors.

image
image
Frozen encoder
Embedding
0.120.68-0.310.440.03-0.770.520.19
Small head: kNN / linear classifier / shallow MLP
embedding / featurizer
  • Numeric summary of an image
  • Similar images should be nearby
  • The classifier learns from vectors instead of raw pixels
Workflow
  • Run the pretrained encoder once
  • Save one vector per image
  • Train a small head on vectors + labels
  • Evaluate with the same split
10

Example clustering of embeddings

If the encoder is useful, visually similar diffraction patterns should sit near one another in embedding space.

Cluster 1
Cluster 2
Cluster 3
Cluster 4
Projected latent space
Projected embedding space with visible clusters.
11

kNN vs. linear probe

Both methods use the same saved embeddings. kNN predicts from nearby examples; a linear probe learns a simple boundary.

Embedding space, drag the query point
cleananomalous
linear boundary

Both methods read the same embedding. kNN votes with the 5 nearest labeled points; the linear probe only checks which side of its boundary you are on. Try the pocket of anomalous points at the bottom left: kNN follows the local labels, the linear probe cannot.

kNN (k = 5)
clean
1 of 5 neighbors anomalous
Linear probe
clean
side of the fixed boundary
They agree here

Move toward the boundary, or into the bottom-left pocket, to find where the two rules split.

kNN
Store labeled embeddings
Prediction comes from nearby labeled examples.
useful when labels change
linear probe
Learn a boundary
A small model learns a boundary in embedding space.
useful with enough labels
kNN watch-outs
  • Sensitive to noisy labels
  • Needs similarity search at inference
  • Does not give calibrated probabilities by default
linear probe watch-outs
  • Needs enough examples per class
  • Must be re-fit when labels change
  • Does not show similar examples by itself
Figure 2 Same embeddings, two classifiers. Drag the query point; kNN votes with its neighbours while the linear probe answers by which side of its boundary the point falls on, and the anomalous pocket shows where they disagree.
12

LoRA fine-tuning

LoRA keeps most model weights fixed and learns a small low-rank update for the task.

W
frozen base
+
B A
small trainable update
=
W + BA
adapted behavior
cost spectrum
  • Full fine-tune: update all weights
  • LoRA: train adapter matrices
  • QLoRA: quantized base plus LoRA adapters
rank r
  • Rank controls adapter size
  • Typical r = 8-32
  • Larger r adds flexibility and overfit risk
adapter files
  • Swap adapters without replacing the base model
  • Each task can have its own adapter
  • QLoRA stores the base in 4-bit and trains adapters in float16
13

Fine-tuning tools

There are many post-training methods beyond this tutorial. Open-source tools make them practical enough to try.

supervised tuning
SFTinstruction tuningadapter tuning
preference tuning
RLHFRLAIFDPOPPO / GRPO
efficient tuning
LoRAQLoRAprompt tuningprefix tuning
model editing
distillationreward modelingtool-use tuning
Useful open-source tools
PEFTTRLUnslothAxolotlVERL

These tools make experiments easier to run, but they do not replace clean splits, metrics, and ablations.