d9cb14f1bc697142c1d6b04f2b12e53c37eb8167
Validation backtest was serialised on the training stream by passing self.cuda_stream as parent_stream into GpuBacktestEvaluator::new (the forked eval-stream still depends on training-stream completion, but the metrics + plan_diag readbacks went through clone_dtoh / memcpy_dtoh, each forcing an implicit sync that blocked behind the training stream's pending work). The prior comment claimed single-stream eval was needed "for cuBLAS determinism" — incorrect: cuBLAS bit-wise reproducibility caveats apply per-handle, not across the process, and each stream already owns its own PerStreamCublasHandles. Costs ~30-40s/epoch on L40S. Plan A: - Route eval through self.validation_stream (already forked at constructor.rs:547 but unused on the eval path) and add a fresh cuda_stream-recorded train_done_event so validation_stream + evaluator's internal forked stream both wait on it before launching eval kernels. GPU-side cuStreamWaitEvent — no CPU sync. - Replace metrics_buf and plan_diag_buf in GpuBacktestEvaluator from CudaSlice<f32> to MappedF32Buffer (cuMemHostAlloc DEVICEMAP). Kernels write through the buffer's dev_ptr; host reads via volatile host_ptr after a single eval_stream.synchronize() per evaluation. Replaces the forbidden clone_dtoh / memcpy_dtoh path per feedback_no_htod_htoh_only_mapped_pinned.md. The single sync blocks only the eval stream — training rolls on uninterrupted. - Update the misleading "single-stream cuBLAS determinism" comment to explain the actual per-stream-handle architecture. Per feedback_no_partial_refactor: every consumer of the metrics_buf / plan_diag_buf contract migrated in lockstep (struct fields, alloc, kernel-arg passing, host readout). Per-stream cuBLAS handle parity with training preserved (val TLOB still uses PerStreamCublasHandles::new(&eval_stream); evaluator forks its own internal cuBLAS state from parent_stream). Verified: cargo check -p ml --lib clean (13 warnings, workspace baseline). cargo test -p ml --lib --no-run clean. No fingerprint change — mapped-pinned is allocation-method orthogonal to kernel buffer layout. Companion commit lands Plan B (async best-checkpoint serialize). Wire-up audit entry covers Plan A here; will be extended with Plan B edit sites in the companion commit. Co-Authored-By: Claude Opus 4.7 (1M context) <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%