jgrusewski 7349713ca8 feat(bf16): f32 forward logit buffers — eliminates root cause of training NaN
Output layer GemmEx now writes f32 (CUDA_R_32F C-matrix) instead of bf16.
When the f32 accumulated dot product exceeded bf16 max (~65504), the bf16
C-matrix write produced Inf/NaN → propagated through softmax → NaN loss.
With f32 output, no truncation overflow is possible.

Forward pass changes:
- 6 logit buffers: CudaSlice<half::bf16> → CudaSlice<f32>
  (on/tg/on_next × v_logits/b_logits)
- gemmex_bf16_to_f32(): BF16 A/B, F32 C — same tensor core throughput
- launch_add_bias_f32_raw(): uses add_bias_f32_kernel (f32 in, f32 out)
- Loss kernels: 12 logit params changed to const float* (no bf16→float cast)
- expected_q_kernel: full f32 rewrite (was bf16 arithmetic)
- cql_grad_kernel: logit inputs as float*, internal computation f32
- ensemble_kernels: logit inputs as float*, softmax/KL in f32
- gpu_experience_collector: exp_v_logits/exp_b_logits → CudaSlice<f32>
- gpu_backtest_evaluator: chunked logit buffers → CudaSlice<f32>
- ensemble_logits_buf in fused_training: CudaSlice<f32>

Per-sample NaN guard kept as safety net for bf16 reward/done/IS-weight
edge cases (not the primary fix — f32 logits are the root cause fix).

Hidden layers stay bf16 — ReLU bounds them. Gradient buffers stay bf16/f32
(already converted). No tensor core throughput loss (same CUBLAS_COMPUTE_32F).

50-epoch convergence: all 50 epochs complete, loss=4.12, Q=1.33, grad=0.49.
895/895 unit tests, 9/9 smoke tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 23:20:05 +01: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%