Skip to content

Commit 9e1b7a2

Browse files
committed
fix: avoid bank update in VBLoRAAdapter ctor
1 parent 9e8520a commit 9e1b7a2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/LoRA/Adapters/VBLoRAAdapter.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ public VBLoRAAdapter(
311311
{
312312
_bankIndicesB = GenerateRandomIndices(rank, bankSizeB);
313313
}
314+
315+
// Now that banks + indices are initialized, sync the underlying LoRA layer to the selected vectors.
316+
UpdateLoRALayerFromBanks(_loraLayer);
314317
}
315318

316319
/// <summary>
@@ -406,16 +409,13 @@ private int[] GenerateRandomIndices(int count, int maxValue)
406409
/// </remarks>
407410
protected override LoRALayer<T> CreateLoRALayer(int rank, double alpha)
408411
{
409-
// Create a standard LoRA layer - we'll override its matrices with bank-selected vectors
410412
int inputSize = GetInputShape()[0];
411413
int outputSize = GetOutputShape()[0];
412414

413-
LoRALayer<T> loraLayer = new LoRALayer<T>(inputSize, outputSize, rank, alpha);
414-
415-
// Replace the LoRA layer's matrices with bank-selected vectors
416-
UpdateLoRALayerFromBanks(loraLayer);
417-
418-
return loraLayer;
415+
// Important: this virtual is invoked from the base constructor, before VB-LoRA banks/indices are initialized.
416+
// We therefore only construct a standard LoRA layer here and let the derived constructor/Forward() synchronize
417+
// it with the vector banks once initialization is complete.
418+
return new LoRALayer<T>(inputSize, outputSize, rank, alpha);
419419
}
420420

421421
/// <summary>

0 commit comments

Comments
 (0)