jgrusewski f3e3ac3477 fix(dqn-v2): bottleneck Linear runtime indices + missing target/DDQN bn paths (2c.3a follow-up)
Three related bugs from the 2c.3a GRN trunk reshuffle that the
bottleneck-Linear runtime sites silently inherited:

1. **on_w_ptrs[24/25] -> [33/34]** (4 sites in gpu_dqn_trainer.rs).
   2c.3a's +9 shift migrated branch/value/VSN/GLU/KAN consumers but
   missed the bottleneck Linear's forward GEMM (line ~14098), forward
   bias-add (~14107), and backward dW/db offsets (~15109-15110).
   Post-2c.3a, indices 24/25 point at b_b1out (153 floats) and start
   of w_b2fc (4288 floats) — not w_bn (672 floats) / b_bn (16 floats).
   Forward + backward were self-consistent on wrong tensors; the actual
   w_bn/b_bn at documented indices 33/34 sat untouched as zeros for
   ~10 commits. Smoke kept passing because GRN's Linear_residual
   projection ran in parallel and provided a clean residual-only
   pathway around the corrupted bottleneck slot.

2. **Target net missing bottleneck path.** forward_target_raw passed
   raw next_states_buf (128-padded) to an encoder expecting
   [B, s1_input_dim=102]; it was reading
   [market|ofi|tlob|mtf] of next_states instead of
   [bn_market_proj|portfolio]. Fix: build tg_bn_concat_buf inline
   before forward_target_raw using tg_w_ptrs[33]/[34] (target's w_bn)
   on next_states_buf[market]; new buffer pair tg_bn_hidden_buf +
   tg_bn_concat_buf.

3. **DDQN argmax missing bottleneck path.** submit_forward_ops_ddqn
   had the same shape mismatch on the online-on-next_states pass.
   Fix: build on_next_bn_concat_buf using on_w_ptrs[33]/[34] (online
   weights, since DDQN argmax uses online net); new buffer pair
   on_next_bn_hidden_buf + on_next_bn_concat_buf.

Three call sites of the existing bn_tanh_concat_kernel now: online-on-
states (states + on_w_bn), target-on-next_states (next + tg_w_bn), and
ddqn-online-on-next_states (next + on_w_bn). Each combination of
weights × input states produces distinct features; sharing the kernel
across distinct buffer pairs preserves the GPU-only cold-path contract.

No fingerprint change (no ISV slot or param tensor added).

Smoke validation (multi_fold_convergence, 700.43s, 3 folds x 5 epochs):
  fold 0 best Sharpe  6.53 at epoch 2
  fold 1 best Sharpe 80.11 at epoch 4
  fold 2 best Sharpe 66.72 at epoch 4
  geom-mean: 39.27 (vs Task 3 20.03, 2c.3c.6 18.80)

The Sharpe lift is consistent with the bottleneck Linear now seeing
its actual weights and the target/DDQN nets seeing input-shape-
consistent features for TD-target / argmax-action computations.

+166 / -9 LOC all in gpu_dqn_trainer.rs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 18:24:06 +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%