jgrusewski 69c64f2266 test(ml-alpha): per-horizon pipeline end-to-end smoke + α-gate (C23)
Composes the C21 + C22 kernels with a host-side learnable α-gate to
prove the full per-horizon contribution path works end-to-end without
yet doing the captured-graph integration in PerceptionTrainer.

Pipeline:
  LNb [B, K, HIDDEN_DIM]
   → per_horizon_attention_pool_fwd  → context_h [B, N_HORIZONS, HIDDEN_DIM]
   → per_horizon_residual_head_fwd   → residual  [B, N_HORIZONS]
   → final[b, h] = baseline[b, h] + tanh(α[h]) * residual[b, h]

Two tests cover the critical invariants for adoption-safety:

  alpha_zero_init_is_identity_to_baseline
    With α = [0, 0, 0, 0, 0] and any random Q_h / w_res / bias_res,
    final_logit MUST be bit-identical to baseline_logit (because
    tanh(0) = 0). Verified via to_bits() byte equality. Proves that
    initialising the new variant with α=0 makes it a strict superset
    of the existing path — switching to AttentionPoolVariant::PerHorizon
    cannot regress before any training has happened.

  alpha_nonzero_changes_output_and_grads_flow_end_to_end
    With α = [0.5, -0.3, 0.2, -0.1, 0.4]:
      * final ≠ baseline (residual contributing) ✓
      * all final logits finite ✓
      * full backward chain (residual_head_bwd → attention_pool_bwd)
        produces finite d_Q_h_scratch + finite d_LNb with at least
        one non-zero entry in each → gradients flow back to both the
        attention queries and the LN_b input ✓

This closes the kernel-side correctness story. The remaining
integration commits (C24+) are operational:

  C24: extend CheckpointV1 → V2 (add q_h, w_res, bias_res, alpha
       fields; V1 files load as Variant::SharedQuery)
  C25: PerceptionTrainer wiring — allocate the device buffers, fold
       attention + residual + gate into the captured graph, plumb
       gradients into AdamW's param list
  C26: 1-epoch smoke (assert no NaN, loss decreases vs baseline) —
       needs real training data + multi-GPU time
  C27: 30-epoch × 3-fold A/B (task #204) — decision gate per
       docs/superpowers/specs/2026-05-18-per-horizon-attention-pool-design.md
       §0 falsifiable claim

C24-C25 are 1-2 day work even when carefully scoped; C26-C27 need
real GPU-hours + result analysis. C21-C23 land the validatable kernel
correctness piece without committing to that time investment yet.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 10:38:24 +02:00

Foxhunt

Production HFT trading system in Rust.

Architecture

The workspace contains 32 crates organized as follows:

Core Libraries (16)

Crate Purpose
trading_engine Order processing, FIX 4.4, IB TWS, SIMD, RDTSC timing
risk VaR, Kelly, circuit breakers, kill switches, compliance
risk-data Risk data types and shared structures
trading-data Trading data types
ml DQN Rainbow, PPO, TFT, Mamba2, ensemble inference
ml-data ML data types and feature definitions
data Market data ingestion and storage
backtesting Replay engine, strategy tester
adaptive-strategy Ensemble execution, microstructure analysis
common Shared types, resilience, error handling
storage S3 and local model storage
model_loader Model serialization and loading
market-data Market data feed handlers
database PostgreSQL access layer (SQLx)
config Configuration management
tli CLI commands and tooling

Services (8)

Service Purpose
backtesting_service gRPC backtesting service
broker_gateway_service FIX routing, broker connectivity
trading_service Core trading operations
ml_training_service Model training orchestration
data_acquisition_service Market data acquisition
trading_agent_service Autonomous trading agents
api_gateway gRPC API gateway with auth
web-gateway Axum REST + WebSocket gateway

Frontend

web-dashboard/ -- React 19 + TypeScript + Vite + TradingView charts.

Building

# Check compilation (no PostgreSQL required)
SQLX_OFFLINE=true cargo check --workspace

# Run tests for a specific crate
SQLX_OFFLINE=true cargo test -p <crate> --lib

# Clippy
SQLX_OFFLINE=true cargo clippy --workspace

ML Models

Four production model architectures on Candle v0.9.1 with CUDA:

  • DQN Rainbow -- Deep Q-Network with prioritized replay, dueling heads, noisy nets
  • PPO -- Proximal Policy Optimization with GAE and LSTM policies
  • TFT -- Temporal Fusion Transformer for multi-horizon forecasting
  • Mamba2 -- State space model for sequence prediction

Each model has a standalone trainer and a UnifiedTrainable adapter for the hyperopt pipeline.

Infrastructure

  • Git: Gitea at git.fxhnt.ai (Tailscale-only), Scaleway DEV1-S
  • Observability: OpenTelemetry OTLP (env OTEL_EXPORTER_OTLP_ENDPOINT)
  • Database: PostgreSQL with SQLx offline mode for CI

License

Proprietary. All rights reserved.

Description
No description provided
Readme 849 MiB
Languages
Rust 88.2%
Cuda 7.7%
Python 1.3%
Shell 1.1%
PLpgSQL 0.8%
Other 0.8%