LoRA and QLoRA: What parameters have been trained

A set of low-level updates is calculated manually, distinguishing weight quantification, computation of accuracy and trainingable parameters, and a checklist is established for the fitper to store and load.

System Chapter . StepCollate in 2 Graphics6 self-measurement3 First-hand sources
Start Body
Learning objectives and first steps3 objectives • 3 first fixes

Try to do it after reading

  • Deduct low update and parameter from matrix shapes
  • Calculate output and quantitative errors before and after fit
  • Distinguishing LoRA, QLoRA, fully fine-tuned engineering boundaries

Suggested first

  • Linear layer and reverse transmission
  • Projection matrix for Transformer
  • Training and verification isolation

There's a model for how to adapt to a new task

Hypothetically, models learn to summarize papers in a fixed format or to adapt to certain types of open domain texts. Full-scale fine-tuning will update a large number of basic parameters, with corresponding gradients and optimizer status. Where resources are limited, the original weight may be frozen and only small incremental amounts may be trained. What really needs to be explained here is where the incremental effect is, what is constrained by the ability to express and what part of the storage is saved.

LoRA is not synonymous with "training only the last level". It can insert several linear variants, with the target module determined by configuration; The freezing of base parameters does not mean that the reverse dissemination is no longer subject to these calculations. This chapter should be read in such a way as to track the input output dimensions of the linear layer and to distinguish between parameters, gradients, optimising state and forward activation. Their visible occupancy cannot be summarized in a single “model size”.

Split the incremental quantities into two small matrices

Using a column agreement, W Shape As dout × din , Enter x Yes. din ×1。 LoRA Use A ∈ r × din and B ∈ dout × r , add alpha/ r Multiply BA 。 The base output and the lower branch can therefore be added directly, with the result still being dout x 1. rank r The determination of the upper bounds of the incremental matrix does not represent the cut-off of the original model.LoRA original paper (b) Provides the basic parameterization; The conversion storage and scaling variants of specific libraries still need to be reconciled separately.

y=Wx+αrBAx,P=r(din+dout)

