a263cd54469768be6bea7556b4eac1bd8f0e083e
The cluster smoke at 9170d24fe showed ~88 s/epoch projected for the
full 8000-step epoch (vs the 17 s baseline) — a 5× regression that
fails the spec §5 wall-time gate. Diagnosis: the inverted-attention
kernel's hot loops recomputed `mean_k_X_inv[j] = (1/K) Σ_k X_inv[j, k]`
per-thread, per-j, every pass:
- fwd pool: 128 × 32 reads per thread = 4096 extra ops × 128 threads
= ~0.5 M wasted ops per fwd
- bwd phase 1: 128 × 32 × 2 passes per thread = ~1.0 M wasted ops
per bwd
At 1000 steps/epoch this alone adds ~1.5 s of pointless compute, and
the cumulative effect across fwd + bwd + DRAM round-trips for the
score tensor was the main contributor to the 5× regression.
REWRITE:
1. `mean_k_X_inv[H]` (0.5 KB) cached ONCE in shared memory at kernel
entry. Each thread h does its OWN k-trajectory load + sum in
parallel during the x_inv staging, so no extra cost vs the prior
x_inv-only stage.
2. Forward now does:
- Pass 1: compute max(score) only — no DRAM writes.
- Pass 2: compute exp(score - max) → write to attn_out (scratch),
accumulate sum locally.
- Pass 3: single sweep over j — divide attn_out by sum (in place),
accumulate pool += attn · mean_k[j]. ← uses cached mean_k.
Eliminates the post-softmax recompute of mean_k that the prior
version did 128× per thread.
3. Backward `d_scores` computation now uses cached mean_k (saves 4096
ops/thread). Also: `dot = pooled[my_h]` is now computed once at
the start of phase 1 from attn × mean_k (one pass over j) instead
of being implicit in the per-j d_attn computation.
CORRECTNESS:
- inverted_attention_pool numgrad PASSES 6 random-position checks
within 5e-2 rel / 5e-3 abs.
- perception_overfit 9/9 tests PASS — including
stacked_trainer_loss_shrinks_on_constant_signal (loss 0.67 → -0.99
over 250 steps).
SMEM FOOTPRINT:
- fwd: x_inv[H · K] + mean_k[H] = 16 KB + 0.5 KB
- bwd: x_inv[H · K] + mean_k[H] + dp[H] = 16 KB + 1 KB
Both well under the 48 KB sm_86 dynamic-shared default; no
cuFuncSetAttribute opt-in needed.
Next: re-run cluster smoke to measure the new wall-time. Expected to
land ≤ 30 s/epoch per spec §5 wall-time gate.
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%