Skip to content

Adapter algebra (v0.71.34)

soup adapters arithmetic applies task arithmetic (arXiv:2212.04089) to LoRA deltas. You add to blend two skills, scale to dial one down, and, the differentiator, negate to subtract one. The output is a single loadable adapter.

bash
soup adapters arithmetic "coder + 0.5*math - toxic" \
    --adapter coder=./coder-lora \
    --adapter math=./math-lora \
    --adapter toxic=./toxic-lora \
    -o ./blended

Names in the expression map to adapter directories via the repeatable --adapter name=path. Exit 0 = ok, 1 = refusal (a bad expression, an unknown name, a path outside the working directory, an -o that is one of the input adapters, or an expression whose terms cancel to zero), 2 = a mistyped or missing option, which is Click's code. The output directory holds a normal adapter_model.safetensors and adapter_config.json, so soup adapters check reads it like any other adapter (v0.76.0): alive means the blend moved away from zero, not that the blend is good.

Why the coefficient math matters

A LoRA does not store its delta directly; it stores two factors whose product is the effective weight change, ΔW = B @ A. Scale both factors by a coefficient c and the delta scales by c², which quietly breaks the whole idea: - toxic (c = -1) would square to +1 and become a no-op instead of a removal.

Soup splits the coefficient as the square root of its absolute value across the two factors and carries the sign, so the delta scales linearly: negation flips it, 0.5* halves it, 2* doubles it. The live check on two real rank-8 adapters: ||ΔW(2·a)|| / ||ΔW(a)|| = 2.000 exactly, where the old c² bug gives 4.0.

Be precise about how far that exactness goes: it holds on the self (diagonal) term, so scaling or negating a single adapter is exact. A multi-adapter sum (like the example above) also carries cross-terms between the adapters, which this element-wise combine does not cancel.

Mixed ranks are now exact (v0.72.0)

Mixed-rank inputs used to be refused with a "harmonize rank" message. As of v0.72.0 they are handled exactly, not approximated.

The reason it is exact is structural rather than numerical. A LoRA delta is ΔW = B @ A, so stacking the A factors of the inputs on top of each other and the coefficient-scaled B factors side by side gives a single adapter whose product is the sum of the individual deltas, by construction. Concatenation loses nothing; there is no approximation step to be wrong about. The output simply carries the summed rank.

bash
# rank-8 and rank-16 adapters in one expression: no longer a refusal
soup adapters arithmetic "coder + 0.5*math" \
  --adapter coder=./coder-r8 --adapter math=./math-r16 -o ./blended

# ask for a fixed output rank instead of the concatenated one
soup adapters arithmetic "coder + 0.5*math" \
  --adapter coder=./coder-r8 --adapter math=./math-r16 --rank 16 -o ./blended

--rank N truncates the concatenated result with an SVD, which is where an approximation does enter, deliberately and only when you ask for it: you are choosing a smaller adapter over an exact one. Without --rank, nothing is discarded.

Ranks are no longer a reason to refuse. Genuinely incompatible layer shapes still are.

What it refuses

GuardBehaviour
Mixed ranksHandled exactly by concatenation since v0.72.0; --rank N truncates with an SVD if you want a fixed output rank
Different base modelsRefused; --allow-cross-base overrides
A FAIL-scanned inputRefused by the backdoor-scan gate; --allow-unscanned skips it
Paths outside the working dir, symlinksRejected
-o the same file as an input adapterRefused since v0.77.2 (#2379 by @ShryukGrandhi), exit 1, before any adapter is read: Output path refused: --output 'x' is the same file as adapter a 'x'; choose a different --output. Through v0.77.1 the input adapter's weights and config were overwritten in place

The combine is signed and un-normalized. Same-rank inputs combine element-wise; mixed-rank inputs combine by concatenation, which is exact by construction (v0.72.0).

A bias tensor changed in v0.78.0. For adapters saved with lora_bias=True, soup adapters arithmetic without --rank gave the lora_B.bias tensor the square root of its coefficient, as if it were a factor, where the --rank path gave it the coefficient. Both paths now give it the coefficient (#2927), so with coefficients other than 1 and -1 that bias changes on soup adapters arithmetic. soup adapters merge keeps scaling it by the weight, and its own weight rule changed in the same release.

The expression parser is hand-written. There is no eval, so an adapter name can never become code.

Honesty

What is proven is the mechanism: the delta really does negate, and the scaling ratio is exact to 2.000 on real adapters. What is not benchmarked is the behavioural outcome, so treat - toxic as "subtract that adapter's delta", not as a certified safety control. Whether subtracting a toxicity adapter measurably reduces toxicity on a real safety eval is an open question upstream calls proof-of-mechanism. Measure it on your own eval before you rely on it.

See also

Soup is free and Apache-2.0. If it saved you a training run, starring the repo costs nothing and helps most. You can also fund the GPU time behind the work a 4 GB laptop cannot reach.