Skip to content

Commit 4720cde

Browse files
authored
Merge pull request #30 from t81dev/phase-20-learning-fabric-1960836874901330008
Implement Phase 20: Learning & Self-Tuning Fabric
2 parents e6f0efa + 857fcb7 commit 4720cde

8 files changed

Lines changed: 398 additions & 48 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ Telemetry exposes sparsity, residency, economic cost, and semantic efficiency in
173173

174174
## 🏗️ Project State & Architecture
175175

176-
The project is currently in **Phase 19**, representing a **Cost-Aware Economic Fabric**:
176+
The project is currently in **Phase 20**, representing a **Learning & Self-Tuning Fabric**:
177177

178-
* **Economic Introspection:** Decisions are driven by projected cost and residency rebates.
179-
* **Hysteresis Scheduling:** Stabilized tile selection to prevent state thrashing.
180-
* **Sparse-Stress Hardening:** Verified performance at 99%+ sparsity.
181-
* **Temporal Pipelining:** Overlapping memory hydration with compute.
178+
* **Adaptive Cost Modeling:** Real-time tuning of scheduler coefficients based on measured costs.
179+
* **Dynamic Scheduler Weighting:** Tiles "learn" kernel preferences to maximize economic efficiency.
180+
* **Self-Tuning Eviction:** Feedback-driven scoring protects blocks that contribute most to efficiency.
181+
* **Temporal Auto-Tuning:** Dynamic batch sizing to optimize the meaning-to-cost ratio.
182182

183183
### Architecture Layers
184184

USER_MANUAL.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ Welcome to the **Ternary Fabric** user manual. This documentation is designed to
3434
Optimizing llama.cpp and GGUF workflows.
3535
15. **[Data-Driven Adaptation](docs/19_DATA_DRIVEN_ADAPTATION.md)**
3636
Details on Phase 19 cost-aware scheduling and adaptive residency.
37-
16. **[Strategy Roadmap](docs/ROADMAP.md)**
37+
16. **[Learning & Self-Tuning](docs/20_LEARNING_AND_SELF_TUNING.md)**
38+
Phase 20 documentation on adaptive cost modeling and scheduler weighting.
39+
17. **[Strategy Roadmap](docs/ROADMAP.md)**
3840
The project roadmap detailing completed and future phases.
3941

4042
---
@@ -73,9 +75,28 @@ When running with the interposer or Python API, the Fabric provides real-time te
7375
* **Zero-Skips:** The number of operations eliminated because an operand was zero. Typically 50-75% for LLM workloads.
7476
* **Semantic Efficiency:** The ratio of useful operations (`active_ops`) to total operations.
7577
* **Economic Efficiency:** The ratio of useful operations to total `fabric_cost` (weighted sum of ops, memory, and residency misses).
78+
* **Adaptive Coefficients:** (Phase 20) Real-time values for `weight_cost`, `mem_read_cost`, etc., reflecting the scheduler's learned cost model.
7679
* **Pool Usage:** Current consumption of the 128MB emulation pool.
77-
* **Eviction Events:** Increments when the policy (Recency + Frequency) frees space for new weight frames.
78-
* **Async Queue:** Shows in-flight GEMVs being processed by the background worker thread.
80+
* **Eviction Events:** Increments when the policy (Frequency + Age + Success) frees space for new weight frames.
81+
* **Dynamic Batch Size:** (Phase 20) Shows the current auto-tuned batch size optimized for the current workload.
82+
83+
---
84+
85+
## 🤖 Adaptive Learning (Phase 20)
86+
87+
Starting with Phase 20, the Ternary Fabric is a self-tuning co-processor. It automatically optimizes its own internal parameters based on measured performance:
88+
89+
### Self-Tuning Cost Model
90+
The scheduler uses a **Hill-Climbing** algorithm to adjust its cost projection coefficients. If the actual `fabric_cost` differs from the `projected_cost`, the fabric updates its internal model to ensure more accurate tile selection in the future.
91+
92+
### Dynamic Scheduler Weighting
93+
Tiles "learn" which kernels they are most efficient at executing. A tile that consistently delivers higher **Economic Efficiency** for a specific kernel (e.g., LSTM) will be favored for that kernel in future scheduling decisions.
94+
95+
### Eviction Policy Optimization
96+
The eviction policy is no longer fixed LRU. It now dynamically weights **Frequency**, **Recency (Age)**, and **Residency Success Rate**. This ensures that weights critical to maintaining high efficiency are protected from eviction.
97+
98+
### Temporal Auto-Tuning
99+
The asynchronous command queue automatically adjusts its **Batch Size** (between 1 and 32) to maximize a composite score of efficiency and throughput. It occasionally "explores" different batch sizes to find the optimal throughput for the current sparsity regime.
79100

80101
---
81102

