jgrusewski 2e80f453d1 Merge: real DQN checkpoint loader + IG diagnostic CLI + latent ensemble-test bug fix
Branch worktree-agent-ace613af, 3 commits (f47af9d2 / 82dca76d / 5f95cad4).

1. DQN::load_from_safetensors is no longer a no-op. Adds
   BranchingDuelingQNetwork::load_from_named_slices (D2D memcpy,
   validates names + shapes, errors on drift). Adds
   NoisyLinear::{weight_mu_mut, bias_mu_mut} for in-place mu restore.
   Rewrites DQN::load_from_safetensors to actually restore weights;
   handles both plain and `trending__`-prefixed checkpoint layouts.
   Resyncs target network. Un-ignores the ensemble adapter's
   test_dqn_checkpoint_round_trip (now deterministic with NoisyNet
   disabled).

2. New post-hoc IG diagnostic CLI at crates/ml-explainability/src/bin/
   ig_diag.rs. Gated by Cargo feature `ig-diag-cli` to avoid cyclic
   dep (ml already depends on ml-explainability). CLI args:
   --checkpoint --states auto|PATH --feature-names --num-steps
   --output --auto-samples --seed. Forward target: mean(Q[direction,
   0..4]) → V(s) via dueling identity; NoisyNet disabled → deterministic.
   Fxcache reader inlined (~80 LOC) to avoid ml-crate dep.
   Integration test measured 1.6% IG completeness error at
   num_steps=64.

3. Latent bug caught while wiring checkpoint loading: ensemble DQN
   adapter tests used vec![0.1; 56] but STATE_DIM=96, so cuBLAS
   gemm_ex was reading 40 bytes of uninitialised memory past the
   CudaSlice. That was the source of flaky argmax in
   test_dqn_adapter_deterministic. Replaced hardcoded 56 with
   ml_core::state_layout::STATE_DIM in 3 test sites.

Tests (ml-dqn --lib): 270→274 pass / 16→15 fail (+4 pass, -1 fail).
All new tests pass. Remaining 15 failures are pre-existing flaky
tests (NoisyNet non-determinism, small state_dim GPU alloc edges)
not introduced by this work.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 10:55:34 +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%