description: <p><a target="_blank" rel="ugc" href="https://github.com/TkskKurumi/DiffusersFastAPI/blob/main/model_as_lora.py">https://github.com/TkskKurumi/DiffusersFastAPI/blob/main/model_as_lora.py</a></p><p>I've attempted to develop an algorithm that can calculate LoRA from subtracting two trained full model. The core is to compress the full Δw (weight difference) matrix into LoRA. </p><p></p><p>I think my matrix compression algorithm is not good enough. I'm not good at linear algebra (or I don't even know what fields of knowledge is needed for the task).</p><p>Compress matrix W of shape(m, n) into matul of A and B of shapes (m, rank) and (rank, n). The compress ratio according to parameter amount is rank*(m+n)/(m*n). I've found that ratio = 25% may nearly represent <a rel="ugc" href="https://civitai.com/models/18427">Fantexi </a>subtract <a rel="ugc" href="https://civitai.com/models/101518/rmhf">my anime model</a>. And ratio=5% with lora alpha doubled has adequate result.</p><p>I've also tried the algorithm to take image as input and use 2 matrixs of shapes (width, rank) (rank, height). Following image has original 1080 pixels width and height and compressed into low rank 32.</p><p><img src="https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/61fb92a4-9a67-49cf-848b-2038f75caf6c/width=525/61fb92a4-9a67-49cf-848b-2038f75caf6c.jpeg" /></p><p></p>
modelVersions.availability: Public
modelVersions.baseModel: SD 1.5
modelVersions.description: <p>The LoRA ≈ A - B. Compress ratio = 25%</p><p>A: <a target="_blank" rel="ugc" href="https://civitai.com/models/101518/rmhf">https://civitai.com/models/101518</a></p><p>B: <a target="_blank" rel="ugc" href="https://civitai.com/models/18427">https://civitai.com/models/18427</a></p>
modelVersions.downloadUrl: https://civitai.com/api/download/models/137811
modelVersions.downloaded: 500
modelVersions.downloadUrl: https://civitai.com/api/download/models/137811
modelVersions.AutoV1: CB67B235
modelVersions.AutoV2: 19799E27C7
modelVersions.AutoV3: E34AB5ADCF1C
modelVersions.BLAKE3: 8F86EC2CF5E96CCACBE95AF0FEDB63BF8DB0B70252686D2C349EF99A1F8CEFEC
modelVersions.CRC32: 19010F31
modelVersions.SHA256: 19799E27C7AEE56B8FC5E2945DFF52E38945AC2D27FE5D52F93A813CA9AB31EB
modelVersions.format: SafeTensor
modelVersions.name: fantexi_25%.safetensors
modelVersions.pickleScanMessage: No Pickle imports
modelVersions.pickleScanResult: Success
modelVersions.scannedAt: 2023-08-10T05:46:22.498Z
modelVersions.type: Model
modelVersions.virusScanResult: Success
modelVersions.hash: USD,s6~qtlNGNwbcxa$*RPoLxvozM{IoWDtR
modelVersions.type: image
modelVersions.url: https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/1a08f577-bc9b-42ca-b46b-82efe1d3e4fc/width=450/1958430.jpeg
modelVersions.hash: UPH^}1~XEQM{w4ohNsSiIpxbo}W:yDxuWBxa
modelVersions.type: image
modelVersions.url: https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/263ed6fb-38c6-4099-9038-ad1ad0422b8b/width=450/1958431.jpeg
modelVersions.hash: UAD+[A4n4n~qE1IUNFRP00-;-;V@ROWBenD%
modelVersions.type: image
modelVersions.url: https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/03818692-93ee-4a37-b84f-c588da2ac4c9/width=450/1958432.jpeg
modelVersions.name: fantexi
modelVersions.publishedAt: 2023-08-10T05:59:47.446Z
name: LoRA Extraction tests
tags: style