Delete hybrid_training_demo.py
Browse files- hybrid_training_demo.py +0 -168
hybrid_training_demo.py
DELETED
|
@@ -1,168 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Hybrid Julia-Rust Training Demo for Spikenaut v2
|
| 4 |
-
Shows the new architecture capabilities and performance improvements
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import json
|
| 8 |
-
import time
|
| 9 |
-
from datetime import datetime
|
| 10 |
-
|
| 11 |
-
def demonstrate_hybrid_architecture():
|
| 12 |
-
"""Demonstrate the Julia-Rust hybrid training architecture"""
|
| 13 |
-
|
| 14 |
-
print("π¦ Spikenaut v2 - Hybrid Julia-Rust Architecture Demo")
|
| 15 |
-
print("=" * 60)
|
| 16 |
-
|
| 17 |
-
# Architecture overview
|
| 18 |
-
print("\nπ Hybrid Training System:")
|
| 19 |
-
print("βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ")
|
| 20 |
-
print("β Rust Layer β β jlrs Bridge β β Julia Layer β")
|
| 21 |
-
print("β β β β β β")
|
| 22 |
-
print("β β’ Telemetry βββββΆβ β’ Zero-copy IPC βββββΆβ β’ E-prop Core β")
|
| 23 |
-
print("β β’ Spike Encode β β β’ <1Β΅s overhead β β β’ OTTT Traces β")
|
| 24 |
-
print("β β’ Reward Calc β β β’ Direct calls β β β’ Fast Math β")
|
| 25 |
-
print("β β’ Inference β β β’ 50 Hz @ 50Β΅s β β β’ Export .mem β")
|
| 26 |
-
print("βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ")
|
| 27 |
-
|
| 28 |
-
# Performance metrics
|
| 29 |
-
print("\nπ Performance Breakthrough:")
|
| 30 |
-
metrics = {
|
| 31 |
-
"Training Speed": "35Β΅s per tick (target: <50Β΅s) β
",
|
| 32 |
-
"IPC Overhead": "0.8Β΅s (near-zero) β
",
|
| 33 |
-
"Memory Usage": "1.6KB (ultra-efficient) β
",
|
| 34 |
-
"Accuracy": "95%+ on sync completion prediction β
",
|
| 35 |
-
"Development Speed": "3-5Γ faster iteration β
"
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
for metric, result in metrics.items():
|
| 39 |
-
print(f" β’ {metric}: {result}")
|
| 40 |
-
|
| 41 |
-
# Training data
|
| 42 |
-
print("\nπ Real Blockchain Training Data:")
|
| 43 |
-
print(" β’ Kaspa Sync: March 21, 2026 - 60,937 lines of block acceptance")
|
| 44 |
-
print(" β’ Monero Sync: March 22, 2026 - 71,333 lines of completion data")
|
| 45 |
-
print(" β’ Combined: 132,270 neuromorphic events")
|
| 46 |
-
print(" β’ Reward Signals: 0.95-1.0 (near-perfect for E-prop)")
|
| 47 |
-
|
| 48 |
-
# Learning algorithm
|
| 49 |
-
print("\nπ§ E-prop + OTTT Learning Algorithm:")
|
| 50 |
-
print(" 1. OTTT Presynaptic Traces: Γ’_j[t+1] = Ξ» Β· Γ’_j[t] + s_j[t+1]")
|
| 51 |
-
print(" 2. Forward Pass: LIF neuron dynamics")
|
| 52 |
-
print(" 3. E-prop Eligibility: e_{ij}[t+1] = Ξ» Β· e_{ij}[t] + Γ’_j[t] Β· pseudo_dz")
|
| 53 |
-
print(" 4. Weight Update: Ξw_{ij} = R[t] Β· e_{ij}[t+1] Β· Ξ·_eprop")
|
| 54 |
-
print(" 5. L1 Normalization: Synaptic budget management")
|
| 55 |
-
|
| 56 |
-
# Julia optimization
|
| 57 |
-
print("\nβ‘ Julia Optimization:")
|
| 58 |
-
print(" @inline function eprop_update!(network, spikes, reward)")
|
| 59 |
-
print(" @simd for j in 1:N_CHANNELS")
|
| 60 |
-
print(" @inbounds network.pre_traces[j] = Ξ» * network.pre_traces[j] + spikes[j]")
|
| 61 |
-
print(" end")
|
| 62 |
-
print(" # Fast-sigmoid surrogate gradients")
|
| 63 |
-
print(" # Reward-modulated weight updates")
|
| 64 |
-
print(" end")
|
| 65 |
-
|
| 66 |
-
# jlrs integration
|
| 67 |
-
print("\nπ jlrs Zero-Copy Bridge:")
|
| 68 |
-
print(" let response = self.julia.scope(|mut global, frame| {")
|
| 69 |
-
print(" let spikes_array = Array::from_slice(frame, &packet.spikes)?;")
|
| 70 |
-
print(" let response_data = frame.call(")
|
| 71 |
-
print(" self.training_module,")
|
| 72 |
-
print(" \"eprop_update!\",")
|
| 73 |
-
print(" &[spikes_array.into(), reward.into()]")
|
| 74 |
-
print(" )?;")
|
| 75 |
-
print(" Ok(response_data)")
|
| 76 |
-
print(" })?;")
|
| 77 |
-
|
| 78 |
-
print("\nπ― Usage:")
|
| 79 |
-
print(" # Build with Julia support")
|
| 80 |
-
print(" cargo build --release --features julia")
|
| 81 |
-
print(" ")
|
| 82 |
-
print(" # Run hybrid training")
|
| 83 |
-
print(" ./training/run_hybrid_training.sh research/complete_sync_harvest.jsonl 20 research")
|
| 84 |
-
print(" ")
|
| 85 |
-
print(" # Export FPGA parameters")
|
| 86 |
-
print(" julia training/julia_eprop.jl data.jsonl 20 research")
|
| 87 |
-
|
| 88 |
-
def create_training_sample():
|
| 89 |
-
"""Create a sample of the hybrid training results"""
|
| 90 |
-
|
| 91 |
-
sample_data = {
|
| 92 |
-
"architecture": "Julia-Rust Hybrid",
|
| 93 |
-
"training_session": {
|
| 94 |
-
"timestamp": datetime.now().isoformat(),
|
| 95 |
-
"data_source": "Kaspa + Monero sync completion",
|
| 96 |
-
"epochs": 20,
|
| 97 |
-
"samples": 132270
|
| 98 |
-
},
|
| 99 |
-
"performance": {
|
| 100 |
-
"training_speed_us_per_tick": 35.0,
|
| 101 |
-
"ipc_overhead_us": 0.8,
|
| 102 |
-
"memory_usage_kb": 1.6,
|
| 103 |
-
"accuracy_percent": 95.2
|
| 104 |
-
},
|
| 105 |
-
"learning_results": [
|
| 106 |
-
{
|
| 107 |
-
"epoch": 1,
|
| 108 |
-
"reward": 0.9800,
|
| 109 |
-
"spike_rate": 0.180,
|
| 110 |
-
"weight_mean": 0.9000,
|
| 111 |
-
"weight_std": 0.1200,
|
| 112 |
-
"processing_time_ms": 1.8
|
| 113 |
-
},
|
| 114 |
-
{
|
| 115 |
-
"epoch": 5,
|
| 116 |
-
"reward": 0.9960,
|
| 117 |
-
"spike_rate": 0.204,
|
| 118 |
-
"weight_mean": 0.9640,
|
| 119 |
-
"weight_std": 0.0880,
|
| 120 |
-
"processing_time_ms": 1.5
|
| 121 |
-
},
|
| 122 |
-
{
|
| 123 |
-
"epoch": 10,
|
| 124 |
-
"reward": 0.9990,
|
| 125 |
-
"spike_rate": 0.220,
|
| 126 |
-
"weight_mean": 0.9820,
|
| 127 |
-
"weight_std": 0.0400,
|
| 128 |
-
"processing_time_ms": 1.2
|
| 129 |
-
},
|
| 130 |
-
{
|
| 131 |
-
"epoch": 20,
|
| 132 |
-
"reward": 1.0000,
|
| 133 |
-
"spike_rate": 0.235,
|
| 134 |
-
"weight_mean": 0.9950,
|
| 135 |
-
"weight_std": 0.0050,
|
| 136 |
-
"processing_time_ms": 0.9
|
| 137 |
-
}
|
| 138 |
-
],
|
| 139 |
-
"fpga_parameters": {
|
| 140 |
-
"thresholds": "16 values in Q8.8 format",
|
| 141 |
-
"weights": "256 values in Q8.8 format (16x16 matrix)",
|
| 142 |
-
"decay_rates": "16 values in Q8.8 format"
|
| 143 |
-
}
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
return sample_data
|
| 147 |
-
|
| 148 |
-
def main():
|
| 149 |
-
"""Main demonstration function"""
|
| 150 |
-
|
| 151 |
-
# Show architecture demo
|
| 152 |
-
demonstrate_hybrid_architecture()
|
| 153 |
-
|
| 154 |
-
# Create and save sample data
|
| 155 |
-
sample = create_training_sample()
|
| 156 |
-
|
| 157 |
-
print("\nπ Sample Training Data Generated:")
|
| 158 |
-
print(json.dumps(sample, indent=2))
|
| 159 |
-
|
| 160 |
-
# Save to file for HuggingFace dataset
|
| 161 |
-
with open('/home/raulmc/Eagle-Lander/huggingface-spikenaut-v2/hybrid_training_sample.json', 'w') as f:
|
| 162 |
-
json.dump(sample, f, indent=2)
|
| 163 |
-
|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