Remove W = [(1,−1], [0,1,1]], A =[[0.2, 10-0.0.3], B =[[0.5], [-0.2], r =1, alpha =2. Multiplies shall be [[0.2, -0.01.3], [-0.08,0.04, -0.12]. Enter x = [1,2,−1] with base output [2,1]; Ax = 0.3 and multiplied by 2 B to receive an increment [-0.3, 0.12] and ultimately [177,1.12]. This does not need to hide the entire matrix Multiplication into a library function.

An updated architectureThe B in the two rows on the left multiplied by the A in the three rows in the middle and the second row in the three rows on the right is equal to negative zero four times the first row, indicating a maximum of one.0.5−0.20.2−0.10.30.2−0.10.3−0.080.04−0.12×× 2 =B:2×1A:1×3ΔW:2×3Line 2 = -0.4 x line 1; Low binding effects are incremental.
All values are synthesized in this chapter; Basic W remains unchanged, with training variables A, B.

With five training parameters in the small case and only six basic matrices, savings are not significant. For the matrix of din = dout = 4096, r = 8, the base weight was 1677716, while A / B totaled 65536, or about three-thirty-nine points. This does not include bias, additional training layers or multiple target matrices, and the single matrix ratio cannot be used directly as a training drop.

What floor is QLoRA's "low precision" on

QLoRA Storage of frozen base weights in low bits and return of gradients to adaptors through base model calculations; It contains the design of NF4, quantitative constant compression and treatment peaks. The weight is stored in four bits, which is not equal to the four bits used for all multiplying, activation and gradients. Actual computational accuracy, quantitative grouping, scaling constants and formulation accuracy all need to be viewed.

The error is understood in a simpler and evenly quantified manner: map [−1,1] to an integer 0 to 15, step 2/15. Enter[−1, −0.2, 0.1,1] map[0,6,8,15], inversely quantified[−1, 10-02,0.06667,1]. The third error was about 0.03333333. It's just a 16-grade even-learning quantifyer Not a code book for NF4 I don't know. Cross-border input also needs to be defined, otherwise the formula may produce an integer that exceeds the four bit range.

Equally quantifyed steps and errorsThe cross-axis values, the vertical axis inverse values, the grey diagonal lines are the ideal map, the green steps are the partial numeric level, and the original zero point one is mapped to zero point 067.Counterquantative ValuesEnter the original value0.1 → 0.066667Error 0.03333333−11
Only some steps highlight the mapping relationship. The true error also depends on the range, code book and abnormal values of each group.

Minimum code and load error

W = [[1., 0., -1.], [0., 1., 1.]]
A, B, x = [.2, -.1, .3], [.5, -.2], [1., 2., -1.]
ax = sum(a*v for a, v in zip(A, x))
y = [sum(w*v for w, v in zip(row, x)) + 2*b*ax
for row, b in zip(W, B)]
print(y) # [1.7, 1.12]
def quant(v):
q = max(0, min(15, round((v+1)*15/2)))
return q, -1+2*q/15
print([quant(v) for v in [-1, -.2, .1, 1]])

Standard Python implemented, not running PEFT, bitsandbytes or GPU fine-tuned. If the loss remains unchanged, check if the target layer matches, A/ B is in the optimist, is wrongly all frozen, and the training label is valid. If the result after loading is abnormal, check the base model revision number, tokenizer, adapter rank/ scale, target module name and whether to double merge. The preservation of the adaptor does not amount to the preservation of a complete base model, and the identity of both must be recorded together.

Common initialization would allow a low matrix to start with zero, and the fit-out start to be consistent with the underlying model; However, setting both matrices at zero could interrupt the initial gradient. Realise details by PEFT v0 21.0 Configuration On the other hand, the dynamic interface is not written as a training script to ensure direct operation. The consolidation of incremental amounts may also involve counter-quantification and re-quantification, which would need to be reciprocated with numerical margins and mission indicators; Could not close temporary folder: %s

A small check of gradient and initialization

Following this chapter, the loss is tentatively set at the sum of two outputs. The output of the guidance for B equals two times Ax, so that the two B elements are both negative 0.06; The number of guides for each element of output to A equals two times the sum of two Bs, i.e. zero six times x, obtained [0.6,1.2, -0.6]. This is a local lead under fixed linear losses and is not a post-training quality indicator. It can be independently validated by adding a parameter to or reducing a small number, and by calculating the difference in the centre.

If B is initially zero and A is not zero, the start output is equal to the base model. At this time, the gradient of A has B, so the first step may be zero; The gradient of B is still not zero, which will start a change in the next step. If both A and B are zero, neither direction may have an initial signal. Specific initialization may be based on other designs, and the diagnosis will be based on the actual weight and gradient, rather than on the quantity of training parameters.

Fitness tasks also require the preparation of the basic model matching and the return of untrained capacity. (b) The improvement of the correct format and the decline in the quality of the facts may be a trade-off of the objective; It is not possible to judge whether or not it is worth publishing a simple example. Version packages should ideally record both basic revisions, adaptor configurations, data Hashi, training targets and independent evaluation results, with clear targets for both regression and retrieval.

Check understanding

Is the order of A, B in the lower branch exchanged?

This chapter A first maps input to r dimensions and B then maps to output dimensions. Exchanges are often not matched by matrix shapes; Different libraries may be stored in switching, but mathematical mapping still needs to be matched.

Does r mean that the base model can only express one dimension of information?

No, it's not. Basic W still exists, and the new matrix BA is bound by the new matrix. The whole fit layer retains the base map, plus a limited increment.

Are there no forward activations of the basic model to freeze the base weight?

No, it's not. (b) The adjuster gradient may still rely on activation through the layers; Saves the parameter gradient from the optimist state and does not equal all active occupancy disappears simultaneously.

Can even four bits of evidence prove the error size of NF4?

Can't. Code books are not scaled in groups, and weight distributions are different. Examples show only the separation level and reconstruction errors and are not a substitute for actual quantification of errors and task assessment.

Only the adaptor file. Can you recover the model independently?

Accurate base model, configuration, tokenizer and loading protocols are usually required. The base number of the mismatch may still be capable of being loaded, but the output may be erroneous or significantly degraded.

There are few training parameters. Why is it still possible that the mission is overworked?

The parameters are not the only factor. Replication of training data, narrow targets, verification of contamination and excessive learning rates can lead to widespread fragmentation; There is still a need to separate assessments, compare base models and observe a variety of capabilities.

Nuclear for 2026-10-29: LoRA v2 、 QLoRA v1 、 PEFT Clear Use v0 21.0 Documents; These sources do not represent the framework experiments that have been carried out by the aircraft. For the next one Prefer to Learning with DPO Explain how the goal of the training has changed from “repeating the answer” to “comparison of the two answers”.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. LoRA — Low-Rank Adaptation of Large Language Models
  2. QLoRA — Efficient Finetuning of Quantized LLMs
  3. Hugging Face PEFT v0.21.0 — LoRA

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.