Files
foxhunt/crates/ml
jgrusewski 7d538d9304 feat(sp21): T2.2 Phase 1 Step B — per-trade tape buffers + readback (atomic)
Replaces Step A's NULL launcher passes with real device buffers.
Both kernel launch sites in gpu_backtest_evaluator.rs (backtest_env_step
and backtest_env_step_batch) now pass real per-trade tape pointers.
The kernel's per-trade emission block fires unconditionally on close
events — single-threaded per-window writes preserve event ordering and
enable race-free counter increment without atomicAdd.

New constants + types:
  - MAX_TRADES_PER_WINDOW = 200_000 (typical eval window bar count;
    per-window memory: 4 SoA buffers × 4 bytes × 200k = 3.2MB)
  - pub struct EvalTrade with 5 fields: bar_index, pnl, holding_bars,
    direction, magnitude. Does NOT include predicted_q / ensemble_var
    — those need entry-time captures (entry_q, entry_var in portfolio
    state) deferred to Phase 1.5.

New struct fields on GpuBacktestEvaluator:
  - per_trade_pnl_buf:          CudaSlice<f32> [n_windows × MAX_TRADES]
  - per_trade_holding_bars_buf: CudaSlice<u32>
  - per_trade_bar_index_buf:    CudaSlice<u32>
  - per_trade_dir_mag_buf:      CudaSlice<u32> (packed dir/mag)
  - per_trade_count_buf:        CudaSlice<u32> [n_windows]

New methods:
  - reset_per_trade_tape (folded into reset_evaluation_state): zeros
    the count buffer at the start of each eval window. SoA value
    buffers don't need zeroing — read up to count[w] only.
  - pub fn read_per_trade_tape(&self) -> Result<Vec<EvalTrade>, MLError>:
    reads count buffer first (cheap), early-returns empty if no trades,
    else reads 4 SoA buffers (~16MB DtoH at PCIe ≈ 1ms) and flattens
    window-major into chronological Vec<EvalTrade>.

Phase 2 follow-up (next commit) — wire read_per_trade_tape to the
enrichment caller in training_loop.rs:1510-1568, replacing
extract_eval_trades_from_metrics (the fake-trade synthesizer).

Phase 1.5 follow-up (if Phase 2 keeps E1+E5) — add entry_q + entry_var
to portfolio_state at trade open, extend per-trade tape with 6th/7th
SoA buffers.

Affected files:
  - crates/ml/src/cuda_pipeline/gpu_backtest_evaluator.rs
    (constants, struct fields, alloc, construction, 2 launcher sites,
    reset_evaluation_state addition, read_per_trade_tape method)

Verification:
  - cargo check -p ml --tests: passes (warnings only)
  - GPU oracle tests: behavior preserved by construction (existing
    WindowMetrics aggregator unaffected — separate kernel)

Plan reference: docs/plans/2026-05-10-sp21-train-eval-coherence-isv-defrost.md
T2.2 multi-phase scope; Phase 1 Step B closure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 21:26:40 +02:00
..

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 aggregation
  • hyperopt — PSO-based hyperparameter optimization with per-model adapters
  • trainers — unified training loops (DQN, PPO, supervised)
  • inferenceInferenceAdapter trait for prediction
  • checkpoint — model checkpointing and restoration
  • evaluation — walk-forward evaluation pipeline

Usage

use ml::dqn::DQN;
use ml::ppo::PpoTrainer;