jgrusewski 829ddfa62c feat(ml-alpha): add batched cfc + heads CUDA kernels (foundation for #8)
Adds 4 new kernel symbols alongside the existing single-sample ones —
zero changes to current call sites, so the in-flight qf5mj baseline is
unaffected. The next commit wires these into PerceptionTrainer's K
loop and exposes --batch-size in the CLI.

  cfc_step_batched              processes [n_batch, n_in/n_hid] tensors
  cfc_step_backward_batched     same; shared mem holds sd_pre[B, n_hid]
                                + sdecay[n_hid] (~16 KiB at B=32, well
                                under L40S 48 KiB block limit). Param
                                grads (grad_b/grad_w_in/grad_w_rec/
                                grad_tau) accumulated via += — thread i
                                is sole writer to its row across all
                                samples, so no atomicAdd and no per-
                                batch scratch buffer.

  multi_horizon_heads_batched    [n_batch, 5] sigmoid outputs from
                                 [n_batch, 128] hidden inputs.
  multi_horizon_heads_backward_batched
                                 shared mem holds sd_z[B, 5]. grad_w
                                 / grad_b += across batch (thread tid
                                 sole writer). grad_h carries the
                                 optional per-sample grad_h_carry
                                 (cfc recurrence chain).

Design notes:
  - Threading: one block of n_hid threads. Each thread loops over
    b ∈ 0..B internally. This avoids cross-block races on grad_*
    buffers and keeps the existing "no atomicAdd" discipline. Cost:
    less raw parallelism than grid-batching, but the bottleneck is
    Mamba2 (already batch-parallel via its own kernel grid).
  - Per-thread accumulators: grad_b / grad_tau land in registers,
    flushed once at end. grad_w_in / grad_w_rec written += per-b
    (thread sole writer to its row, safe).
  - All B samples processed in stream order inside one kernel launch
    — saves K * (B-1) launches per sequence vs serialising B
    independent calls.

77 ml-alpha tests pass (kernels not yet exercised — wiring is the
next commit).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-17 10:20:27 +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%