From 3389a59281a72ded376c64cf55ca8a772ae1d682 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Sat, 16 May 2026 21:42:57 +0200 Subject: [PATCH] spec(ml-alpha): stacked Mamba2 -> CfC amendment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mid-execution architecture revision: Mamba2 stays as a sequence encoder; CfC becomes the layer on top (replacing the Phase 1d.3 MLP stacker). Gate becomes 'stacked AUC >= Mamba2-only stacker AUC at every horizon' — proves the CfC layer is additive, rather than CfC alone beating Mamba2 alone. Plan 1 kernels (cfc_step, heads, projection, BCE, AdamW, Graph A) are unchanged. Only CfcTrunk's forward path gains a Mamba2 prefix that consumes the snapshot stream and emits a 128-dim h_mamba which CfC reads. The Mamba2 kernel (mamba2_alpha_kernel.cubin) is already in the build. Option B (parallel + fused dual-stream) is documented as the Plan 2 fallback if the stacked gate fails. Co-Authored-By: Claude Opus 4.7 --- .../specs/2026-05-16-ml-alpha-cfc-ppo-design.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/superpowers/specs/2026-05-16-ml-alpha-cfc-ppo-design.md b/docs/superpowers/specs/2026-05-16-ml-alpha-cfc-ppo-design.md index 0d72546de..85940c581 100644 --- a/docs/superpowers/specs/2026-05-16-ml-alpha-cfc-ppo-design.md +++ b/docs/superpowers/specs/2026-05-16-ml-alpha-cfc-ppo-design.md @@ -1,9 +1,24 @@ # ml-alpha — Greenfield CfC + PPO Trading System Design **Date**: 2026-05-16 -**Status**: Approved (all 7 sections + ISV-driven auto-tuning addition) +**Status**: Approved with **2026-05-16 stacked-architecture amendment** (see Section 2.5 below) **Supersedes**: `2026-05-16-alpha-ppo-trainer.md` (the earlier DQN-port plan, abandoned per user direction to rebuild from first principles) +## 2026-05-16 Amendment: Mamba2 → CfC stacked perception (Option A) + +The original spec framed CfC as a *replacement* for Mamba2 at the perception trunk, with a hard gate requiring CfC AUC ≥ Mamba2 AUC at every horizon. Mid-execution of Plan 1, the architecture was revised to a **stacked design** where Mamba2 stays in the system as a frozen-or-jointly-trained sequence encoder feeding into CfC. The CfC layer learns per-cell time-constants over the SSM output. + +**Why the change**: Phase 1d.3 already validated `Mamba2 → MLP stacker`. Replacing the MLP stacker with CfC strictly extends the validated path rather than swapping a known-good encoder for an unvalidated one. The gate now proves "the CfC layer is additive" rather than "CfC alone beats Mamba2 alone." + +**Affected sections**: +- Section 2 — `Perception trunk` reads: Mamba2 SSM (input → 128-dim h_mamba) → CfC cell (128-dim h_mamba → 128-dim h_cfc) → multi-horizon heads + projection +- Section 4 — Gate: `stacked AUC ≥ Mamba2-only AUC at every horizon` (with the Mamba2-only AUC measured from a comparable stacker-MLP architecture for fairness) +- Section 7 — Param count: ~50K trainable (15K Mamba2 + 35K CfC stack) + +**Fallback path (Option B — parallel + fused)**: if the stacked gate fails, fallback is dual-stream (Mamba2 + CfC read snapshots in parallel; outputs concat → projection → heads). Documented as a Plan-2 amendment if A's gate fails; not implemented in Plan 1. + +The CfC kernels (`cfc_step.cu`), heads, projection, BCE, AdamW, and Graph A are unchanged. Only the trunk's forward path adds a Mamba2 prefix. + ## TL;DR A clean greenfield rebuild of `ml-alpha` as a full closed-loop alpha trading system for ES.FUT on IBKR with $35k starting capital. Three components: (1) a Rust model library that owns a CfC perception trunk + 5 multi-horizon alpha heads + a CfC actor-critic policy, (2) an offline training binary, (3) an `AlphaPpoStrategy` integration in the existing `trading_agent_service` for live runtime. Everything GPU-resident on the hot path. Online learning with EWC anchoring + replay buffer (80% offline / 20% live) + kill-switch on σ-band metric deviations. Hyperparameters that vary during training are ISV-driven (signal-driven controllers, no magic numbers). Reuse the existing IBKR adapter, data ingestion, execution engine, and risk manager.