WHITE_PAPER.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Ternary Fabric sits at the intersection of Ternary Neural Networks (TNNs) and do
5353
As of Phase 15, the Ternary Fabric has achieved deep integration with high-level frameworks like PyTorch and native hardware acceleration for complex structures.
5454
- **PyTorch Integration:** The `TFMBSLinear` module enables seamless acceleration of deep learning models with automatic quantization and residency management.
5555
- **Native RTL Kernels:** Recurrent and attention-based structures, including **T-LSTM**, **T-Attention**, and **T-CONV3D**, are now natively supported in hardware, providing extreme throughput for diverse AI workloads.
56+
- **Learning & Self-Tuning (Phase 20):** The fabric now includes a data-driven adaptation layer that autonomously optimizes cost coefficients, scheduling multipliers, and eviction priorities in real-time, maximizing economic efficiency for dynamic workloads.
5657

5758
## 6. Conclusion
5859
The Ternary Fabric provides a scalable, efficient, and high-throughput substrate for the next generation of ternary-quantized neural networks. The successful completion of Phase 15 demonstrates that ternary-native computing can scale to meet the demands of modern AI, from LLMs to computer vision, while maintaining a fraction of the power and area overhead of binary systems.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Phase 20: Learning & Self-Tuning Fabric
2+
3+
## Overview
4+
Phase 20 introduces the **Learning Layer** to the Ternary Fabric. It moves beyond fixed heuristics and implements a self-tuning feedback loop that optimizes the co-processor's behavior based on real-time execution metrics.
5+
6+
## 1. Adaptive Cost Coefficients
7+
The scheduler's decision-making process relies on a set of projection coefficients (`weight_cost`, `mem_read_cost`, etc.). In Phase 20, these are no longer static.
8+
9+
- **Mechanism:** Hill-climbing feedback loop.
10+
- **Feedback Signal:** Error delta between `projected_cost` and actual measured `fabric_cost`.
11+
- **Goal:** Minimize projection error to ensure the scheduler always selects the truly optimal tile.
12+
13+
## 2. Dynamic Scheduler Weighting
14+
Each tile maintains a set of kernel-specific performance multipliers.
15+
16+
- **Learning:** After each kernel execution, the tile's performance multiplier is adjusted based on its **Economic Efficiency** relative to the moving average.
17+
- **Decay:** Multipliers slowly decay back toward 1.0 to ensure the fabric remains responsive to changing workload patterns.
18+
- **Result:** The fabric "learns" tile preferences automatically, favoring tiles that have historically performed best for specific operations.
19+
20+
## 3. Feedback-Driven Eviction
21+
The eviction policy uses a composite score to determine which memory blocks to keep resident.
22+
23+
- **Scoring Formula:** `Score = W_freq * Frequency + W_age * Recency + W_success * Success_Rate`
24+
- **Tuning:** If the fabric experiences high residency misses, it automatically increases the weight of success and frequency to protect critical weights.
25+
- **Result:** Automatically protected hot weights that contribute most to system efficiency.
26+
27+
## 4. Temporal Pipeline Optimization (Auto-Batching)
28+
The asynchronous execution engine dynamically tunes its batch size.
29+
30+
- **Objective Function:** `0.7 * Economic Efficiency + 0.3 * Throughput`
31+
- **Exploration:** The engine occasionally (5% of the time) tries a slightly different batch size.
32+
- **Adaptation:** If the exploration yields a better composite score, the "base" batch size is updated in that direction.
33+
34+
## 5. Economic Introspection
35+
The `economic_metrics.csv` log has been expanded to track the evolution of these learning parameters over time.
36+
37+
| Field | Description |
38+
| :--- | :--- |
39+
| `projected_cost` | The cost predicted by the scheduler. |
40+
| `batch_size` | The auto-tuned batch size used for the operation. |
41+
| `weight_cost` | The current value of the learned weight cost coefficient. |
42+
| `eviction_scores` | The scores assigned to blocks during the last eviction event. |
43+
44+
## 6. Interpreting the Learning Curve
45+
When analyzing logs, a healthy "learning" phase should show:
46+
1. `projected_cost` converging toward `fabric_cost`.
47+
2. `economic_efficiency` steadily increasing as the scheduler favors better tiles.
48+
3. `dynamic_batch_size` stabilizing at a value that balances latency and throughput.

docs/ROADMAP.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,15 @@ Using Phase 18 metrics to drive autonomous fabric behavior and scheduling.
148148
* **Sparse-Regime Hardening:** Verified efficiency in 95-99% sparse regimes with dedicated stress benchmarks.
149149
* **KPI Maturation:** Introduction of `Economic Efficiency` (Meaning / Cost) vs `Semantic Efficiency` (Meaning / Ops).
150150

151+
### Phase 20 — Learning & Self-Tuning Fabric ✅
152+
Turning heuristics into a self-tuning system that optimizes its own parameters.
153+
* **Status:** Complete.
154+
* **Deliverables:**
155+
* **Adaptive Cost Coefficients:** Scheduler now uses a hill-climbing feedback loop to minimize the delta between projected and actual costs.
156+
* **Dynamic Scheduler Weighting:** Per-tile/per-kernel multipliers that adapt based on historical economic efficiency.
157+
* **Eviction Policy Self-Tuning:** Scoring weights (frequency, recency, success) adjust automatically to maximize residency hit rates.
158+
* **Temporal Pipeline Optimization:** Auto-tuning of async batch sizes to maximize a composite efficiency/throughput score.
159+
151160
---
152161

153162
# 🔑 What This Strategy Gives You

0 commit comments

Comments
 (0)