jgrusewski a6acc25ec8 fix(cuda): branch-gate done in compute_advantage_return (resolves step-4 NaN)
Replaces multiplication-gating `advantages[b] = done * (ret - vt)` with
branch-gating `is_done ? (ret - vt) : 0.0f`. The multiplication form
fails on IEEE-754 `0 * Inf = NaN`: when any batch's encoder produces a
non-finite `v_tp1` early in training (random-init outliers across 128
parallel backtests), the prior expression propagated that non-finiteness
to ALL non-done batches' advantages via `0 * (Inf - vt) = NaN`, which
then broke `compute_advantage_rms` (sum of A² → NaN), PPO surrogate
(A/RMS → NaN → ratio×A → NaN → l_pi=NaN), and the aux head through
shared encoder gradient. Validated step-4 NaN bisect 2026-05-29.

The branch-gate is the canonical fix per IEEE-754 done-gating discipline:
- `is_done ? r : (r + γ × vtp1)` — non-finite vtp1 never enters a done
  batch's ret, and non-done batches' ret can still be non-finite (which
  is fine because the V regression envelope clamp salvages it back to
  bounds via fmaxf/fminf NaN-passthrough semantics)
- `is_done ? (ret - vt) : 0.0f` — non-done batches get 0 unconditionally,
  regardless of ret's finiteness

Smoke at HEAD (b4aadff75 = atomicAdd-fixed + V envelope ±10) with the
prior multiplication-gate: deterministic NaN at step 4 (l_pi/l_aux NaN,
l_v finite at 6.329).

Smoke at HEAD + this fix: clean trajectory through 110 steps:
- step 100: l_q=1.80, l_pi=0.49, l_v=0.37, dones=10, pnl=-$8.9k, wr=0.36
- step 109: l_q=1.81, l_pi=0.75, l_v=0.33, dones=13, pnl=-$9.9k, wr=0.37

l_v dropped from 6.33 to 0.33 because the envelope's ±10 bound is now
actually constraining V regression targets (previously the masking
behavior of ±200 envelope made high l_v "look healthy" while hiding the
underlying NaN propagation).

This finally unblocks the Phase 2.1 smoke gate and the Phase 2.2/2.3
implementations downstream.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 01:37:49 +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%