Skip to content

Commit f8fba90

Browse files
committed
fix: init VBLoRA bank B with small noise
1 parent ee44996 commit f8fba90

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/LoRA/Adapters/VBLoRAAdapter.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,20 @@ private void InitializeBanksIfNeeded(int inputSize, int outputSize)
349349
if (!_globalBankB.ContainsKey(_bankKey))
350350
{
351351
Matrix<T> bankB = new Matrix<T>(_bankSizeB, outputSize);
352+
T stddev = NumOps.Multiply(
353+
NumOps.Sqrt(NumOps.Divide(NumOps.One, NumOps.FromDouble(_bankSizeB))),
354+
NumOps.FromDouble(0.01));
352355

353-
// Initialize with zeros (so adapters start with no effect, like standard LoRA B matrix)
356+
// Initialize with small Gaussian random values so both A and B receive gradient signal immediately.
354357
for (int i = 0; i < _bankSizeB; i++)
355358
{
356359
for (int j = 0; j < outputSize; j++)
357360
{
358-
bankB[i, j] = NumOps.Zero;
361+
// Box-Muller transform for Gaussian random numbers
362+
double u1 = Random.NextDouble();
363+
double u2 = Random.NextDouble();
364+
double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2);
365+
bankB[i, j] = NumOps.Multiply(NumOps.FromDouble(randStdNormal), stddev);
359366
}
360367
}
361368

0 commit comments

Comments
 (0)