Commit Graph

4015 Commits

Author SHA1 Message Date
jgrusewski
6767241b17 perf: parallel target/online forward on separate CUDA streams
Pass 2 (target forward) and Pass 3 (Double DQN online forward)
run concurrently on main stream + forked double_dqn_stream.
Fork/join via CUDA events captured in graph topology.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 22:48:59 +02:00
jgrusewski
56035c7c95 perf: multi-stream branch dispatch — 3 advantage heads in parallel
Fork 3 CUDA streams at CublasForward construction. In forward_online_raw
and forward_online_f32, the trunk records an event, each branch stream
waits on it, submits its GEMM+bias ops on its own stream (via
cublasSetStream), then the main stream joins all three. This overlaps
the 3 independent advantage head computations (exposure, order, urgency)
that previously executed sequentially.

Safety: a distinct_branches guard checks h_b0!=h_b1!=h_b2 at runtime;
callers that alias branch hidden buffers (Pass 3 Double DQN scratch
reuse) fall back to the sequential loop. CUDA Graph capture (CUDA 12+)
captures the fork/join pattern as graph dependencies.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 22:28:07 +02:00
jgrusewski
7aeaae3520 perf: event-based experience→training phase transition
Replace stream.synchronize() between experience collection and training
with a CUDA event recorded on the forked stream. The event is checked
lazily at the start of run_training_steps, allowing CPU-side setup
(can_train, ensure_fused_ctx, guard init, variable capture) to overlap
with the tail of GPU experience collection kernels.

Also converts the curiosity kernel sync to the event pattern with
non-blocking is_complete() poll before synchronize().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 22:15:30 +02:00
jgrusewski
5363185721 perf: dynamic batch sizing — AutoBatchSizer drives batch_size on H100
Set batch_size=0 in config/gpu/h100.toml as sentinel for auto-compute.
The constructor now treats batch_size==0 as "let AutoBatchSizer drive":
it uses the VRAM-computed ceiling capped at 8192, instead of the static
1024 that was wasting >90% of H100's 80GB VRAM bandwidth.

Previously AutoBatchSizer computed the optimal batch (e.g. 2085808) but
the profile's batch_size=1024 always won. Now with batch_size=0 the
sizer's result flows through, enabling full SM occupancy on H100.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 22:08:01 +02:00
jgrusewski
7e04dd0c0f perf: async q-stats readback via CUDA events
Replace synchronous memcpy_dtoh in reduce_current_q_stats() with
cuMemcpyDtoHAsync_v2 + CudaEvent pattern. The function now returns the
PREVIOUS call's results (one-step delay) while the current reduction
runs asynchronously, eliminating a GPU stall every 50 training steps.

Adds flush_q_stats_readback() to drain the final in-flight readback at
epoch end, matching the existing flush_readback() pattern for loss/grad_norm.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 22:07:50 +02:00
jgrusewski
6972f91262 perf: CUDA events replace per-step stream.synchronize in training loop
Replace the blocking stream.synchronize() in replay_adam_and_readback()
with async DtoH copies + CUDA event recording. Each step now returns
the previous step's scalars while the current step's readback lands
asynchronously. A flush_readback() call at epoch end collects the
final in-flight transfer. This eliminates 341 per-epoch CPU stalls
where the H100 sat idle waiting for Rust to re-enter the loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 22:01:27 +02:00
jgrusewski
171fb0832c docs: H100 GPU optimization implementation plan — 10 tasks
Phase 1: CUDA events, dynamic batch size, async q-stats, phase overlap
Phase 2: Multi-stream branches, target/online parallelism
Phase 3: CUDA Graph experience collection, lock removal
Validation: H100 benchmark with epoch time + SM utilization targets

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 21:41:21 +02:00
jgrusewski
0b185ddb54 docs: H100 GPU optimization spec — 9 optimizations for 2min→<10s epochs
CUDA events, multi-stream branches, graph-captured experience
collection, dynamic batch sizing, async readbacks, fxcache alignment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 21:36:40 +02:00
jgrusewski
28ad7cece1 fix: align precompute data-dir with train_baseline_rl symbol subdir
precompute passes data-dir/SYMBOL to match how train_baseline_rl
calls load_all_bars(data_dir, symbol). compile-and-train gets
FOXHUNT_FEATURE_CACHE_DIR env var and --epochs fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 21:09:06 +02:00
jgrusewski
f01c7f8181 fix: baseline-rl template adds required volumes + volumeClaimTemplates
Mirrors train-dqn's volume setup: git-ssh-key, training-data (rw),
cargo-target-cuda, workspace (dynamic PVC). training-data NOT
readOnly — needs write for checkpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 21:05:38 +02:00
jgrusewski
55444f7f42 refactor: baseline-rl wraps compile-and-train, fix fxcache + epochs
compile-and-train:
- Added feature-cache-dir parameter + FOXHUNT_FEATURE_CACHE_DIR env
- Fixed --max-steps-per-epoch → --epochs on train-best step

