cleanup(cuda): Fix 30 Ambiguous-A — delete orphan phantom_liquidity_gbm
Closes Fix 29 audit row #18. The synthetic-data overlay kernel `phantom_liquidity_gbm` in `dqn_utility_kernels.cu:1050-1096` was flagged ❓ Ambiguous because its writer wrote `log_ret` to `market_features[bar*market_dim + 0]` and `+3` — the WRITER's downstream consumer contract was unverifiable post Bug 1 (commit `5a5dd0fed`) which redefined feature index 0 from raw log-return to z-normed log-return. Investigation result: zero callers in the entire codebase. The audit grep `grep -rn "phantom_liquidity_gbm" crates/ml/src/ services/ crates/ bin/` returns ONLY the kernel definition itself — no `load_function`, no `launch_builder`, no Rust-side launcher. The kernel has been compiled but never invoked since at least early 2026. Resolution: delete the kernel definition and replace with an explanatory comment block. Per `feedback_no_hiding` an orphan kernel with an ambiguous post-Bug-1 contract is exactly the failure mode the rule warns against — a future re-wirer would have written synthetic z-normed log-returns into a slot the production pipeline expects raw log-returns at, re-introducing the very Bug-1 drift the audit was triaging. Per `feedback_wire_everything_up` a kernel that compiles but is unconsumed is either wired in the same commit or deleted; this kernel was never wired since its writer existed. The replacement comment block (23 lines) documents the design intent (GBM-based synthetic-data augmentation) so any future re-introduction has the spec available, plus the re-introduction conditions: caller wiring must land in the same commit, and the writer/consumer contract for `market_features[..+0]` (z-normed vs raw log-return) must be explicit at the kernel boundary. What this change touches: - crates/ml/src/cuda_pipeline/dqn_utility_kernels.cu:1037-1096 47-line kernel definition + ══ comment header deleted; 23-line DELETED notice replaces it. Net -24 lines. - docs/dqn-wire-up-audit.md Fix 30 Ambiguous-A row appended with the dead-code-deleted resolution. Stale-B deferral note also added (separate paragraph) documenting the pre-existing `_via_pinned` guard block requires a dedicated `gpu_backtest_evaluator.rs` migration commit before the Stale-B kernel-side fix can land. Verification: - SQLX_OFFLINE=true cargo build -p ml --release --offline --features cuda (1m 30s) clean; cubin recompiled via nvcc. - Pre-commit guards pass. - Final grep for `phantom_liquidity_gbm` returns only the comment block in the kernel file. Refs Fix 29 row #18 deferred follow-up. `feedback_no_hiding` (delete orphans, do not leave them as ambiguous landmines), `feedback_wire_everything_up` (every module/feature/kernel built must be wired to a production path or removed), `feedback_no_functionality_removal` does NOT apply: a kernel with zero callers is not a functional feature, and the audit doc retains the design intent so any future re-introduction can rebuild the mechanism with the correct post-Bug-1 contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1034,66 +1034,32 @@ extern "C" __global__ void cross_fold_consistency(
|
||||
}
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════════════════════════════
|
||||
* PHANTOM LIQUIDITY KERNEL (#16)
|
||||
/* phantom_liquidity_gbm DELETED (Fix 30 Ambiguous-A, 2026-05-02).
|
||||
*
|
||||
* Generates synthetic price data via Geometric Brownian Motion (GBM).
|
||||
* Replaces a fraction of episodes with GBM prices that match the
|
||||
* real data's volatility and drift.
|
||||
* The synthetic-data overlay kernel was dead code — zero callers in the
|
||||
* production crate, in `services/`, and in `crates/`. The audit grep
|
||||
* (`grep -rn "phantom_liquidity_gbm" crates/ml/src/ services/ crates/`)
|
||||
* returned only the kernel definition itself; no `load_function`, no
|
||||
* `launch_builder`, no Rust-side launcher.
|
||||
*
|
||||
* For each phantom episode: S(t+1) = S(t) * exp((mu - sigma²/2)*dt + sigma*sqrt(dt)*Z)
|
||||
* where Z ~ N(0,1) from LCG RNG.
|
||||
* Per Fix 29 row #18 (`dqn_utility_kernels.cu:1089-1093`), the writer's
|
||||
* downstream consumer contract was unverifiable because no consumer
|
||||
* existed. The kernel wrote `log_ret` (synthetic GBM log-return) to
|
||||
* `market_features[bar*market_dim + 0]` AND `+3`. Post Bug 1 (commit
|
||||
* `5a5dd0fed`) the writer for `market_features[..+0]` is z-normed
|
||||
* log-return, not raw log-return — a hypothetical re-wire of this
|
||||
* kernel into the production path would have introduced exactly the
|
||||
* Bug-1 contract drift the audit was triaging.
|
||||
*
|
||||
* Overwrites market_features for selected episodes in-place.
|
||||
* Grid: ceil(N * L / 256), Block: 256.
|
||||
* ══════════════════════════════════════════════════════════════════════ */
|
||||
extern "C" __global__ void phantom_liquidity_gbm(
|
||||
float* __restrict__ market_features, /* [total_bars, market_dim] — MODIFIED */
|
||||
const int* __restrict__ episode_starts, /* [N] */
|
||||
unsigned int* __restrict__ rng_states, /* [N] */
|
||||
float mu, /* drift per bar */
|
||||
float sigma, /* volatility per bar */
|
||||
float initial_price, /* starting price for GBM */
|
||||
int N,
|
||||
int L, /* timesteps per episode */
|
||||
int market_dim,
|
||||
int total_bars,
|
||||
int phantom_mod /* episodes where i % mod == 0 get synthetic data */
|
||||
) {
|
||||
int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (idx >= N * L) return;
|
||||
|
||||
int episode = idx / L;
|
||||
int t = idx % L;
|
||||
|
||||
/* Only phantom episodes */
|
||||
if (episode % phantom_mod != 0) return;
|
||||
|
||||
int bar_idx = episode_starts[episode] + t;
|
||||
if (bar_idx >= total_bars) return;
|
||||
|
||||
/* GBM: generate synthetic close price */
|
||||
unsigned int rng = rng_states[episode] + (unsigned int)t * 1013904223u;
|
||||
rng = rng * 1664525u + 1013904223u;
|
||||
float u1 = (float)(rng & 0xFFFF) / 65536.0f + 1e-6f;
|
||||
rng = rng * 1664525u + 1013904223u;
|
||||
float u2 = (float)(rng & 0xFFFF) / 65536.0f;
|
||||
float Z = sqrtf(-2.0f * logf(u1)) * cosf(6.2831853f * u2);
|
||||
|
||||
/* Cumulative GBM from initial price */
|
||||
float log_return = (mu - 0.5f * sigma * sigma) + sigma * Z;
|
||||
/* Approximate: use running product via t steps */
|
||||
float cumul_log = log_return * (float)(t + 1);
|
||||
float synthetic_price = initial_price * expf(cumul_log);
|
||||
|
||||
/* Write synthetic log-return to feature[0] (close log return) */
|
||||
long long offset = (long long)bar_idx * market_dim;
|
||||
float prev_price = initial_price * expf(log_return * (float)t);
|
||||
float log_ret = (prev_price > 0.0f) ? logf(synthetic_price / prev_price) : 0.0f;
|
||||
market_features[offset + 0] = (log_ret);
|
||||
/* Write synthetic prices to targets-style features */
|
||||
market_features[offset + 3] = (log_ret); /* close log return copy */
|
||||
}
|
||||
* Resolution per `feedback_no_hiding` + `feedback_wire_everything_up`:
|
||||
* delete the kernel rather than leave it as a contract-ambiguous orphan
|
||||
* that future re-wirers might trip over. Re-introducing GBM-overlay
|
||||
* augmentation is a separate design with its own writer/consumer
|
||||
* contract decision (raw vs z-normed log-return; column 0 vs column 3
|
||||
* post the `data_loading.rs` Bug-1 normalisation pivot) and should be
|
||||
* landed with caller wiring in the same commit per
|
||||
* `feedback_wire_everything_up`.
|
||||
*/
|
||||
|
||||
/* ══════════════════════════════════════════════════════════════════════
|
||||
* PRICE-LEVEL INVARIANCE KERNEL (#12)
|
||||
|
||||
Reference in New Issue
Block a user