PeetPedro commited on
Commit
a021b9b
·
verified ·
1 Parent(s): da67c0c

Upload MODEL_CARD.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. MODEL_CARD.md +82 -2
MODEL_CARD.md CHANGED
@@ -6,6 +6,8 @@ tags:
6
  - bitnet
7
  - ggml
8
  - simd
 
 
9
  - edge-ai
10
  - binary-release
11
  license: mit
@@ -14,7 +16,7 @@ library_name: smart-tree
14
 
15
  # smart-tree — Ternary Inference Engine
16
 
17
- 🚀 **Production-ready binary for BitNet 1.58-bit / GGUF I2_S (type 36) inference with SIMD acceleration**
18
 
19
  ## Overview
20
 
@@ -100,7 +102,7 @@ pub enum I2SScaleSource {
100
  }
101
  ```
102
 
103
- ## NEW: SIMD-Accelerated Ternary GEMM (Experiment 3)
104
 
105
  Integrated **FELIX SIMD hot-path engine** for blazing-fast ternary matrix multiplies:
106
 
@@ -135,6 +137,70 @@ let out_val = simd_ternary_row_i2s(&row_weights_i2s, &activations, scale);
135
  - **Prefetch hints** for sequential layer traversal
136
  - **Exact integer arithmetic** throughout (no FP in hot path)
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  ## Integration
139
 
140
  ### As Rust Dependency
@@ -146,6 +212,7 @@ smart-tree = { git = "https://github.com/peterlodri-sec/smart-tree" }
146
  ```rust
147
  use smart_tree::gguf_interop::{I2SPacker, GgufI2SBridge};
148
  use smart_tree::simd_ternary::{simd_ternary_gemm_i2s, simd_backend};
 
149
 
150
  // Low-level pack
151
  let bytes = I2SPacker::pack_trits(&[-1, 0, 1, 0]);
@@ -158,6 +225,16 @@ let wave = GgufI2SBridge::i2s_to_wave64(&i2s)?;
158
  // SIMD GEMM
159
  println!("Running on: {}", simd_backend());
160
  simd_ternary_gemm_i2s(&weights, rows, cols, &acts, &mut out, scales);
 
 
 
 
 
 
 
 
 
 
161
  ```
162
 
163
  ## Testing
@@ -167,6 +244,7 @@ All cores validated:
167
  cargo test --lib ternary_bridge # 7 tests - lossless bridges
168
  cargo test --lib gguf_interop # 10 tests - GGUF I2_S roundtrips
169
  cargo test --lib simd_ternary # 5 tests - SIMD GEMM correctness
 
170
  ```
171
 
172
  ## Related Work
