#1056·ai-toolkit

Bug: Zero-gradient deadlock when expanding LoRA/DoRA rank (New capacity remains completely unused)

Author: WilameSouzaCreated Sep 21, 2026Updated Sep 21, 2026

Description

When resuming a LoRA/DoRA training with a higher rank (e.g., expanding from Rank 128 to Rank 160), the newly added capacity is completely ignored by the model. It fails to learn new concepts and behaves as if the latent space is still restricted to the original rank.

I ran an SVD analysis on the expanded DoRA blocks, and it confirms that the "effective rank" remains strictly capped at the original rank (128). The newly added 32 dimensions remain completely untouched throughout the subsequent training steps.

Root Cause (The Zero-Gradient Deadlock)

The issue lies in how the new dimensions are initialized during the upscale process in toolkit/network_mixins.py (inside the load_weights method).

Currently, when expanding the rank, the code pads both lora_down (matrix A) and lora_up (matrix B) using torch.zeros().

Because the forward pass is $\Delta W = B \times A$, the backward pass relies on the chain rule:

  • The gradient for $A$ depends on the current values of $B$.
  • The gradient for $B$ depends on the current values of $A$.

Since both the new rows in $A$ and new columns in $B$ are strictly 0, their respective gradients will also be 0 on the very first backward pass. The newly added dimensions are trapped in a zero-gradient deadlock (saddle point) and will never update.

Proposed Solution

To fix this, we need to mimic the standard LoRA initialization behavior for the newly added dimensions:

  • lora_up (matrix B) should continue to be padded with zeros (this ensures the model's output isn't destroyed/altered when resuming).
  • lora_down (matrix A) should be padded with random values (e.g., using Kaiming Uniform), so that matrix B can actually receive gradients right from step 1.

Suggested Code Change

In toolkit/network_mixins.py (around line 749), the lora_down expansion block should be changed:

From:

python
elif "lora_down" in key and src_h < tgt_h:
    print_once(f"Expanding {key} from {load_value.shape} to {blank_val.shape}")
    new_val = torch.zeros((tgt_h, tgt_w), device=load_value.device, dtype=load_value.dtype)
    new_val[:src_h, :src_w] = load_value  # src_w should already match
    load_sd[key] = new_val
    self.did_change_weights = True

To:

python
elif "lora_down" in key and src_h < tgt_h:
    print_once(f"Expanding {key} from {load_value.shape} to {blank_val.shape}")
    
    import math
    new_val = torch.empty((tgt_h, tgt_w), device=load_value.device, dtype=load_value.dtype)
    torch.nn.init.kaiming_uniform_(new_val, a=math.sqrt(5))
    
    new_val[:src_h, :src_w] = load_value  # preserve previously trained weights
    load_sd[key] = new_val
    self.did_change_weights = True

(The block for lora_up should be left untouched, as it correctly uses zeros).

Written by Aisha running through Gemini 3.1 Pro Preview (jailbreaked)