4e629830b68b3583a3fedba25f0784202e717e83
Adds labels 47 (train_vsn_out), 48 (step_entry_w_in_W), 49 (step_entry_w_in_b). 10-run smoke at seed=16962, n=10, b=128: in ALL failing runs the FIRST NaN is train_vsn_out at first_bad_idx=40 — the FIRST broadcast context feature in the [B, K, ENCODER_INPUT_DIM=56] window tensor. ROOT CAUSE: VSN kernel stride mismatch. `window_tensor_d` is allocated `[B, K, ENCODER_INPUT_DIM=56]` and `encoder_context_broadcast` writes to offset `idx * 56 + 40`. But the VSN forward kernel `variable_selection_fwd` at variable_selection.cu:41 reads with `x_row = x + row * VSN_FEATURE_DIM=40` — stride 40 against a stride-56 buffer. For row 0 the stride happens to align. For row 1+ VSN reads mixed data across the [B, K, 56] row boundaries — broadcast context features bleed into VSN's "snap features" view, and snap features bleed across K boundaries. The bug has existed since context broadcast was wired but only produces NaN when the broadcast values get large enough to cause softmax overflow — typically after a few steps of trade-context accumulation (unrealized_R growing with position drift). The "step-4" character is a side effect: clean weights + accumulated trade-context magnitude → first row that overflows softmax → NaN propagates through gradients → all encoder weights corrupted by step 5 (confirmed: step_entry_w_in_W label 48 fires at step=5). Confirmed by the chain of established scans: - Labels 38-42 (top of step): all weights clean - Label 47 (train_vsn_out post-VSN): NaN at idx=40 (first broadcast feature) - Labels 43/44/45 (Mamba2 L1 projections pre-scan): NaN cascading - Labels 36/37 (saved fwd state at L1 save): NaN cascading - Labels 19, 31, 32, 34 (LN_a bwd inputs): NaN cascading - Label 13 (vsn_W in action-selection fwd graph): fires at step=5 from AdamW having applied NaN gradient (consequence, not cause) Fix scope: change VSN_FEATURE_DIM stride to ENCODER_INPUT_DIM in variable_selection_fwd and variable_selection_bwd, OR pass row_stride as a kernel argument. Single-PR scope, no architecture change. 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%