@@ -175,6 +253,8 @@ cargo test --lib simd_ternary # 5 tests - SIMD GEMM correctness
175
  - **[Falcon3-I2_S](https://huggingface.co/tiiuae/Falcon3-3B-Instruct-GGUF)**: Reference GGUF I2_S model
176
  - **[enthea](https://github.com/peterlodri-sec/enthea)**: Sister crate for quantized GEMM/attention
177
  - **[FELIX Assembly](https://github.com/peterlodri-sec/felix-assembly)**: CPU-agnostic SIMD ISA
 
 
178
 
179
  ## License
180
 
 
6
  - bitnet
7
  - ggml
8
  - simd
9
+ - lora
10
+ - finetuning
11
  - edge-ai
12
  - binary-release
13
  license: mit
 
16
 
17
  # smart-tree — Ternary Inference Engine
18
 
19
+ 🚀 **Production-ready binary for BitNet 1.58-bit / GGUF I2_S (type 36) inference with SIMD acceleration and LoRA-T fine-tuning**
20
 
21
  ## Overview
22
 
 
102
  }
103
  ```
104
 
105
+ ## Experiment 3: SIMD-Accelerated Ternary GEMM ✅
106
 
107
  Integrated **FELIX SIMD hot-path engine** for blazing-fast ternary matrix multiplies:
108
 
 
137
  - **Prefetch hints** for sequential layer traversal
138
  - **Exact integer arithmetic** throughout (no FP in hot path)
139
 
140
+ ## NEW: Experiment 4 — LoRA-T Fine-Tuning ✅
141
+
142
+ **LoRA-T: Low-Rank Adaptation for Ternary Weights**
143
+
144
+ Adapts QLoRA methodology to frozen ternary (BitNet 1.58-bit) bases:
145
+ - Freeze pretrained ternary weights (I2_S / BitNetWave64)
146
+ - Inject trainable low-rank adapters (A @ B) in FP32
147
+ - Forward: `y = W_ternary @ x + α * (A @ B) @ x`
148
+ - Gradient flows only through A, B (ranks typically 8-64)
149
+ - Fusion support for zero-overhead inference
150
+
151
+ Based on: Hu et al. "LoRA: Low-Rank Adaptation..." + Dettmers et al. "QLoRA"
152
+
153
+ ### API
154
+ ```rust
155
+ use smart_tree::lora_ternary::{
156
+ LoraTConfig, LoraAdapter, LoraTModel, LoraTTrainer,
157
+ lorat_qwen2_5_05b, lorat_small_test,
158
+ };
159
+
160
+ // Configure LoRA
161
+ let config = LoraTConfig {
162
+ rank: 16,
163
+ alpha: 16.0,
164
+ dropout: 0.1,
165
+ target_modules: vec!["q_proj".into(), "v_proj".into(), /* ... */],
166
+ fused_inference: true,
167
+ init_strategy: InitStrategy::Standard,
168
+ };
169
+
170
+ // Factory for Qwen2.5-0.5B
171
+ let mut model = lorat_qwen2_5_05b(config);
172
+ // Or small test model
173
+ let mut model = lorat_small_test(LoraTConfig { rank: 8, ..Default::default() });
174
+
175
+ // Training step
176
+ let mut trainer = LoraTTrainer::new(&mut model, 1e-4);
177
+ trainer.step(&[
178
+ ("layers.0.self_attn.q_proj", &input_acts, &output_grads),
179
+ // ...
180
+ ]);
181
+
182
+ // Inference: fuse adapters into base weights
183
+ for adapter in model.adapters.values() {
184
+ adapter.fuse_into(&mut base_weights);
185
+ }
186
+ // Now base_weights includes LoRA deltas — no extra compute at inference!
187
+
188
+ // Manual forward (alongside base model)
189
+ let mut out = vec![0.0f32; out_dim];
190
+ adapter.forward(&input, &mut out); // Adds α(A@B)x to base output
191
+ ```
192
+
193
+ ### Parameter Efficiency
194
+ | Model | Frozen Params | LoRA Params (r=16) | Ratio |
195
+ |-------|---------------|--------------------|-------|
196
+ | Qwen2.5-0.5B | ~500M | ~2.1M | 0.4% |
197
+ | Llama-3-8B | ~8B | ~4.2M | 0.05% |
198
+
199
+ ### Initialization Strategies
200
+ - **Standard**: A ~ N(0, √(2/in_dim)), B = 0 (Hu et al.)
201
+ - **Balanced**: Both ~ N(0, 1/√rank) (SDXL style)
202
+ - **Orthogonal**: QR-factorized for numerical stability
203
+
204
  ## Integration
205
 
206
  ### As Rust Dependency
 
212
  ```rust
213
  use smart_tree::gguf_interop::{I2SPacker, GgufI2SBridge};
214
  use smart_tree::simd_ternary::{simd_ternary_gemm_i2s, simd_backend};
215
+ use smart_tree::lora_ternary::{lorat_qwen2_5_05b, LoraTTrainer, LoraTConfig};
216
 
217
  // Low-level pack
218
  let bytes = I2SPacker::pack_trits(&[-1, 0, 1, 0]);
 
225
  // SIMD GEMM
226
  println!("Running on: {}", simd_backend());
227
  simd_ternary_gemm_i2s(&weights, rows, cols, &acts, &mut out, scales);
228
+
229
+ // LoRA-T fine-tuning
230
+ let mut model = lorat_qwen2_5_05b(LoraTConfig { rank: 16, ..Default::default() });
231
+ let mut trainer = LoraTTrainer::new(&mut model, 1e-4);
232
+ // ... training loop ...
233
+
234
+ // Deploy: fuse and serialize
235
+ for adapter in model.adapters.values() {
236
+ adapter.fuse_into(&mut base_weights);
237
+ }
238
  ```
239
 
240
  ## Testing
 
244
  cargo test --lib ternary_bridge # 7 tests - lossless bridges
245
  cargo test --lib gguf_interop # 10 tests - GGUF I2_S roundtrips
246
  cargo test --lib simd_ternary # 5 tests - SIMD GEMM correctness
247
+ cargo test --lib lora_ternary # 6 tests - LoRA-T forward/backward/fusion
248
  ```
249
 
250
  ## Related Work
 
253
  - **[Falcon3-I2_S](https://huggingface.co/tiiuae/Falcon3-3B-Instruct-GGUF)**: Reference GGUF I2_S model
254
  - **[enthea](https://github.com/peterlodri-sec/enthea)**: Sister crate for quantized GEMM/attention
255
  - **[FELIX Assembly](https://github.com/peterlodri-sec/felix-assembly)**: CPU-agnostic SIMD ISA
256
+ - **[LoRA](https://arxiv.org/abs/2106.09685)**: Low-Rank Adaptation
257
+ - **[QLoRA](https://arxiv.org/abs/2305.14314)**: Efficient Finetuning of Quantized LLMs
258
 
259
  ## License
260