train-baseline-rl:
- Thin wrapper: templateRef to compile-and-train with hyperopt-trials=0
- No duplicate infrastructure — reuses compile, gpu-warmup, fetch-binary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 21:01:19 +02:00
jgrusewski
8507827ad0 fix: workspace uses volumeClaimTemplate (shared PVC across DAG tasks)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:57:38 +02:00
jgrusewski
614a7f24d0 fix: volume name cargo-target-cuda matches compile-and-train template
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:48:57 +02:00
jgrusewski
a075d3d963 feat: standalone train-baseline-rl workflow with compile + fxcache
Reuses compile-training, gpu-warmup, fetch-binary templates from
compile-and-train. Own train step runs train_baseline_rl directly
with --epochs, FOXHUNT_FEATURE_CACHE_DIR, and fxcache validation.
No hyperopt — pure baseline with default params.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:45:28 +02:00
jgrusewski
6928ebe1b2 fix: cargo-target-pvc → cargo-target-cpu (correct PVC name)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:39:35 +02:00
jgrusewski
f9609baff6 fix: train-baseline-rl compiles in-cluster, requires fxcache
- DAG: compile (ci-compile-cpu) + gpu-warmup → train (H100)
- Compiles from source targeting compute cap 90
- fxcache REQUIRED — fails if no .fxcache found
- Error chains printed with {:#} for full cause visibility
- Uses cargo-target-pvc for compile cache + sccache

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:37:23 +02:00
jgrusewski
0cf184a9f2 fix: train-baseline-rl uses ci-builder image with CUDA libs
Fixed ubuntu:24.04 → ci-builder for GPU runtime. Added LD_LIBRARY_PATH
stub removal. H100 detects GPU but DQNTrainer creation fails — needs
investigation (likely PER buffer allocation at 10M × 3 regime heads).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:34:32 +02:00
jgrusewski
dea78ef60c feat: train-baseline-rl Argo template — direct walk-forward training
Dedicated workflow for baseline RL training without hyperopt.
Runs train_baseline_rl binary on GPU node with fxcache.
Fetches pre-compiled binary from MinIO, falls back to PVC.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 20:27:46 +02:00
jgrusewski
a4ba8bddaa feat: fxcache stores per-bar timestamps for walk-forward windowing
Each record now starts with an i64 timestamp (nanoseconds since epoch)
before the feature/target/OFI data. v1 records grow from 432 to 440
bytes, v2 from 112 to 120 bytes. The timestamp is always i64 even in
bf16 mode. train_baseline_rl reconstructs bars with real timestamps
instead of placeholders so the walk-forward windower can split by month.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 19:29:41 +02:00
jgrusewski
0cd3d58a2b feat: train_baseline_rl loads from fxcache, skipping DBN extraction
Auto-discovers fxcache via env var or sibling directory. Falls back
to DBN loading if no cache found. Reconstructs aligned bars from
cached targets for walk-forward windowing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 19:23:41 +02:00
jgrusewski
1d0ed5afd1 feat: shared argo-base-egress policy for DNS, K8s API, MinIO, Mattermost
All pods with app.kubernetes.io/part-of=foxhunt get base infra
access. Fixes MinIO log archival timeout for precompute-features
and databento-download workflows. Component-specific policies
still add extra rules (GitLab SSH, external HTTPS, etc.).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 10:10:18 +02:00
jgrusewski
891be68c18 fix: increase precompute memory limit to 56Gi for 61M MBP-10 snapshots
Previous 32Gi OOM'd with 148GB of MBP-10 data (61M snapshots ≈ 15GB
in memory + trades + OHLCV). ci-compile-cpu node has 64GB.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 09:44:56 +02:00
jgrusewski
bb8e75c50c fix: cache key uses filenames only — CWD-independent
Cache key hashes filename + size + mtime instead of full paths.
Resolves mbp10/trades relative paths by walking up from data_dir.
Ensures precompute binary and cargo test produce the same key
regardless of working directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 09:02:16 +02:00
jgrusewski
6893d75800 fix: unify cache key — precompute and loader use same function
Precompute binary now uses calculate_dbn_cache_key_full from the
library instead of its own compute_cache_key. Canonicalize all
paths in the key function so relative/absolute produce the same
key. Walk up parent dirs for sibling feature-cache discovery.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 02:13:49 +02:00
jgrusewski
c17847b9a8 chore: remove old Parquet cache and binary cache — fxcache is the only path
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 01:37:59 +02:00
jgrusewski
51f686e723 feat: mbp10_data_dir and trades_data_dir are unconditional (no Option)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 01:24:30 +02:00
jgrusewski
6281b7d115 fix: fxcache auto-discovery cleans stale files on key mismatch
Exact key match only — no fallback to loading unvalidated caches.
On miss, stale .fxcache files are deleted to prevent disk bloat
and confusion from outdated cached data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 01:15:52 +02:00
jgrusewski
30c1801582 chore: rename test_data/mbp10 to mbp10-fixtures, remove uncompressed .dbn
Removed 2.6GB of uncompressed .dbn files (derivable from .zst).
Renamed directory to mbp10-fixtures to distinguish unit test
fixtures from training data. Updated all test references to use
.dbn.zst paths directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 01:13:19 +02:00
jgrusewski
a34a4634ed feat: fxcache auto-discovery via env var and sibling directory
load_training_data() checks for .fxcache in:
1. Explicit feature_cache_dir (set via with_feature_cache())
2. $FOXHUNT_FEATURE_CACHE_DIR env var
3. Sibling feature-cache/ directory next to data dir

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 01:07:40 +02:00
jgrusewski
08d6b1a32d refactor: precompute_features runs pure CPU — no DQNTrainer needed
Extract standalone functions from DQNTrainer:
- extract_features_from_bars(): 42-dim feature extraction
- extract_ohlcv_bars_from_dbn(): DBN to OHLCVBar conversion
- collect_dbn_files_recursive(): file discovery

