acdafe508e82e3a07a0519f790e386c01cdaacaa
Implements §6 of the Phase 4 spec — wires DuelingQHead into
IntegratedTrainer in DIAGNOSTIC-ONLY mode (V_dq trains via Bellman
loss every step, but does NOT yet feed PPO advantage — that's
Phase 4.3, a 10-LOC follow-up commit).
IntegratedTrainer additions:
- dueling_q_head: DuelingQHead field
- 4 AdamW states (w_v, b_v, w_a, b_a) — LR from RL_LR_Q_INDEX
- 19 per-step buffer fields:
Forward outputs:
dueling_v_d [B], dueling_v_tp1_d [B], dueling_a_d [B×N],
dueling_q_composed_d [B×N]
Target net forward scratch:
dueling_q_target_composed_d [B×N], dueling_v_target_tp1_d [B],
dueling_a_target_tp1_d [B×N]
Loss path scratch:
dueling_v_loss_d [B], dueling_a_loss_d [B×N],
dueling_target_value_d [B], dueling_loss_pb_d [B],
dueling_grad_composed_d [B×N]
Per-batch weight grads:
dueling_grad_w_v_pb_d [B×HIDDEN_DIM], dueling_grad_b_v_pb_d [B],
dueling_grad_w_a_pb_d [B×HIDDEN_DIM×N], dueling_grad_b_a_pb_d [B×N]
Reduced weight grads:
dueling_grad_w_v_d [HIDDEN_DIM], dueling_grad_b_v_d [1],
dueling_grad_w_a_d [HIDDEN_DIM×N], dueling_grad_b_a_d [N]
10-step launch sequence in step_with_lobsim_gpu_body (after existing
IQN forward block):
1. dueling_q_head.forward(h_t_borrow) → V_dq, A, composed_Q
2. dueling_q_head.forward(h_tp1_d) → V_dq_tp1
3. dueling_q_head.forward(sampled_h_t_d) → online composed_Q for loss
4. dueling_q_head.forward_target(sampled_h_tp1_d) → target composed_Q
5. build_bellman_target(target_composed, r, dones, γ^n) → target_value
6. compute_loss_and_grad(online, target, actions) → loss + grad_composed
7. decompose_and_backward_to_weights(sampled_h_t, grad, actions)
→ per-batch w/b grads
8. reduce_axis0_free × 4 → final weight grads
9. LR ← ISV[RL_LR_Q_INDEX] (DuelingQHead is a Q learner)
10. Adam step × 4 (w_v, b_v, w_a, b_a)
What's NOT yet done (Phase 4.3):
- compute_advantage_return STILL uses v_pred_d / v_pred_tp1_d
(Plan A v2 path UNTOUCHED — qpa should stay healthy in cluster smoke)
- Soft-update of target net weights (recommend reusing
dqn_target_soft_update_fn kernel in Phase 4.3)
- Diag JSONL fields for dueling_v_at_taken_ema, dueling_loss
Validated:
- cargo build --release clean
- integrated_trainer_smoke (1 step end-to-end) passes
- alpha_rl_train --steps 3 --n-backtests 128 under compute-sanitizer
memcheck: 0 errors, l_q rising 0 → 0.024, l_v = 0.0001
CRITICAL: This commit should be cluster-validated BEFORE Phase 4.3.
At b=1024 5k steps, expected:
- qpa stays healthy (composed_Q_dq doesn't feed ensemble)
- pnl matches Plan A v2 trajectory exactly (V_dq doesn't drive PPO)
- V_dq trains stably (visible in compute-sanitizer's grad flow)
If cluster shows any regression, the bug is in this commit's wiring,
NOT in Plan A v2 (which is structurally preserved).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
Languages
Rust
88.2%
Cuda
7.7%
Python
1.3%
Shell
1.1%
PLpgSQL
0.8%
Other
0.8%