Skip to content

Multiply Difference

ljleb edited this page Jun 7, 2023 · 14 revisions

Multiply difference preserves the shared characteristics between two models $A$ and $B$, with respect to a third model $C$ used as the origin of the operation. It emphasizes the common traits between models $A$ and $B$, discarding weights that disagree.

The formulae for multiply difference is:

$$M = C + \alpha S(\sqrt{|(A - C) \times (B - C)|}, A + B - 2C)$$

Where $S(v, u)$ copies the signs of $u$ and applies them to $v$ element-wise.

When a particular parameter in $A$ has a very small difference with the corresponding parameter in $C$, then the multiplication ensures that the corresponding parameter difference between $B$ and $C$ becomes smaller. The same applies from $B$ to $A$. The multiplication between the two differences produces a squared difference, which the square root turns back into a linear difference.

A parallel with logic can be drawn for this method. In some contexts, addition and logical OR are used interchangeably. Similarly, multiplication and logical AND can sometimes have the same meaning. Looking at it this way, multiply difference can be seen as an AND operation on the traits of $A$ and $B$ relative to $C$.

Examples

$A$: GhostMix civitai

$B$: Lyriel civitai

$C$: Realistic Vision v2.0 civitai

$\alpha$: 1.0

Generation params:

magnificent tree in futuristic mechanical tools forest, metallic forestscape, bolts, screws, chainsaws, best quality, 8k, intrinsic value, masterpiece
Negative prompt: worst quality low resolution draft, monochrome
Steps: 30, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 2515498628, Size: 512x512, Model hash: d7465e52e1, Model: ghostmix_v12, Denoising strength: 0.5, Hires upscale: 2, Hires steps: 20, Hires upscaler: 4x_DPED, Script: X/Y/Z plot, X Type: Checkpoint name, X Values: "ghostmix_v12.safetensors [d7465e52e1],lyriel_v16.safetensors [ec6f68ea63],Realistic_Vision_V1.4.safetensors [21c6d51e3e],wiki_muldif.safetensors"

image

$A$: GhostMix civitai

$B$: Lyriel civitai

$C$: Realistic Vision v2.0 civitai

$\alpha$: 1.0

Generation params:

stellar night of sparkling micro explosions, end of the world, massive yzyoljxv, best quality, 8k, deep emotional catastrophe, masterpiece
Negative prompt: worst quality low resolution draft, monochrome, movie title
Steps: 30, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 3027539060, Size: 512x512, Model hash: d7465e52e1, Model: ghostmix_v12, Denoising strength: 0.5, Hires upscale: 2, Hires steps: 20, Hires upscaler: 4x_DPED, Script: X/Y/Z plot, X Type: Checkpoint name, X Values: "ghostmix_v12.safetensors [d7465e52e1],lyriel_v16.safetensors [ec6f68ea63],Realistic_Vision_V1.4.safetensors [21c6d51e3e],wiki_muldif.safetensors"

image

Special Cases

C > B > A

If $C$ is a base of $B$ and $B$ is a base of $A$, then $B$ will filter any weight in $A$ that diverges from $C$. In this case, $B$ will act as a kind of filter on $A$.

A = B

By putting the same model for $A$ and $B$, we get a simple weighted sum between $C$ and $A$:

$$C + \alpha \times S(\sqrt{|(A - C) \times (B - C)|}, 2A - 2C)$$

$$= C + \alpha \times S(\sqrt{(A - C)^2}, 2(A - C))$$

$$= C + \alpha \times S(|A - C|, A - C)$$

$$= C + \alpha \times (A - C)$$

$$= C + \alpha \times A - \alpha \times C$$

$$= C - \alpha \times C + \alpha \times A$$

$$= (1 - \alpha) \times C + \alpha \times A$$

Clone this wiki locally