DQNTrainer delegates to these, ensuring consistency.
Precompute binary no longer initializes CUDA — runs on any
CPU node (ci-compile-cpu at EUR 0.85/hr vs GPU at EUR 12.60/hr).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 00:52:36 +02:00
jgrusewski
b14e9cbd6b fix: precompute_features uses full GPU path, not CPU
DQNTrainer constructor requires CUDA for regime-conditional heads.
Use DQNTrainer::new() (GPU) instead of new_with_device(Cpu).
Set buffer_size=100_000 to satisfy PER minimum threshold.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 00:17:37 +02:00
jgrusewski
bdcb765e32 feat: train-dqn template passes feature-cache-dir to trainer
Adds feature-cache-dir parameter (default: /data/feature-cache) so
the training binary can load pre-computed .fxcache files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 00:00:38 +02:00
jgrusewski
5ea7c51580 feat: DQN data loader checks .fxcache before DBN streaming
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:59:49 +02:00
jgrusewski
cba407b79d feat: Argo precompute-features template + argo-precompute.sh CLI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:59:34 +02:00
jgrusewski
0c8620fd81 feat: precompute_features binary — DBN to .fxcache pipeline
CLI binary that reads OHLCV + MBP-10 + trades DBN data via DQNTrainer,
runs the full feature extraction pipeline, and writes a .fxcache file
for zero-overhead GPU loading during training. Uses CPU device to avoid
CUDA dependency for data-only workloads.

