jgrusewski 7356e3c7bb fix(rl): close 3 of 4 deferred items from Phase E.2 (greenfield)
Closes 3 of 4 deferred items from commit 2665669b5; item 1 (encoder
backward) is deferred to a follow-up commit (see Notes below).

Item 2 — Bellman target projection kernel:
  New `bellman_target_projection.cu` replaces the host-side stand-in
  `build_synthetic_bellman_target`. Reads γ from
  ISV[RL_GAMMA_INDEX=400] per pearl_controller_anchors_isv_driven.
  Standard C51 categorical projection with linear interpolation onto
  the discrete support [V_MIN, V_MAX]; no atomicAdd (per-source-atom
  serial shared writes bracketed by __syncthreads, Q_N_ATOMS=21
  inner-loop syncs).

  Also adds `dqn_select_action_atoms` in the same TU — selects per-batch
  action-row atoms from the full target-net output. Both kernels exposed
  via DqnHead::project_bellman_target / DqnHead::select_action_atoms +
  DqnHead::forward_target (new — target-network forward using
  w_target_d / b_target_d).

  IntegratedTrainer::step_synthetic now consumes the kernel path:
  forward_target → select_action_atoms → project_bellman_target →
  backward_logits. The `build_synthetic_bellman_target` host function is
  DELETED.

Item 3 — Per-head LR ISV controller:
  New `rl_lr_controller.cu` emits per-head learning rates to ISV slots
  [412..417]: RL_LR_BCE_INDEX, RL_LR_Q_INDEX, RL_LR_PI_INDEX,
  RL_LR_V_INDEX, RL_LR_AUX_INDEX (RL_SLOTS_END bumped 412 → 417).
  Bootstrap 1e-3 per pearl_first_observation_bootstrap; Wiener-α blend
  with floor 0.4 per pearl_wiener_alpha_floor_for_nonstationary.

  IntegratedTrainer launches the controller at the top of step_synthetic
  AFTER the encoder forward; it then DtoH-mirrors ISV and mutates each
  per-head AdamW.lr field before the Adam steps. The PHASE_E2_DEFAULT_LR
  constant is DELETED. The `lr` parameter on step_synthetic is gone
  (greenfield — no caller override).

  The controller currently emits the constant LR_BOOTSTRAP target; the
  signal-modulated variant (gradient-norm EMA-driven LR adaptation) is
  reserved for Phase E.3+ — kernel header documents the upgrade path
  and the 5 diagnostic-signal args are already plumbed.

Item 4 — PPO V-loss canonicalization:
  Deletes `returns_/v_pred/loss_v` from ppo_clipped_surrogate_fwd
  (kernel + ppo.rs::surrogate_forward signature). V gradient now flows
  ONLY through the dedicated `v_head_fwd_bwd` kernels per
  feedback_single_source_of_truth_no_duplicates. PPO surrogate now
  handles policy loss + entropy bonus only. The IntegratedTrainer's
  surrogate_forward call site no longer passes returns/v_pred/loss_v.

ISV slot table (rl/isv_slots.rs):
  408..411  loss-balance λ (BCE/Q/π/V)   ← existing
  412       RL_LR_BCE_INDEX              ← new
  413       RL_LR_Q_INDEX                ← new
  414       RL_LR_PI_INDEX               ← new
  415       RL_LR_V_INDEX                ← new
  416       RL_LR_AUX_INDEX              ← new
  417       RL_SLOTS_END                 ← was 412

Notes — item 1 (PerceptionTrainer::backward_encoder_with_grad_h_t)
deferred:
  The IntegratedTrainer.step_synthetic path now COMBINES the Q/π/V
  grad_h_t contributions into a dedicated `grad_h_t_combined_d` slot
  via the existing `grad_h_accumulate_scaled` kernel (loss-balance λ
  weighted), which is the prerequisite plumbing for the encoder
  backward entry point. The PerceptionTrainer-side method that consumes
  this slot — CfC bwd + Mamba2 bwd + encoder Adam step on caller-
  provided grad_h_t — is a multi-thousand-line refactor of
  perception.rs::dispatch_train_step (~7,400 lines) and is being
  sequenced as a standalone follow-up commit to keep the kernel
  signature changes here (items 2/3/4) reviewable in isolation.

All three landed items are greenfield replacements per project policy
(feedback_no_legacy_aliases, feedback_no_partial_refactor): no
deprecated fields, no const-or-ISV fallback shims, no parameter
backward-compat. ISV is the single source of truth for all adaptive
parameters per pearl_controller_anchors_isv_driven.

Validation:
  cargo check -p ml-alpha --lib                                ✓
  cargo check -p ml-alpha --tests --examples                   ✓
  cargo check --workspace --lib                                ✓
  cargo test  -p ml-alpha --lib (63 passed, 6 ignored)         ✓
  cargo build -p ml-alpha --features cuda (new cubins built)   ✓

Companion to E.2 (commit 2665669b5). Encoder backward + Phase E.3
LobSim integration follow in subsequent commits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 23:49:38 +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%