Language models, retrieval, prompting, and language adaptation · Instruction, preference, and parameter-efficient adaptation · LNG070 · Training method
Houlsby adapters
Inserts small trainable bottleneck modules into a pretrained network while largely freezing existing weights. Each task stores adapter parameters, enabling modular transfer without copying all model weights.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Inserts small trainable bottleneck modules into a pretrained network while largely freezing existing weights. Each task stores adapter parameters, enabling modular transfer without copying all model weights.
Question / objective
Can small residual bottleneck modules adapt a pretrained encoder while preserving its base weights?
Architecture / computational structure
Inserted down-projection/nonlinearity/up-projection modules add residual corrections; original model matrices can remain frozen. Learned adapter matrices, biases, and optional heads differ from bottleneck width and placement hyperparameters.
Assumptions
Added modules introduce inference operations and may bottleneck difficult distribution changes.
Formula / computational definition
An adapter computes h'=h+W_up f(W_down h+b_down)+b_up, with bottleneck width m much smaller than hidden width d. The residual form supports initialization close to the identity mapping.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Bottleneck width, insertion locations, nonlinearity, initialization, trainable normalization/head settings, learning rate, and task-specific adapter selection.
Fitting, fine-tuning, and adaptation
Fit adapters and a task head with the appropriate supervised or self-supervised loss, keeping the base frozen unless explicitly specified. Tune bottleneck width and learning rate, validate latency and accuracy, and test task switching. If composing adapters, evaluate interference instead of assuming modularity guarantees independence.
How to use and calibrate
Compare task accuracy, trainable parameter counts, latency, storage across tasks, and transfer/forgetting when adapters are swapped. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Serve several classification tasks using one shared encoder and separate small adapters.
Interpretation / pitfalls
Watch out
Different adapter placements are not interchangeable; adapter composition can create interference unless trained and evaluated explicitly. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use a documented adapter library or explicit PyTorch/R torch modules; do not assume every PEFT release provides every adapter variant. R can implement the residual bottleneck natively. The example computes one adapter forward pass with fixed toy matrices.
Example scope: Houlsby-style residual bottleneck forward pass with fixed toy matrices.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Houlsby-style residual bottleneck forward pass with fixed toy matrices.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
h = [0.4,-0.2]
z = max(dot([0.5,0.3],h),0)
out = [h[0]+0.2*z,h[1]-0.1*z]
print(out)
Component demo, not a trained model — Houlsby-style residual bottleneck forward pass with fixed toy matrices.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
h <- c(0.4,-0.2)
z <- max(sum(c(0.5,0.3)*h),0)
out <- h+c(0.2,-0.1)*z
print(out)
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG070.