File size: 2,450 Bytes
f0a4c6c
4e7d5ad
f0a4c6c
4e7d5ad
 
 
 
 
5ccbada
4e7d5ad
 
f0a4c6c
4e7d5ad
 
f0a4c6c
6436c17
f0a4c6c
6436c17
5ccbada
4e7d5ad
5ccbada
4e7d5ad
 
 
 
 
 
5ccbada
4e7d5ad
5ccbada
 
 
 
 
4e7d5ad
5ccbada
 
 
4e7d5ad
5ccbada
4e7d5ad
5ccbada
4e7d5ad
5ccbada
4e7d5ad
5ccbada
4e7d5ad
 
 
 
 
 
5ccbada
c36c040
4e7d5ad
 
 
5ccbada
4e7d5ad
 
 
c36c040
4e7d5ad
c36c040
4e7d5ad
 
 
5ccbada
4e7d5ad
 
 
 
c36c040
4e7d5ad
6436c17
4e7d5ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
license: apache-2.0
tags:
  - lora
  - fine-tuning
  - adaptive
  - research
  - nested-lora
  - synaptic-plasticity
  - rank-adaptation
library_name: transformers
datasets:
  - nyu-mll/glue
pipeline_tag: text-classification
---

# Unified-LoRA

**LoRA fine-tuning with synaptic plasticity: a neurobiologically-inspired controller that switches between qualitatively different operational modes based on training stress.**

⚠️ **This is NOT a pretrained model.** Unified-LoRA is a training method/controller.

πŸ‘‰ **Code**: [github.com/Sva76/Unified-LoRa](https://github.com/Sva76/Unified-LoRa)
πŸ‘‰ **Demo**: [unified_lora_demo.ipynb](https://github.com/Sva76/Unified-LoRa/blob/main/notebooks/unified_lora_demo.ipynb)

## What It Does

A composite synaptic stress signal **Ο†(t) = f(Convergence, Entropy, Stress)** drives a 3-state FSM:

| Mode | Ο† range | Rank | Behavior |
|------|---------|------|----------|
| SINGLE | Ο† < 0.3 | r=4 | Efficient cruise |
| MULTI | 0.3 ≀ Ο† < 0.7 | r=8 | Active learning |
| MIRROR | Ο† β‰₯ 0.7 | r=16 | Max capacity + weight snapshot for rollback |

Rank transitions use **nested matrix slicing** (r4 βŠ‚ r8 βŠ‚ r16) β€” zero cold-start, zero re-allocation.

Mirror mode saves a weight snapshot on entry. On exit, if weights drifted <5% (transient noise), the snapshot is restored. If drift was significant (real signal), the new weights are kept.

## Results

**GLUE (DistilBERT):** 3/4 tasks equal or better with 33–56% rank reduction.

**Noise resilience:** +31 F1 at 50% label noise, 9Γ— lower variance. No benefit on clean data. Confirmed at 67M–3B.

**Stress-recovery cycle (Tinker/Llama-3.2-1B):** Ο† returns to pre-shock baseline (0.33 β†’ 0.83 β†’ 0.33), demonstrating fully reversible stress handling.

## Quick Start

```python
from controller import setup_unified_lora

adapters, ctrl = setup_unified_lora(model, target_modules=["q_proj", "v_proj"])

for batch in dataloader:
    loss = model(**batch).loss
    loss.backward()
    ctrl.step(loss=loss.item())  # Ο†(t) needs the loss for convergence signal
    optimizer.step()
    optimizer.zero_grad()
```

## Citation

```bibtex
@software{unified_lora_2025,
  author = {Simona Vargiu},
  title = {Unified-LoRA: Synaptic Plasticity Controller for Adaptive LoRA Fine-Tuning},
  year = {2025},
  url = {https://github.com/Sva76/Unified-LoRa}
}
```

## Contact

Simona Vargiu (Independent Researcher) β€” simona.vargiu.malta@gmail.com