Also promotes load_training_data() and ofi_features to pub visibility
so the example binary can access them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:56:30 +02:00
jgrusewski
1e2b55d1c1 test: fxcache roundtrip tests — f64, bf16, find, validation, empty
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:48:17 +02:00
jgrusewski
f6b3b13afa feat: fxcache module — flat binary feature cache format (f64 + bf16)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:45:22 +02:00
jgrusewski
3c2874d082 docs: feature precompute pipeline implementation plan
10 tasks: fxcache format, writer, reader, tests, precompute binary,
DQN loader integration, Argo template, CLI script, train-dqn update,
local validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:35:47 +02:00
jgrusewski
a643652d0e docs: feature pre-compute pipeline design spec
Flat binary .fxcache format (f64 + bf16 versions), precompute_features
binary, Argo workflow integration, local validation plan.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:30:42 +02:00
jgrusewski
aa1accf5b7 chore: remove old Python-based Databento batch download job
All downloads now use the Rust download_baseline binary via the
Argo WorkflowTemplate (databento-download).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:03:03 +02:00
jgrusewski
3ca1f92339 fix: lower download template resources to fit platform nodes
500m/512Mi request fits alongside existing platform workloads.
Download is I/O-bound, not CPU-bound.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:00:00 +02:00
jgrusewski
3d63f73c08 fix: add retry with backoff to Databento download_quarter
3 retries with exponential backoff (2s, 4s, 8s) for transient
connection failures (IncompleteBody/UnexpectedEof). Partial files
are deleted before retry so skip-existing logic works correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 22:57:43 +02:00
jgrusewski
cb8afe3caf feat: parameterized Argo WorkflowTemplate for Databento downloads
Replace hardcoded K8s Job with reusable Argo WorkflowTemplate
(databento-download) parameterized by schema, output-dir, parallel,
and node-pool. Add argo-download.sh CLI wrapper matching the
argo-train.sh pattern. Remove old streaming job file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 22:40:37 +02:00
jgrusewski
fda01452c9 fix: Databento download — run as root for apt, fix output-dir path
Remove runAsUser:1000 so apt-get install ca-certificates works.
Fix double-nested ES.FUT path (output-dir is the schema root, not ES.FUT subdir).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 21:58:19 +02:00
jgrusewski
67af21449e fix: Databento streaming download — CA certs + all 4 schemas
Root cause: ubuntu:24.04 has no CA certificates, rustls-native-certs
fails TLS handshake. Fix: apt-get install ca-certificates before
running download binary. Also add port 80 to network policy for apt.

Downloads OHLCV-1m, Trades, OHLCV-1s, MBP-10 via streaming API
(get_range) — parallel quarterly downloads, individual .dbn.zst files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 21:48:28 +02:00
jgrusewski
3b77359e74 fix: use ci-compile-cpu node for Databento download (faster bandwidth) 2026-03-31 17:35:43 +02:00
jgrusewski
97d2ba87a2 fix: Databento download job — HOME=/tmp for pip, network policy label
Set HOME=/tmp to fix pip cache ownership, --no-cache-dir for clean install.
Label compile-and-train matches network policy for HTTPS egress.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 17:22:41 +02:00
jgrusewski
514285a59b feat: Databento batch download K8s job — all 5 schemas to training PVC
Downloads completed batch jobs (mbp-10, trades, ohlcv-1m, ohlcv-1s, mbp-1)
to training-data-pvc. Cleans old data per schema before downloading.
Uses existing databento-credentials secret.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 13:06:38 +02:00
jgrusewski
828417b523 fix: test reads threshold from dqn-smoketest.toml — no hardcoded values
Integration test now loads imbalance_bar_threshold and ewma_alpha from
config/training/dqn-smoketest.toml. Single source of truth for all
config values. Production threshold lowered to 0.5 for maximum bar yield.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 12:37:25 +02:00
jgrusewski
afdc6bacc3 feat: imbalance bar disk cache — /tmp/.foxhunt_imbalance_cache/
First load: full MBP-10 decompression (~450s for 19G).
Subsequent loads: bincode deserialize (<1s).

Cache key: hash(dir + symbol + threshold + alpha).
Auto-invalidates when any source .dbn file is newer than cache.
Cache failures are non-fatal — falls through to recomputation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 11:59:39 +02:00