Pretrained physics models
Pretraining on many simulations, then fine-tuning on a new case with little data.
Outcome: Explain pretraining on many simulations and fine-tuning on a new case; write a fine-tuning recipe: load weights, new head, freeze, train the head, then optionally unfreeze at a very small learning rate; judge a pretraining claim: equal data, held-out physics, compute; read a learning curve, and say why more cases of one design family do not teach another.
Builds on Self-attention and the transformer, Training on industrial meshes
Every model so far was trained from scratch on one problem's data. In language and vision, a common recipe is different: pretraining, then fine-tuning.
DefinitionPretraining and fine-tuning
The same recipe is being tried in physics. A model that has seen many flows, plasmas and reaction–diffusion systems may have learned something general about transport, waves and boundary layers, and need fewer expensive runs. In the news the idea appears under names such as “Large Physics Models” (PhysicsX, Luminary's SHIFT-NVH).
Pretraining data
The Well (Polymathic AI, 2024) collects about 15 TB of simulations across many physics in one format. Models pretrained on such collections usually work on regular grids and cut each field into patches, small square blocks of cells that each become one token. PDE-Transformer (Holzschuh et al. 2025) is one of them: its authors report better results with pretraining than from scratch on three 2D tasks from The Well.
Fine-tuning, step by step
- Load the pretrained weights.
- Replace the output layer (the head) with one for the new quantities.
- Freeze the rest and train only the head, at an ordinary learning rate: it starts from random weights. With few runs, updating millions of weights can overfit fast and can erase what pretraining learned. Freezing is only a starting point, to be checked on held-out designs. Keum and Warey (2026) adapted a car-aerodynamics transformer, pretrained on 411 cases of four vehicle families, to a held-out family with 20 samples: they report that the frozen encoder failed, that full fine-tuning was unstable, and that low-rank adapters (LoRA) in every layer worked.
- Once the head has converged, optionally unfreeze everything and continue with a very small learning rate. Keep this step only if validation improves.
A rehearsal on the aircraft
The course’s runs can rehearse the recipe, though not the scale. Example 9-1 treats the 22 Latin-hypercube runs with as the pretraining set and 4 runs with as the new problem, and scores every step on the other 18 runs with .
Example 9-1. Pretrain on part of the aircraft’s runs, then fine-tune on four others, with PyTorch
import numpy as np
import torch
from torch import nn
from aircraft import load_runs, split_runs
torch.manual_seed(0)
d = load_runs()
train, val, test, in_box = split_runs(d)
alpha, sweep, cp = d["alpha"], d["sweep"], d["cp"]
lhs = np.sort(np.r_[train, val]) # the 44 LHS runs
pre = lhs[sweep[lhs] <= 28] # stands in for "many simulations"
new = lhs[sweep[lhs] > 28] # stands in for "a new case"
tune, held = new[:4], new[4:] # fine-tune on 4, score on 18
# One row per surface point: xyz, normal, alpha, sweep -> cp.
design = np.repeat(np.c_[alpha, sweep][:, None], cp.shape[1], 1)
X = np.concatenate([d["xyz"], d["normal"], design], -1)
mu = X[pre].reshape(-1, 8).mean(0)
sd = X[pre].reshape(-1, 8).std(0)
X = torch.tensor((X - mu) / sd, dtype=torch.float32)1
Y = torch.tensor(cp, dtype=torch.float32)[..., None]
# A point-wise field model, an encoder and a head: the neural
# field of 4.5 without its Fourier features.
class Model(nn.Module):
def __init__(self, width=128):
super().__init__()
self.encoder = nn.Sequential(
nn.Linear(8, width), nn.SiLU(),
nn.Linear(width, width), nn.SiLU(),
nn.Linear(width, width), nn.SiLU())
self.head = nn.Linear(width, 1)
def forward(self, x):
return self.head(self.encoder(x))
def fit(model, runs, params, lr, steps):
opt = torch.optim.Adam(params, lr=lr)
x, y = X[runs].reshape(-1, 8), Y[runs].reshape(-1, 1)
for _ in range(steps):
i = torch.randint(0, len(x), (1024,))
loss = nn.functional.mse_loss(model(x[i]), y[i])
opt.zero_grad()
loss.backward()
opt.step()
def rel_l2(model, runs): # mean relative L2 error per run
with torch.no_grad():
err = (model(X[runs]) - Y[runs]).norm(dim=(1, 2))
return (err / Y[runs].norm(dim=(1, 2))).mean().item()
# 1. "Pretrain" on the runs with sweep <= 28 degrees.
model = Model()
fit(model, pre, model.parameters(), 3e-3, 3000)
torch.save(model.state_dict(), "pretrained.pt")
print(f"pretrained only {rel_l2(model, held):.1%}")
# 2. Load the weights, a new head, freeze the encoder.
model = Model()
model.load_state_dict(torch.load("pretrained.pt"))
model.head = nn.Linear(128, 1)2
model.encoder.requires_grad_(False)3
fit(model, tune, model.head.parameters(), 3e-3, 1000)4
print(f"fine-tuned head {rel_l2(model, held):.1%}")
# 3. Optionally unfreeze everything, very small learning rate.
model.encoder.requires_grad_(True)
fit(model, tune, model.parameters(), 3e-5, 1000)5
print(f"then unfrozen {rel_l2(model, held):.1%}")
# 4. The same network from scratch on the same 4 runs.
scratch = Model()
fit(scratch, tune, scratch.parameters(), 3e-3, 3000)
print(f"from scratch {rel_l2(scratch, held):.1%}")
- The inputs are normalised with the statistics of the pretraining runs and kept for every later step: the Watch out above, in code.
- Assigning a new
nn.Linearreplaces the head, with fresh random weights. The encoder keeps the pretrained ones. requires_grad_(False)freezes the encoder: autograd computes no gradients for its weights.- Only the head’s parameters reach the optimiser, at an ordinary learning rate.
- Step 4 of the recipe: every parameter, at a learning rate a hundred times smaller.
pretrained only 12.4% fine-tuned head 9.9% then unfrozen 8.3% from scratch 17.9%
Example 9-1 prints the mean relative L2 error over the 18 held-out runs. Fine-tuning on four runs takes it from 12.4 % (pretrained alone) to 8.3 % after unfreezing; trained from scratch on the same four, the network reaches 17.9 %. On seeds 1 and 2 the four rows come in the same order. The 18 runs decide whether to keep the unfrozen step and also score it; a real study would hold out a separate test set. The pretrained network beats the one from scratch even before it is fine-tuned, because here the new problem lies close to the pretraining data: one solver and one aircraft, a far smaller shift than between two kinds of physics.
Judging a pretraining claim
Three checks apply. The model should be compared with the same architecture trained from scratch on exactly the fine-tuning data, tuned with equal care. It should be tested on equations, geometries or regimes outside the pretraining set; otherwise it may have seen the problem before. And the cost of pretraining counts: a gain that needs a thousand GPU-days of pretraining may not pay for one product line.
A claim that more data will close a gap is read from a curve of test error against the number of training cases, also called a learning curve (the curves of overfitting plot the loss against the training step). In deep learning such curves often fall as a power law over a wide range before they flatten (Hestness et al. 2017). A curve measured on one design family describes that family only: more cases of it do not teach the model about another family or regime. The other family has to be in the training data, pretraining or fine-tuning, and whether the model reaches it without having seen it is tested only by a split that holds it out (train, validation and test).