Three optimizations targeting GPU allocation churn and lock contention: 1. In-place polyak update: Var::set() reuses existing GPU buffer instead of Var::from_tensor() which allocates a new one per call. Eliminates ~10,000 cudaMalloc/cudaFree per epoch (20 params × 500 steps). 2. Fused affine ops: Replace 13 Tensor::full()/Tensor::ones() constant tensor allocations per step with tensor.affine(mul, add) — a single fused kernel. Patterns: 1-x → x.affine(-1,1), γ*x → x.affine(γ,0), 0.5*x² → (x*x).affine(0.5,0). Applied across all 4 loss paths (branching Bellman/Huber, standard Bellman/Huber, IQN). Eliminates ~6,500 GPU allocs/epoch. 3. Batch pre-sampling (K=8): Sample 8 batches under one READ lock, train all 8 under one WRITE lock. Reduces async lock acquisitions from 2×N to 2×ceil(N/8). Priority staleness across 8 steps is negligible. Combined estimated impact: 20-35% H100 throughput improvement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ml
10-model ML ensemble for the Foxhunt HFT system, built on Candle v0.9.1.
Models
- DQN (Rainbow) — deep Q-network with prioritized replay, dueling heads, noisy nets
- PPO — proximal policy optimization with GAE, LSTM policies, clip-higher
- TFT — temporal fusion transformer for multi-horizon forecasting
- Mamba2 — state space model for sequence prediction
- Liquid Networks — biologically inspired networks for non-stationary data
- TLOB — transformer-based limit order book analysis
- KAN — Kolmogorov-Arnold networks
- xLSTM — extended LSTM architecture
- TGGN — temporal graph neural network
- Diffusion — diffusion-based generative model
Key Modules
ensemble— model ensemble coordination and confidence aggregationhyperopt— PSO-based hyperparameter optimization with per-model adapterstrainers— unified training loops (DQN, PPO, supervised)inference—InferenceAdaptertrait for predictioncheckpoint— model checkpointing and restorationevaluation— walk-forward evaluation pipeline
Usage
use ml::dqn::DQN;
use ml::ppo::PpoTrainer;