Quantization, Fine-Tuning, and Low-Rank Adaptation
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Pipeline parallelism with mini-batches and stages — covered in Lecture 1
- Mini-batches flowing through GPUs — covered in Lecture 1
- Model parallelism by pipeline split — covered in Lecture 2
Slicing a network across devices does not finish the cost story. Every remaining weight and gradient still occupies bits, and those bits still travel on a slow link. This lecture treats three families of cuts: quantization (fewer bits per number), fine-tuning and low-rank adapters (fewer trained numbers), and a short preview of pruning (fewer live weights).
6.1 Communication Bottlenecks After Model and Data Slicing
After you already split the model and split the data, what still dominates time and memory? The leftover payload: every weight and every gradient that you store and ship.
Distributed training solved two placement problems. It did not make the numbers themselves cheap. The rest of the session attacks that leftover cost.
6.1.1 Recap of Slicing, Mini-Batches, and Pipeline Handoffs
Model slicing (placing different layers, or stage blocks, on different devices) puts stage 1 on GPU 0, stage 2 on GPU 1, and later stages on later GPUs. Data slicing (splitting the training set into batches and then into mini-batches) feeds those stages a stream of small frames rather than one giant tensor. Call a mini-batch a successive data frame if that picture helps: frame 1, then frame 2, then frame 3.
A first mini-batch is processed on the first GPU. That GPU emits activations, the layer outputs. Those activations travel to the next GPU. The next GPU continues the forward pass. The chain repeats until the last stage produces a prediction.
After the last stage, the system computes a loss, a scalar that says how wrong the prediction is. Write for that scalar. Back propagation then attributes to each trainable weight. For every mini-batch and every layer, the system computes gradients, the partial derivatives of the loss with respect to the weights.
For a local weight on one pipeline stage, the gradient that must move is
Here is the loss after the last stage, is a trainable parameter that lives on this GPU, and is the number (or tensor of numbers) that earlier stages need in order to update . In a convolutional network the learnable objects are filters. In a fully connected network they are the link weights between nodes.
Those gradients must travel backward along the pipeline so earlier stages can update their weights. Picture a server plus a set of client devices. Each client holds part of the model. After a mini-batch, millions or billions of gradient numbers must move across the interconnect.
Pipeline patterns such as GPipe already showed this handoff: send a mini-batch forward, compute for the local parameters, then send those values back so earlier layers can adjust. GPU 0 processes batch one and sends the output onward. Later, the loss-driven gradients must return.
Think of a bucket brigade at a fire. Water (activations) moves forward from person to person. Empty buckets (gradients) must come back, or the front of the line cannot refill. The analogy breaks because empty buckets are light, while gradients are often as large as the weights themselves.
Two compression targets sit in that picture. You can compress the data representation, how each number is stored. You can compress the model, how many weights you store or update. Both attacks cut storage, arithmetic, and wire traffic.
6.1.2 What Must Be Stored and Moved
A modern network may have millions or billions of parameters. For each parameter you store a weight and you compute a gradient. Every GPU that shares work must exchange those gradients. After mini-batch one finishes on one GPU, the values go across the network to another GPU. That is where a network bottleneck appears: the interconnect is slower than on-device math, and the payload is huge.
The same numbers also occupy GPU memory. A 7 billion parameter model, an 8 billion parameter model, or a 120 billion parameter model makes the problem worse. Pre-trained large language models (LLMs) move enormous tensors during training and during serving. If you work with those models, gradient and weight traffic dominate cost.
A motivating question frames the rest of the material: after slicing, what is the main computational and communication factor you still have to address?
Imagine plotting two curves against model size. The horizontal axis is parameter count, from millions to hundreds of billions. The vertical axis is time per step. On-device multiply time grows, but interconnect time grows at least as fast, because the message is a full gradient tensor. The landmark is the crossing where wire time exceeds math time. Past that landmark, a faster GPU without a smaller message barely helps.
6.1.3 Student Questions and Answers
A natural first guess is that the hard part is still calculus: can we even form ? That guess is understandable, because back propagation is the engine. It is not the remaining bottleneck.
Q: Should the main issue be that back propagation must be differentiable?
A: Treat differentiability as already true. The pipeline assumes you can form gradients. The remaining bottleneck is how you represent those gradients and store encodings, and how you ship them between GPUs. You can store a number in FP32, FP16, integer-8, 4-bit, or even 1-bit form. The encoding choice changes memory and communication volume.
The correction is sharp. Differentiability is a prerequisite that the training stack already assumes. The new lever is the bit layout of each stored and sent number.
6.1.4 Representation as the Lever, and Today's Map
Computer-architecture courses already show number encodings. FP32 uses 32 bits per value. FP16 uses 16 bits. Integer formats use 8 bits, 4 bits, or 1 bit. The goal is to cut storage and communication overhead without destroying learning.
Scope: These encoding cuts assume that the optimizer still sees a usable update, and that the task can tolerate a small grid of representable numbers. If a detection task needs tiny mantissa changes, a 4-bit or 1-bit gradient can stall learning. If the interconnect is already faster than compute, shrinking bits saves memory but not wall-clock time.
On a sketch of one 32-bit word, the bits are not equal. Later sections split sign, exponent, and fraction. For now, hold the idea that "a number" is a labeled packet of bits, not a magic real value.
Pitfall: Treating slicing as the full solution. Pipeline stages still exchange full tensors. Pitfall: Counting only weights and forgetting that each training step also stores and ships gradients, and often optimizer buffers. Pitfall: Assuming a smaller encoding is free accuracy. Fewer bits delete information. You must measure whether the model still learns.
Three families of methods attack that overhead:
- Quantization changes how each number is encoded, so the same tensor uses fewer bits.
- Fine-tuning (and later parameter-efficient fine-tuning) changes which weights you update, so you do not train every parameter of a giant model.
- Pruning later removes or zeros redundant weights and filters. That family is only previewed here.
Exam note: The core distributed-training idea is that slicing is not enough. You still pay for every bit you store and every bit you send. Be ready to name the leftover payload as weights plus gradients on the reverse pipeline path.
GPU-to-GPU gradient exchange in pipeline-parallel training is the practical setting. The same bit-width choices also matter when a fine-tuned model must run on an edge device. NVIDIA mixed-precision training, which can keep some values in a 32-bit training format and shrink others to FP16, is the daily form of this lever in large-model stacks.
Slicing placed layers and mini-batches. The leftover problem is representation: how many bits each gradient and weight uses on the wire and in GPU memory. Next we open a 32-bit word and name its fields.
6.2 Floating-Point Layouts and Integer Encodings
Quantization only makes sense if you know what a "32-bit number" contains. This section opens the packet: sign, exponent, and fraction, then walks the same real value down to 16-bit and integer grids.
A 32-bit float is not 32 equal votes. One bit chooses the sign, a block of bits chooses the scale, and the rest choose the extra fraction. Change the block sizes and you change both range and precision.
6.2.1 Why Bit Layout Matters
A floating-point value is a sign bit, an exponent field, and a mantissa (fraction) field. The sign chooses positive versus negative. The exponent chooses the scale, a power of two. The mantissa chooses the extra fraction bits that sit after an implicit leading 1 in normal numbers.
Think of the layout as a labeled strip of bits. One bit is rose-colored for the sign. Eight bits are green for the exponent in FP32. The remaining yellow bits are the mantissa. Change how many bits each field gets, and you change both the range and the precision.
A postal address is a useful everyday map. The sign is the side of the street. The exponent is the city block (a power-of-two zoom). The mantissa is the house number on that block. The analogy breaks for subnormal numbers and infinities, which use reserved exponent patterns. For normal values the three-field picture is enough.
A first verbal slip in the walkthrough said that a sign bit of 0 means negative. The worked number then used sign . Standard IEEE-style encoding uses for negative and for positive. Keep the worked example. Treat the "0 means negative" line as a slip.
6.2.2 Mathematical Formulation of FP32
Let be the sign bit, the 8-bit exponent field read as an unsigned integer, and the 23-bit mantissa field read as an unsigned integer. For a normal FP32 value the decoded number is
The constant is the exponent bias for binary32 (IEEE FP32). The term rebuilds the significand with the hidden 1. The unbiased scale is .
The spoken formula was: minus one to the power of the sign, times two to the power of (the exponent value minus 127), times one plus the mantissa's decimal value divided by a power of two. One pass said "divided by 2" without the 23. The IEEE layout uses because there are 23 stored fraction bits. A denominator of would only be correct for a 1-bit fraction.
If every exponent bit is 0 except the highest, the 8-bit field is . Converting bit by bit, each position contributes . All zeros cancel. The remaining 1 at position 7 gives . Then the unbiased scale is
The verbal cue was "this is fixed": you always subtract 127 from the stored exponent in FP32 for normal numbers.
Assumption: The formula above is for normal numbers, where is not 0 and not 255. If , IEEE uses subnormals with no hidden 1 and scale . If , the encoding is infinity or NaN, not a finite weight. Training encodings usually stay in the normal range; a zero gradient is an all-zero bit pattern, which is a subnormal/zero case, not the hidden-1 formula.
Plot range against fraction bits. The horizontal axis is exponent-field width. The vertical axis is the largest finite . FP32 with 8 exponent bits reaches about . A 5-bit exponent (FP16) reaches only about . The landmark is overflow: values that fit in FP32 become inf in FP16. That is why some 16-bit formats keep eight exponent bits.
6.2.3 Worked Example: Encoding in FP32
Setup. Represent . The walkthrough filled three fields and then mixed them with the decode formula.
Step 1 — Sign. The number is negative, so . Then .
Step 2 — Exponent field as an integer. The green bits converted from binary to decimal as . A classroom prompt asked for . The answer is , which matches an exponent field with only the bit set.
Step 3 — Mantissa as an integer. The yellow bits converted to the decimal integer .
Step 4 — Combine. Using the FP32 rule with bias 127 and 23 fraction bits:
Now , so
The working value is , which is the IEEE binary32 encoding of . A rounded board figure was a display rounding of the significand; the three stored integers already decode exactly to this float.
Sense-check: the result is negative, near , and slightly coarse because only 23 fraction bits are stored. That is what you want from a real FP32 decode.
A binary-to-decimal converter is a valid check, but the formula above is the actual decode rule. You do not need to memorize converter websites. You do need the three fields and the bias.
6.2.4 FP16, BF16, and TF32 Variants
FP16 (IEEE binary16) uses 16 bits in total: 1 sign bit, 5 exponent bits, and 10 mantissa bits. The bias is 15, one less than in the same way 127 is one less than .
Here is still the sign bit, is the 5-bit exponent field as an integer, and is the 10-bit fraction as an integer. The hidden 1 is the same idea as FP32. Only the field widths changed.
The spoken decode for a 16-bit try on the same was: minus one to the power of the sign, times two to the power of (the stored exponent minus 15), times one plus divided by .
For that 16-bit packet, , , and the stored exponent is :
The same real value became about after the 16-bit encoding (). That is already a representation error, even before any extra rounding in later integer formats.
Sense-check: FP16 kept the exponent , so the value stayed near , but the shorter fraction drifted from to .
BF16 (bfloat16, spoken as "brain float 16") keeps a 16-bit total but spends the bits differently: 1 sign bit, 8 exponent bits, and 7 mantissa bits. The extra exponent bits keep FP32-like range. The shorter mantissa loses fraction detail.
For a normal bfloat16 value,
The exponent field is 8 bits with the same bias as FP32. The fraction has only 7 stored bits, so the divisor is , not .
One cross-check mixed a mantissa integer with a divisor and an 8-bit exponent. That mix collides FP16's 10-bit fraction with BF16's 8-bit exponent. If the integer is a 7-bit fraction, the correct divisor is :
Using would be the FP16 fraction rule applied to the wrong format.
TF32 (spoken as "TensorFlow 32") was listed as a 19-bit training format used on some GPU and TPU paths. A common industry layout for TF32 is 1 sign bit, 8 exponent bits, and 10 mantissa bits, which sums to 19. NVIDIA's name for that layout is TensorFloat-32. The class label "TensorFlow 32" is the same 19-bit idea: keep FP32's exponent width and FP16's fraction width.
Different vendors pick different default formats for GPU versus TPU training. Conversion among those formats is why quantization is not a side trick. It is the daily number-format layer of large-model training.
6.2.5 Integer Eight-Bit Range and Four-Bit Collapse
Signed INT8 does not store a hidden-1 fraction. It stores an integer in about 8 bits. One teaching picture uses 1 sign bit and 7 magnitude bits. The positive magnitudes sum to . The stated integer range to map into is .
Two's-complement INT8 still uses the range . The extra negative value is the extra code you get by not mirroring .
Integer values such as can land exactly. The pain starts when you force a float with a rich mantissa into a small integer grid.
A 4-bit signed picture uses 1 sign bit and 3 data bits. The maximum positive magnitude is .
A sample float (spoken as minus 8.978) cannot fit in a signed 4-bit grid whose positive cap is . The encoding snaps to magnitude with a negative sign, which is .
The error is already about , not a rounding dust. Other spoken samples included and collapsing toward once the format is integer. A comment "5 means you are losing 0.4" was a quick error sketch, not a full table: if the true value is and the integer is , the gap is .
Sense-check: 4-bit signed integers cannot represent at all, so the collapse toward is not a small mantissa trim. It is a range failure.
As you walk from 32 bits toward 1 bit, representation error grows. If the true value is and INT8 stores , the gap is already . If that gap is tiny next to the task, you may accept it. If you are updating weights, even a small mantissa can matter, because convergence depends on precise increments.
Pitfall: Reading the sign bit backwards ( as negative). IEEE uses for negative. Pitfall: Using as the FP32 fraction divisor. The stored fraction has 23 bits, so divide by . Pitfall: Mixing BF16's 8-bit exponent with FP16's fraction. Match divisor to fraction width. Pitfall: Treating integer 4-bit as "a bit less precise FP32." If the value is outside in that toy signed picture, you overflow, you do not just round.
6.2.6 Student Questions and Answers
The prompt is the exponent-field conversion used in the decode.
Q: What is , the decimal reading of an exponent field that has only its highest bits set?
A: . That value is the decimal reading of the exponent field with only the highest of eight bits set, and it is the number that then enters in the FP32 decode.
Exam note: Know the FP32 split: 1 sign bit, 8 exponent bits, 23 mantissa bits, bias 127. Replay at least through sign, exponent integer 128, and . Know that FP16 uses bias 15 and 10 mantissa bits, and that the same became about in the 16-bit try. Know signed INT8 range and why 7 magnitude bits top out at 127.
GPU and TPU vendors expose these layouts as native types. Tensor cores prefer FP16, BF16, or TF32 packets. A weight that looks like "3.14" in Python is already one of these bit strips in hardware.
FP32, FP16, BF16, TF32, and small integers are different packets of the same real idea. Next we use that idea as a training tool: quantize a gradient, send the short packet, and optionally expand it again.
6.3 Quantization of Weights and Gradients
If a gradient tensor is already the right shape, why is it still expensive? Because each entry is a fat number. Shorten the encoding and the same tensor becomes a smaller packet.
Quantization means rewriting a number in a smaller encoding. This section defines the send path first: quantize, ship, and optionally dequantize. Memory counts and the INT8 integer map come after that path.
6.3.1 Definition, Pipeline, and Trade-Off
A gradient may start in FP32 or FP16. You quantize it, send the short packet over the network, and, if you still want a floating value for the optimizer, you dequantize on the far side.
The pipeline in words is: take the gradient in some format such as 32 or 16, make a lesser-size representation, send it, then optionally expand it again so you can update weights. Dequantization tries to recover a usable float. It cannot invent bits that were never sent.
Think of a photo sent as a tiny JPEG. The file is light. The far side can expand it to a full-size image. The expansion cannot restore faces that the JPEG already smeared. The analogy breaks because JPEG is nonlinear, while the class INT8 map is a multiply, a round, and a divide.
Quantization is encode-and-send. Dequantization is decode-on-arrival. The pair is lossy: the integer grid is coarser than the original float grid. T1 describes the same idea as using fewer physical bits to represent a value, and notes that mixed-precision libraries may keep some tensors in a 32-bit training format while shrinking others to FP16.
Benefits named in class:
- lower communication cost
- less GPU memory
- faster processing of each tensor
- lower network bandwidth
- quicker training in wall-clock time
The cost is information loss. Moving from 32 bits toward 1 bit, or toward 4 bits, throws away fraction bits. Weight updates that needed a mantissa like the fractional part of will not see that extra precision. The result is a trade-off: smaller storage and smaller messages, versus weaker updates and possible harm to convergence. You must measure whether the lost bits still let the model learn.
6.3.2 Memory and Bandwidth for a 7 Billion Parameter Model
A concrete memory picture used a 7 billion parameter model during a training step that holds FP32 weights. The spoken phrase was that you need 28 GB if you want the weight update in that representation.
Each FP32 value uses 4 bytes. Then
The verbal claim matches that product: 28 GB for the 7 billion parameter step in FP32. FP32 is treated as the richest common format, so accuracy loss from encoding is treated as none, while bandwidth cost is the worst.
Sense-check: 7 times 4 is 28, and "billion parameters times bytes" is "gigabytes" in the decimal GB used in class.
FP16 cuts the payload in half. The 16-bit layout was described as 1 sign bit, then 5 exponent bits, then 10 mantissa bits. Bandwidth saving is . Memory for the same 7 billion weights is 14 GB. The INT8 footprint is the next rung.
INT8 uses 8 bits per value, spoken as 1 sign bit plus 7 remaining bits. Relative to 32 bits you keep of the bits, so you save a factor of 4. One sentence also said "8 times you saved." The bit ratio is the consistent memory ratio, and 7 GB was the stated INT8 footprint. The "8 times" line matches a 32-to-4-bit cut (INT4), not INT8. Keep 7 GB as the INT8 figure.
INT4 and 1-bit encodings were listed on the same ladder. Each further cut saves more memory and more wire time, and each further cut grows error. You cannot look only at the saving column.
Accuracy comments, given as rules of thumb rather than a named benchmark:
- FP32: no accuracy loss from format, maximum bandwidth
- FP16: accuracy change called negligible, bandwidth saving
- INT8: a drop "less than one percent" in a generic story, with an immediate warning that 1% can be huge for a hard target
- INT4: used when you must deploy to edge devices or ship a fine-tuned model in a federated setting; a 1% to 2% drop may be acceptable
T1 reports the same qualitative trade: mixed precision often still converges, but it can land in a worse local minimum than full precision, because values such as and can collapse to the same code.
A GPU face detector at 99% accuracy may still be valid on a Raspberry Pi after INT4 if the drop is about 2% and the bandwidth saving is large. One spoken saving figure was "eight percent," which does not match an 8-times bit cut. Treat the Pi story as "small accuracy drop, large resource saving." The reliable bit-ratio for INT4 versus FP32 is , not an 8% bandwidth cut.
Exam note: Be ready to pair each bit-width with both a memory ratio and an accuracy warning, not only with a compression factor. The 7 billion parameter ladder is 28 GB FP32, 14 GB FP16, 7 GB INT8, then INT4 and 1-bit with growing error.
6.3.3 Where Quantization Sits in the Training Loop
The painful moment is back propagation, not a quiet forward pass on a laptop. Workers hold FP32 data and FP32 gradients. For each weight they compute a gradient. Those tensors are quantized. The compressed values travel through the network to the destination GPU. On arrival you may dequantize if you want more numeric range inside the optimizer. You may also keep the quantized values if the optimizer can use them.
In distributed training the exchange is staged. GPU 1 sends gradients to GPU 2, GPU 2 to GPU 3, GPU 3 to GPU 4, in the reverse direction of the forward pipeline. After the forward pass you compute gradients and exchange them so each stage can adjust its weights. Using 8-bit values instead of 32-bit values shrinks that reverse traffic to one fourth, so communication becomes faster. Storage falls. Arithmetic can fall. Precision also falls. That is the same trade-off again.
GPipe-style mini-batching still applies. Data is divided into mini-frames. Mini-batch one enters the first stage, activations flow forward, the last stage computes loss, and for each block must go back. Those returning tensors are the values you consider for quantization.
Scope: Quantizing the reverse traffic helps when the interconnect is the limiter. If a stage is compute-bound, shorter gradients save memory but may not shorten the step. Integer paths also assume hardware that can pack and unpack INT8 or INT4 without a costly unpack loop on the CPU.
Sketch the pipeline on a page. The horizontal axis is stage index (GPU 0 to GPU 3). The vertical axis is time. Forward activations step down-right. Backward gradients step down-left. The landmark is the backward diagonal: that is the fat payload quantization tries to thin.
6.3.4 INT8 Scaling Formula and Worked Example for
Floating formats had a field-wise IEEE-style formula. Integer quantization uses a scale that maps a real range onto the integer grid.
Setup. Take the real value . Choose the signed INT8 grid . Use the maximum positive integer as the scale, the "maximum possible one" in the spoken walkthrough.
The class formula is: the INT8 value equals the round of times the scale.
Here is the real gradient or weight, is the scale sent with the packet, and is the integer on the wire. This is a simplified affine map that treats as living near . Standard libraries often store a per-tensor scale as so values outside still land in . The exam walkthrough uses on .
Quantize. Substitute:
Round (spoken as "you can apply the ceil value; after 5 it is 83"):
You have replaced the float with the integer . That integer is what you send.
Dequantize. Send and also send the same scale . On the far side, divide:
The recovered quotient is . The walkthrough first said the recovered value is , then named the residual error . That error is
So the "got 0.65 back" line is the intended real, and is the actual gap after integer rounding.
Sense-check: is a hair above , because rounded up. Rounding down to would have sat a hair below. The grid cannot hit exactly.
The verbal pair is: quantization is multiply-by-scale-and-round; dequantization is divide-the-integer-by-the-same-scale. You "apply the reverse" of the formula.
You must then ask whether per value disturbs learning and convergence. For one weight it looks tiny. Across a billion weights, the same class of error can pile up. The residual will accumulate: each step adds a small grid error, and billions of weights multiply the chance that those errors push updates the wrong way.
Pitfall: Believing dequantization restores the original float. It only returns a nearby grid point. Pitfall: Using the memory slogan "8 times" for INT8. INT8 versus FP32 is a cut (7 GB versus 28 GB). Pitfall: Reading a Raspberry Pi "eight percent" saving as the bit-ratio. Treat that spoken percent as unreliable. Pitfall: Ignoring accumulation. A gap on one scalar is not the story of a 7 billion parameter step.
6.3.5 Student Questions and Answers
The first question is the decode step itself.
Q: How do you dequantize?
A: Apply the reverse arithmetic. If you quantized by rounding , recover with the same scale that you send along with the integer.
Lost bits are a separate confusion. Expanding an integer does not recreate a deleted fraction.
Q: Even if you dequantize, the precision lost during quantization is still lost, right? The original bits were not even transferred.
A: Yes. You try to return toward a real value, but you cannot get the exact original. You generalize to some nearby grid point. You reduce error relative to living forever in a tiny integer, but you do not recreate deleted mantissa bits. For weight updates even a smaller value can matter, so you should not throw those bits away blindly.
A third instinct is to stay in integers inside the original network math.
Q: Can we convert weights to the 127-scale integers inside the original network calculation itself, and then do integer-only math instead of sending floats?
A: The weights start as floats. Learning still uses back propagation of a real-valued gradient. You may quantize that gradient, for example turning a value such as into an INT8 code, send the code, and dequantize on the far side, as in the story. Integer-only arithmetic is possible in that send-and-update path. The obstacle is error. The received value is already high by in the worked example. That error accumulates very quickly across billion weights. The example is one weight. A billion weights later, learning can drift. So yes, you can pass integers. You must still watch accumulation.
6.3.6 When to Insist on Dequantization
Quantize-then-dequantize is not mandatory for every net. For complex detection, including object detection and real-time accident detection, keep the extra care: quantize for the wire, dequantize for the update, and test whether the task still converges. For simpler CNN detection, you may not need that extra expand step.
Edge and federated deployments often force a small integer format such as INT4. A 1% to 2% drop can be acceptable if the device constraint is real. A GPU at 99% face-detection accuracy versus a Raspberry Pi with about a 2% drop is the concrete "still valid" story.
6.3.7 Industry Applications and Practical Checks
GPU and TPU vendors expose FP32, TF32, BF16, FP16, and integer paths. Conversion among those encodings is daily work in large-model training, not a homework toy. NVIDIA Automatic Mixed Precision is one library form of the same ladder: wrap an optimizer and let the runtime pick FP16 where it dares.
Interactive converters let you type any number and watch FP32, FP16, BF16, and integer reconstructions. Integer inputs are the easy case. The hard case is a float whose mantissa does not survive the smaller grid.
Exam note: The INT8 worked pair with error is the numerical template to replay. Write the scale, the round, the reverse divide, and the residual. Dequantization does not restore deleted bits. Integer-only sends are legal and error accumulates across billions of weights.
6.4 Fine-Tuning and Transfer Learning
Quantization left trained weights in place and only shortened their encoding. This section asks a different question: how do you teach a giant pretrained model a company task when you cannot retrain billions of entries?
If a vision-language model never saw your factory photos, why would a shorter bit-width help? It would not. You need new training on your labels, but you cannot afford a full pretraining run.
6.4.1 Fine-Tuning Is Not Quantization
A prompt asked how fine-tuning differs from quantization.
Quantization leaves the trained weights in place and only shortens their encoding. You do not retrain just to quantize. Fine-tuning updates model weights by training on your own data. The aim is to turn a generic model into a specialist for your task and your company data. A large language model never saw that private corpus, so you must introduce the corpus if you want outputs that match it.
Fine-tuning a 120 billion or 8 billion parameter net from scratch is not realistic. Those models were trained by labs such as Meta and Google on terabytes of general text and images. You still want to inject custom images, for example defective MRF tires, into a vision-language model (VLM). Named VLMs in the discussion included Qwen (spoken as QUN / Kwan), Mistral (spoken as mystical), and a Llama-family model (spoken as polygama / polygamma). The three product families are the intended set.
Without a parameter-saving trick, "fine-tune from scratch" would mean retraining billions of weights. That path is closed.
Purpose. Fine-tuning exists to inject a small labeled set into a model that already knows generic vision or language. Inputs. A pretrained weight tensor , a small company dataset (images plus labels, or text plus answers), and a choice of which tensors may change. Outputs. Updated weights (or a small adapter, in the next section) that mark defects, answer domain questions, or otherwise match the company task.
6.4.2 Domain Adaptation With Few Company Images
A VLM is a vision-language model: it jointly handles images and text. It can caption an image, or generate an image from a caption, and it can act as a visual agent on mixed inputs including video. Those models are strong generalists because they were trained on huge multimodal corpora.
They are not born as MRF tire inspectors. Defects may be a vertical scratch, a horizontal scratch, or other marks on the tread or sidewall. You may have only about 100 labeled company images, not millions. Training a detector from zero on 100 images will not match a foundation VLM. So you adapt the pretrained model.
Domain adaptation here means: keep the general knowledge already baked into billions of parameters, and add a small amount of company-specific knowledge so the model becomes a task specialist. After adaptation, the same VLM becomes an MRF tire defect expert. It can mark defects on new images and it can run faster because the serving path is specialized, not a giant general chat model doing a side job.
The data scale named for the company trial was hundreds of samples, not millions. With that small set, Qwen, Llama-family, and Mistral-style models were trained until a new image produced a defect decision.
Think of the pretrained weights as a world encyclopedia. You do not rewrite the encyclopedia. You add a thin company pamphlet and staple it on. The analogy breaks if the pamphlet contradicts the encyclopedia on facts that must stay frozen; then you are in catastrophic forgetting, which is flagged later, not solved here.
6.4.3 Layer Freezing, Feature Extraction, Partial and Full Fine-Tuning
A first family of tricks is old transfer learning.
Steps.
- Start from a pretrained backbone (ResNet, BERT-base, or a VLM trunk).
- Feature extraction / frozen backbone. Freeze most layers so their weights do not change. Feed your images through those frozen layers. Train only a new task head, the last classifier (or a few last layers) that maps features to your labels.
- Partial fine-tuning. Freeze the early layers and unfreeze one, two, or three layers in front of the head. Inputs still pass through the frozen stack. Loss is computed at the head. Gradients update only the unfrozen block plus the head. You can grow that trainable window slowly.
- Full fine-tuning. Every weight is trainable, after you swap the classifier.
If the head used to score 1,000 ImageNet classes and you have a 3-class, 4-class, or 10-class tire problem, you must replace that head.
T1's layer-freezing chapter adds a systems reading of the same freeze: once a pipeline stage has converged, you can drop its activations and skip its gradient work, which frees GPU memory during model-parallel training. That is freeze-for-memory. The class story here is freeze-for-adaptation: keep generic features, train the task head.
Trace, tiny tire head. Suppose the frozen backbone emits a 512-dimensional feature . The old ImageNet head mapped to 1000 logits. You throw that head away. You attach a new matrix and bias for three tire labels: scratch, bulge, good.
Forward: . Loss is cross-entropy on the company label. Backward: and update. because those weights are frozen.
With 100 images and a few epochs, only the head numbers move. The encyclopedia stays put. The pamphlet is the new head.
Sense-check: 1539 is a tiny trainable set next to a ResNet or a VLM. That is the point of freezing.
The verbal contrast is sharp. On ResNet-scale models, partial or even full fine-tuning can be fine. BERT-base fine-tuning on a single GPU is the same size class. On ChatGPT-scale models, updating all layers or even a large last block is not possible in this setting. That is why the discussion turns to PEFT and LoRA.
When to use which. Use a frozen backbone plus a new head when the company set is tiny and the backbone already sees related images. Use partial unfreezing when the head alone underfits. Use full updates only when the pretrained net is small enough (ResNet, BERT-base). Do not plan a full update of a chat-scale LLM. Complexity. Full fine-tuning stores gradients and optimizer states for every parameter. Frozen-backbone training stores them only for the head. The wall is memory and wall-clock, not a missing derivative.
So the simple stack is: freeze a lot, train a little, maybe walk the trainable window deeper. For giant LLMs and VLMs you still need a more extreme cut: parameter-efficient fine-tuning (PEFT), including LoRA.
6.4.4 Student Questions and Answers
The opening contrast is the one to keep in exam language.
Q: What is fine-tuning, and how is it different from quantization?
A: In fine-tuning you update weights by training on your own data, turning a generic model into a task-specific model, without retraining just to change bit-width. In quantization you only reduce the precision of existing weights, without that retraining step.
A second instinct already points at PEFT.
Q: Could we first quantize to shrink the model, freeze some layers, and fine-tune only the rest, so we never touch the entire net?
A: Yes. That is the right instinct. Freeze a large body of weights that already hold general knowledge. Train only some layers, or, in the PEFT view, only a small extra adapter. You do not retrain the whole giant.
Exam note: If a question contrasts the three compression families, quantization changes bit-width, fine-tuning changes which weights learn your data, and pruning (next topic) zeros or drops redundant weights. Freeze-and-train-a-head is the simple path. Full updates are for ResNet-scale nets, not ChatGPT-scale nets.
Company defect inspection with a handful of images is the reason PEFT exists. You cannot collect ImageNet-scale labels inside one factory.
Fine-tuning staples a pamphlet onto an encyclopedia. For chat-scale models even the last layers are too large to update. The next section splits one giant matrix into two thin factors and trains only those.
6.5 Parameter-Efficient Fine-Tuning and LoRA
Chat-scale models made full updates impossible. Parameter-efficient fine-tuning (PEFT) attacks that wall. Low-rank adaptation (LoRA) is the PEFT method developed in detail: freeze , train two thin factors, add their product.
How do you add company knowledge to a million-entry matrix without touching a million entries? Split the update into two thin factors whose inner size is a tiny rank .
6.5.1 Split a Giant Matrix Into Two Thin Matrices
Start with a square weight matrix of size . For a mental picture, take . Then
which is 10 lakh parameters in one matrix. LoRA does not update that full grid. It writes the grid as a product of two much thinner matrices whose inner dimension is a small rank .
Keep the row count . Choose a tiny column count , such as , , or . One factor is . The other is . Their product is again :
The stored learnable count is , not . The output size matches the original multiply. The trainable set is the two thin factors. Keep the multiply shape of while training only those factors.
Forget a long linear-algebra sermon about rank if you need to. The working picture is: pick a small , split, multiply back to the old shape, and train only the split pieces.
A sliding door on a wide wall is a fair everyday map. The wall (frozen ) already stands. You add a thin pair of rails (the two factors) that let the door move a little. The analogy breaks if is so small that the door can only slide in one direction; then the adapter cannot express a rich task.
6.5.2 Mathematical Formulation
Let be a frozen pretrained weight matrix. Let be the LoRA rank. Introduce two learnable matrices. One spoken assignment was and . Another later line swapped the names and said is and is . The product must be either way.
This write-up fixes the names so that is : and . If you swap the letters, swap the product order too. Do not mix the two conventions in one line.
The adapter is
and the used weight is
where stays frozen and only and receive gradient steps. You are not touching ; you learn two small matrices that represent the new task, then you add that product onto .
Forward pass, including a scaling factor (spoken both as "alpha by R" and, in one pass, as if it were a learning-rate term):
Here is the layer input, is the layer output, is a positive scale hyperparameter, and is the rank. The frozen path stays. The adapter path is the only path you update. is not the optimizer learning rate. It is a separate knob that keeps adapter updates a similar size when you change .
Before training, and are initialized to small random values so that starts as a small change to . A common library default sets to zero and to a small Gaussian, which makes at step 0. The class version (both factors small and random) is the same idea: start with a tiny pamphlet, not a second encyclopedia.
After training, encodes domain-specific patterns: legal phrasing, tire-scratch textures, or whatever the new task is.
One wording said predictions use only and not . The forward formula above still includes . The intended claim is that updates use only and , while the frozen still contributes to the forward pass.
6.5.3 Worked Examples of Parameter Counts
Train skinny factors, then multiply back to . The counts below are the exam arithmetic.
Example A — with rank . Original count:
LoRA factors and :
You train 400 numbers instead of 10,000. Those 400 numbers are the MRF-task knowledge in this toy. After you form the product you again have a grid to add onto . Most of that grid can be near zero. The product still has the right shape.
One spoken addition said "100 into 2 is 200, plus 2 into 100 is 400," which double-counts if you treat the second term as already 400. The consistent total is .
Sense-check: , so you train 4% of that matrix. The multiply shape is unchanged.
The toy is the same pattern with numbers you can write on one board.
Example B — toy with rank . Factors and give
learnable values. The product is . You still only train 16 adapter entries. The walkthrough counted "4 plus 4 plus 8" on the way to 16. The clean count is .
Sense-check: a full has 16 entries too, so rank on a is not a saving. The toy is for shape, not for compression. Compression appears when .
Example C — with a rank-1 split. The original matrix is . The adapter is and . A spoken arithmetic said each thin factor is , and the two sides sum to "parameters." Note that
so is 512 FP32 bits in one vector, not 512 parameters. Parameter counts would be learnable values versus full values. Keep both readings: 1,024 parameters, or 32,768 bits if each of the two vectors is stored as 512 FP32 bits.
Example D — million-scale motivation. A matrix is 10 lakh entries. LoRA replaces that with two skinny factors whose inner size is a small . That is the point of the method: keep the multiply shape, drop the trainable count.
The small numbers inside and are the task-specific weights. After they learn, you "assign back": add into the working model so the fine-tuned net contains the new knowledge.
6.5.4 Back Propagation Through and
For each training example the model predicts, you compute a loss against the ground truth, then back propagate. You do not update . Gradients flow into and , which together form .
Let be the loss and let be the layer output after the adapted multiply,
Let , a column. Chain rule in the spoken sketch was "dL by dH, times dH by the next factor," then a gradient involving the transpose of .
Write . Then the adapter contribution is . Differentiating through that product gives
A reconstructed pair from the walkthrough omitted :
That pair is the same transpose structure with the scale folded into the optimizer step. Standard LoRA sends updates only into and . The audio mixed with transpose; that is a slip for the incoming gradient, not an update of .
After many examples, and settle. Their product encodes the task. Adding that product to yields the fine-tuned matrix. The values you add are small. A spoken numeric cartoon was: if a frozen entry is and the adapter entry is , the sum is . Some adapter entries stay 0.
Loss may be classification or regression. The model predicts as a function of the adapted weights. You compare to the label, form , and send and . Repeat. That is ordinary back propagation on a tiny variable set, with the giant frozen.
6.5.5 How Many Parameters You Train, and Optimizer-State Saving
You can vary , , and how many layers get LoRA. Full fine-tuning trains the whole matrix. LoRA trains per adapted matrix. One comparison said that after LoRA you might train only "93 lakh" parameters against a much larger full count. The matching full-model denominator was not given, so treat 93 lakh (9.3 million) as a named worksheet figure, not a universal ratio.
A per-layer worksheet used:
- full matrix parameter count on the order of in a display that repeated 3.07 (the exact power was not clean)
- LoRA with shape involving
- LoRA with shape involving
- LoRA total per layer = both factors, times the number of adapted layers
- compression ratio from those counts
- scale
A named saving was 95.3% of optimizer states relative to the dense baseline. Optimizer states (moment buffers in Adam-style methods) track each trainable tensor. If you train 400 numbers instead of 10,000, those extra buffers shrink with the trainable set.
A training simulator compared feature extraction against LoRA. Feature extraction showed a wide gap between training loss and validation loss, read as "it will not learn much" and as overfit. LoRA reduced that gap and moved more useful information into the updated adapter weights. The simulator is a way to see that a small trainable set can still fit the new task.
Transfer learning with a frozen backbone is "very simple" next to LoRA. The piece to learn deeply is PEFT/LoRA: choose two low-rank matrices, train them, freeze , add the product.
Catastrophic forgetting, the risk that new training erases old skills, is flagged as a later topic, not derived here.
When to use LoRA. Use it when is too large to update and you have a small specialized set. Alternatives: a new task head (cheaper, weaker), full fine-tuning (stronger, often impossible), or external retrieval (next section). Pitfall: Treating as the Adam learning rate. Pitfall: Updating "a little" and calling it LoRA. LoRA freezes . Pitfall: Picking so large that . Then you paid LoRA complexity without the saving.
6.5.6 Student Questions and Answers
Fine-tuning is not a distributed-only trick.
Q: Fine-tuning is a generic mechanism, right? It is not specific to distributed training?
A: Yes. It is adaptation. Whenever you want an LLM or VLM that was trained on a huge corpus to serve a new task, you can fine-tune. Distributed training is one place you meet the memory wall, not the only place you use LoRA.
A compression instinct from linear algebra does not replace LoRA.
Q: Is there another optimization, for example PCA as an initialization, to shrink the matrix?
A: No. The pretrained matrix may have thousands of features, a spoken width of 2752 among them, learned for a generic task. If you crush that to two or three PCA features, you lose the generalization of generic features you were trying to keep. If you keep a large PCA rank, you still perturb the generic basis and you lose the point of freezing . LoRA adds a thin increment instead of rotating away the original features. PCA is the wrong tool here.
Exam note: LoRA questions want the shape story times , the freeze-and-add rule with , optional scale , and the fact that back prop updates and only. Replay the count.
LoRA is how teams attach legal, medical, or factory knowledge to a frozen foundation model without renting a full pretraining cluster.
LoRA keeps frozen and trains two thin factors. The next contrast is a tool that never touches weights at all: retrieval-augmented generation.
6.6 Fine-Tuning Versus RAG and Prompting
LoRA changed weights. A common confusion is to treat that change as the same trick as retrieval-augmented generation (RAG). This section splits the tools: external lookup versus baked-in skill.
If the answer already lives in a PDF, do you need new weights? Often no. If the answer is a pixel box on a tire, a retrieved paragraph will not draw the box.
6.6.1 Retrieval-Augmented Generation Is External Memory
RAG is a storage and retrieval process. It sits outside the model. Documents live in a database. A user question arrives. The language model receives that question and checks whether matching data lives in the RAG store. If a match exists, the system pulls the corresponding context. Now the model holds two pieces: the user question and the retrieved context. It writes an answer from both.
Let be the user question and let be frozen generator weights. RAG answers
Fine-tuning answers with adapted weights and no fetch of that task skill:
Here is the frozen generator, is the external context, is the task input (text or image), and is the LoRA adapter. RAG never writes . Fine-tuning imbibes task knowledge into and , then into .
You can dump PDFs, presentation decks, Jira tickets, Confluence pages, or medical notes into that store. Text question-answering is the sweet spot.
Fine-tuning changes the model. Task knowledge is inside and , then inside . There is no extra fetch step at inference for that knowledge. You imbibe the new skill into the weights themselves.
You can also stay outside the weights with prompts only: a zero-shot prompt or a few-shot prompt (spoken as "few short" / "zero short"). That path never updates . It only shows extra text or extra example images in the request.
| Tool | Where knowledge lives | Typical job | Weight update |
|---|---|---|---|
| Prompting | Inside the request text | Easy few-example tasks | None |
| RAG | External database | PDF / Jira / Confluence QA | None |
| LoRA / fine-tuning | Adapter plus frozen | Skills the model must perform | only |
When to pick which: retrieve text that already exists; train when the model must do a new perceptual or stylistic skill.
6.6.2 Why Tire Bounding Boxes Do Not Belong in RAG
Suppose the task is: given a tire image, draw a bounding box on a scratch. The expectation is a box on the damaged region, not a paragraph of advice. RAG will not match that job. You cannot store a few defect photos in a text database and expect a retrieved paragraph to localize pixels. Storing the image in RAG and hoping a match appears does not give you coordinates.
Prompting was tried without touching weights: show an "upper line defect," a "vertical defect," and then a new photo. It did not work for this complexity. The team had to show images during training so the model became an expert. For complex problems the model may not understand the prompt exemplars. For simple fetch-and-read jobs, such as reading PDF documents, prompts may help.
The split in one sentence: RAG is for textual documents you insert and retrieve. Fine-tuning is for skills you must bake into weights, such as drawing boxes on factory images. Object detection for a specific company, such as MRF tires, is the fine-tuning side. Document QA is the RAG side.
Scope: RAG helps when the fact is already written down and can be fetched as text. It breaks for dense visual localization, for skills that are not a lookup, and for private images that have no useful text neighbor in the store. Few-shot image prompts failed here, so the team had to train.
6.6.3 Generic Answers Versus a Domain Model
A generic model, asked whether a California employer may fire a worker for a social-media post made outside work hours, tends to hedge: employment law varies by state, exceptions apply, here is a vague pointer. A domain-tuned model can cite a labor code, name exceptions, and give a tighter reason. The same pattern is the MRF detector: general VLM versus tire expert.
Picture two desks. On the left, a generalist reads a question and hedges. On the right, a specialist has already studied the code and answers with a citation. RAG can slide a statute onto the generalist's desk at ask-time. Fine-tuning is sending the specialist to school before the question arrives.
6.6.4 Student Questions and Answers
The mix-up is to treat LoRA as another name for RAG.
Q: Is LoRA the same technique that RAG uses?
A: No. RAG is a storage mechanism and a retrieval process, external to the model. Fine-tuning imbibes knowledge into the weights. RAG helps when you can fetch text. It does not replace training for object detection with bounding boxes on company images.
Exam note: A comparison item should mention at least one task that RAG cannot cover (pixel localization / bounding boxes) and one task it can cover (PDF question answering). Few-shot prompts failed on the hard visual task.
Jira and Confluence dumps are RAG workloads. Factory camera inspection is a fine-tuning workload. Mixing the two tools without that split is a design error.
RAG fetches. LoRA bakes. The last family, pruning, neither fetches nor adds adapters: it zeros redundant weights.
6.7 Preview of Pruning
Quantization shortened bits. LoRA shrank the trainable set. Pruning is the third compression family, scheduled for a later session. The preview is enough to separate it from quantization and LoRA.
If two filters learned the same scratch detector, do you need both? No. You keep one copy and zero or drop the extra kernel. You do not delete the whole convolutional stage.
6.7.1 Zeroing Weights Instead of Retraining Everything
Pruning adjusts the weight tensor by forcing some values to zero, as if you snipped branches. If a weight is and it fails a keep-test, you store . You can also drop filters, which cuts the number of live kernels in a convolutional layer. The aim is fewer effective weights, less storage, and less training and serving cost.
T1 describes a related serving cut as model distillation via pruning: define a keep-test, drop neurons that fail it, and keep a smaller net with the same job. That full recipe is later. Here the picture is already enough: zero what you do not need.
Dropout is named as one pruning-style technique: it reduces the number of active weights, though classical dropout is stochastic at training time. The later session goes deeper.
Purpose. Cut live parameters without inventing a new architecture. Inputs. A trained (or nearly trained) tensor , and a keep-test (magnitude, similarity, or a dropout mask). Outputs. A sparser with some entries zero, or a convolutional layer with fewer filters.
6.7.2 Do Not Delete Layers; Collapse Redundant Filters
A convolutional layer is not itself the learned object. The filters are. A spoken shape "34 comma 3" means 34 filters of size . Then the layer learns
parameters in that picture (the spoken product ignores input-channel depth). If each filter also sees input channels, the fuller count is . The class product is the per-channel kernel area times the filter count.
You "play" inside those filters. You do not delete the layer. Removing a layer throws away that stage of computation. "The layer is not a learning thing; filters are learnable things."
Sense-check: 34 small patches have spatial weights. That is a board-sized count, not a 7 billion parameter count. The lesson is where learning lives, not the absolute size.
If you declare 64 or 128 filters, several of them may learn nearly the same feature. The distance between two filter matrices can be tiny. If two filters look for the same pattern, you can keep one copy. That merge is one pruning style. Declared width 128 does not mean 128 distinct concepts. Near-duplicate filters are the ones you remove to cut training time and storage.
Pitfall: Deleting a CNN layer and calling it pruning. The stage of computation is then gone. Pitfall: Assuming 128 filters means 128 different detectors. Many can be duplicates. Pitfall: Mixing dropout's random training mask with a permanent zero. Dropout is related in spirit; it is not the same serving-time snip.
Sketch two grids that look almost equal: both light up on a vertical edge. The keep-test notices the tiny distance and drops one grid. The layer still exists. It just has 127 filters instead of 128.
6.7.3 Student Questions and Answers
The branch picture is the right spirit, if you zero weights rather than delete stages.
Q: What is a pruning technique? Is it removing branches?
A: Yes, in spirit. You zero some weights or drop some filters so the live parameter count falls. Dropout is one related method. The full recipe is a later topic.
The dangerous shortcut is to remove a whole layer.
Q: In a CNN, can we prune by removing layers?
A: No. You cannot remove the layer. Remove-layer means that stage of learning is gone. Filters are what learn. A layer with 34 filters of learns values. If two of 64 or 128 filters converge to the same feature, keep one. That is a pruning move.
Exam note: Pruning details, including systematic filter-similarity tests, are promised for the next session. The examinable distinction now is: quantization changes bits, LoRA changes which extra matrices you train, pruning zeros redundant weights or filters. Do not delete CNN layers.
Over-wide CNNs with 128 filters often duplicate detectors. Collapsing those duplicates is a practical serving optimization, not only a diagram in a textbook.
Three levers, three objects: bits (quantization), extra matrices (LoRA), live filters (pruning). Practice the formulas from this lecture first. Leave the full pruning recipe for the next session.
Exam Guidance Summary
No numeric mark map was given. The emphasis signals still tell you what to practice.
- After pipeline slicing, the remaining cost is storing and shipping gradients. Bit-width is the first lever.
- Know the FP32 split: 1 sign bit, 8 exponent bits, 23 mantissa bits, bias 127. Replay at least through sign, exponent integer 128, and .
- Know that FP16 uses bias 15 and 10 mantissa bits, and that the same became about in the 16-bit try.
- Know signed INT8 range and why 7 magnitude bits top out at 127.
- Memorize the INT8 scale template: for gives 83; dequantization is ; error is . Write every intermediate, not only the final float.
- Pair the 7 billion parameter memory ladder with the accuracy warnings: 28 GB FP32, 14 GB FP16, 7 GB INT8, then INT4/1-bit with growing error.
- Dequantization does not restore deleted bits. Integer-only sends are legal and error accumulates across billions of weights.
- Fine-tuning is not quantization. Freeze-and-train-a-head is the simple path. Full updates are for ResNet-scale nets, not ChatGPT-scale nets.
- LoRA is the PEFT method to know: with , train only, optional scale . Replay the count.
- RAG is external retrieval. It is not LoRA. Bounding-box inspection needs fine-tuning. PDF/Jira/Confluence QA can use RAG. Few-shot prompts failed on the hard visual task.
- Pruning preview: do not delete CNN layers; merge similar filters; dropout was named as related. Details later, along with catastrophic forgetting.
- Interactive number converters and a LoRA training simulator were recommended as practice, not as a substitute for the formulas.
Exam note: If a question contrasts the three families, write: quantization changes bit-width, fine-tuning changes which weights learn your data, pruning zeros redundant weights or filters. Pair every compression factor with an accuracy or error warning.
Key Industry Applications
- Pipeline-parallel GPU training (GPipe-style): activations go forward, quantized gradients come back. Bit-width cuts message size on the reverse path.
- Foundation LLM/VLM serving: GPT-style, BERT-style, Qwen, Mistral, and Llama-family models are too large to retrain; PEFT/LoRA is the practical adaptation path.
- Factory visual inspection: MRF-style tire defect detection with about 100–hundreds of images, needing bounding boxes, not a document index.
- Edge and federated deployment: INT4 (and similar) on devices such as a Raspberry Pi, accepting about a 1–2% accuracy drop to win memory and bandwidth.
- Accelerator formats: FP32, TF32 (19-bit), BF16, FP16, INT8 chosen by GPU/TPU vendors; conversion among them is quantization work. NVIDIA mixed precision is the common training form of that conversion.
- Enterprise text stacks: RAG over PDFs, Jira, and Confluence for lookup; not a replacement for visual fine-tuning.
- Legal specialists: a generic model hedges on California employment questions; a tuned model cites labor code.
- CNN serving: prune near-duplicate filters in wide layers (64 or 128 kernels) to cut storage and time.
- Transfer baselines: ResNet-style full or partial fine-tuning still works when the backbone is small enough; giant chat models need LoRA.
- Optimizers: LoRA's 95.3% optimizer-state saving matters because Adam-style buffers scale with the trainable tensor count, not with the frozen .
DML Lecture 6 notes · Quantization, Fine-Tuning, and Low-Rank Adaptation
Sections Breakdown
Why leftover weight and gradient traffic still dominates after slicing.
Sign, exponent, and mantissa layouts from FP32 down to small integers.
Bit-width cuts, the 7B memory ladder, and the INT8 0.65 worked map.
How company data updates a pretrained model without a full retrain.
Freeze W, train rank-r factors A and B, and count the saved parameters.
When retrieval helps document QA and when visual tasks need adapters.
Zero redundant weights or filters; do not delete whole CNN layers.
The numerical templates and contrasts most likely to appear on an exam.
Where quantization, LoRA, RAG, and pruning show up in production stacks.
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
Communication Bottlenecks After Model and Data Slicing
Must-know: Slicing is not enough; you still pay for every bit you store and send on the reverse pipeline path.
⚠️ Top pitfall: Naming differentiability as the leftover bottleneck instead of representation and communication of gradients.
Self-check: After GPipe-style slicing, what payload still dominates interconnect time?
Connects to: Floating-point layouts and integer encodings, Quantization of weights and gradients
Floating-Point Layouts and Integer Encodings
Must-know: FP32 is 1 sign, 8 exponent, 23 mantissa bits with bias 127; replay -3.14 through exponent 128 and 2^{128-127}.
⚠️ Top pitfall: Reading sign 0 as negative, or dividing the FP32 fraction by 2 instead of 2^{23}.
Self-check: Decode -3.14 given s=1, E=128, M=4781507.
Connects to: Quantization of weights and gradients
Quantization of Weights and Gradients
Must-know: INT8: q = round(x * 127) maps 0.65 to 83; dequantize as 83/127 with error 0.003543. Dequantization cannot restore deleted bits.
⚠️ Top pitfall: Believing dequantization recreates the original float, or quoting an 8x saving for INT8 instead of 4x.
Self-check: Quantize 0.65 with scale 127, dequantize, and state the residual.
Connects to: Floating-point layouts and integer encodings, Fine-tuning and transfer learning
Fine-Tuning and Transfer Learning
Must-know: Quantization changes bit-width; fine-tuning changes which weights learn your data. Full updates are for ResNet-scale nets, not ChatGPT-scale nets.
⚠️ Top pitfall: Treating quantization as a substitute for fine-tuning, or planning a full update of a chat-scale LLM.
Self-check: You have 100 tire images and a pretrained VLM. Do you quantize or fine-tune, and which layers move?
Connects to: Quantization of weights and gradients, Parameter-efficient fine-tuning and LoRA
Parameter-Efficient Fine-Tuning and LoRA
Must-know: W' = W + BA with r << d; train A and B only; optional scale alpha/r. Replay 100x100 to 400.
⚠️ Top pitfall: Using PCA to crush frozen features, or thinking predictions use only Delta W and not Wx.
Self-check: How many numbers does LoRA train for a 100 by 100 matrix with rank 2?
Connects to: Fine-tuning and transfer learning, Fine-tuning versus RAG and prompting
Fine-Tuning Versus RAG and Prompting
Must-know: RAG cannot cover pixel localization or bounding boxes; PDF question answering can use RAG. LoRA is not RAG.
⚠️ Top pitfall: Treating LoRA as the same technique RAG uses, or expecting few-shot image prompts to draw tire boxes.
Self-check: Should MRF scratch boxes live in a RAG store or in a LoRA adapter?
Connects to: Parameter-efficient fine-tuning and LoRA, Preview of pruning
Preview of Pruning
Must-know: Quantization changes bits, LoRA changes extra matrices, pruning zeros redundant weights or filters. Do not delete CNN layers.
⚠️ Top pitfall: Removing a convolutional layer and calling it pruning.
Self-check: A layer is 34 comma 3. What learns, the layer or the filters, and how many 3 by 3 weights are in that picture?
Connects to: Quantization of weights and gradients, Parameter-efficient fine-tuning and LoRA
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.