Commit Graph

12 Commits

Author SHA1 Message Date
jgrusewski
a86168cdea cleanup: delete legacy bf16 replay buffer code and stale hyperopt results
Remove dead bf16 kernel handles (scatter_insert_bf16, gather_bf16_rows,
gather_bf16, f32_to_bf16_cast), bf16_slice_to_gpu_tensor_gpu converter,
a16 allocator, and dtod_clone_u16 — all obsoleted by the f32 migration.
Fix unused variables (w_ptrs, concat_dim) and unnecessary mut bindings.
Delete 25 stale hyperopt campaign results from local experiments.

All 1254 tests pass (895 ml + 359 ml-dqn), zero compiler warnings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:02:55 +02:00
jgrusewski
68804a1a51 fix(cuda): remove --use_fast_math, eliminate cross-stream NaN race, f32 rewards/dones
Three root causes of sporadic NaN during training:

1. --use_fast_math (nvcc) breaks IEEE 754 NaN semantics: fmaxf(NaN,x)
   returns NaN instead of x, isnan()/isinf() compile to false.
   Replaced with --ftz=true --fmad=true --prec-div=true --prec-sqrt=true
   across all 4 build.rs (ml, ml-dqn, ml-ppo, ml-core).

2. Cross-stream race: replay buffer wrote batch data on the device's
   original stream while the trainer read it on a forked stream.
   Fixed by passing the forked stream to the DQN agent via agent_device,
   so all GPU components share a single CUDA stream (zero sync overhead).

3. Rewards/dones stored as bf16 in replay buffer caused done=0xFFFF NaN.
   Converted entire rewards/dones pipeline to f32: experience collector,
   replay buffer storage, nstep kernel, loss/grad kernels.

Also:
- Removed fast_isnan/fast_isinf/fast_isfinite wrappers — standard
  isnan/isinf/isfinite work correctly without --use_fast_math
- Updated dqn-smoketest.toml: lr=1e-4, epsilon=1e-8 (f32 Adam values)
- Removed debug printfs from gather kernels
- Added curiosity_weight to training profile system
- Cleaned up smoke_params() inline overrides

11/11 smoke tests pass, 5/5 stress runs of 50-epoch test pass,
359/359 ml-dqn + 895/895 ml unit tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 16:18:37 +02:00
jgrusewski
ac06c502d9 feat(bf16): 33/37 CUDA kernels compile — build.rs shows ALL failures
- attention_kernel.cu: fixed float* out pointer, mixed arithmetic
- curiosity_training_kernel.cu: 3 Adam kernels native BF16, fused kernel fixed
- ensemble_kernels.cu: softmax/KL native BF16, warp_sums BF16
- build.rs: compile ALL kernels before failing (shows complete failure list)

Remaining: attention_backward (38 casts), iql_value (43),
ppo_experience (37), experience_kernels (49) — agents T8/T10 running

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:34:41 +01:00
jgrusewski
840780f709 feat(bf16): fix ensemble + curiosity kernels, stale comments removed
- ensemble_kernels.cu: softmax/KL → native BF16 arithmetic
- curiosity_training_kernel.cu: 3 Adam kernels → native BF16, next_state ref fixed
- build.rs: removed stale standalone kernel comment

Remaining: attention_kernel.cu fails (T6 agent mixed types), T8/T10 agents running.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:20:56 +01:00
jgrusewski
a797e61d96 WIP(bf16): atomic BF16 conversion — 36/37 CUDA kernels, all Rust types
CUDA kernels: 36 of 37 compiled with __nv_bfloat16* (dt_kernels.cu remaining)
Rust types: ALL CudaSlice<f32> → CudaSlice<half::bf16> across ml + ml-core
Build: all kernels now compiled with common_device_functions.cuh (BF16 helpers)
BF16 math wrappers: bf16_sqrt, bf16_log, bf16_exp, bf16_pow, bf16_fabs, bf16_fmax,
  bf16_fmin, bf16_cos, bf16_zero, bf16_one, bf16(), atomicAddBF16

NOT YET COMPILING — ml-core boundary errors (Vec<f32> → Vec<half::bf16>)
and dt_kernels.cu float*__nv_bfloat16 ambiguity remain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 23:00:45 +01:00
jgrusewski
70ba9341fa feat(bf16): BF16 cuBLAS forward infrastructure — gemmex_bf16 + BF16 bias kernels
- cublasGemmEx BF16×BF16→BF16 method (CUBLAS_COMPUTE_32F, tensor core path)
- BF16 bias+relu and bias-only CUDA kernels (add_bias_relu_bf16_kernel)
- 15 BF16 activation buffers allocated in CublasForward (online + target)
- f32_to_bf16_kernel loaded for states conversion
- bf16_weight_ptrs() helper for BF16 flat buffer offset computation
- forward_online_bf16() method — complete BF16 forward pass (not yet wired)
- cudarc f16 feature enabled, nvrtc removed

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 21:53:00 +01:00
jgrusewski
d485dde5a2 fix: eliminate NVRTC, fix evaluator SIGSEGV, 22D search space, trade physics
Major changes:
- Eliminate ALL runtime NVRTC: c51_loss + mse_loss kernels converted to
  precompiled cubins with runtime num_atoms/v_min/v_max/branch params
- Fix evaluator SIGSEGV: rng_states/q_gaps sized for chunked batch (cn)
  not n_windows; NULL pointer guard in action_select kernel
- Add trade_physics.cuh shared header for train/eval consistency
- Add equity circuit breaker (25% DD from peak) + margin-aware position cap
- Consolidate 46D→22D hyperopt search space, enable ensemble by default
- Fix trade counting: use exposure index not factored action
- Fix Calmar overflow: clamp to ±100 in kernel
- Softer CVaR penalty (cap 3.0 not 10.0) for undertrained models
- Fix win_rate display (ratio→percentage)
- Remove dead code (normalize_reward, calculate_completion_penalty)
- Add tracing subscriber to hyperopt test for visible metrics
- Per-chunk sync in evaluator for reliable error reporting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 00:33:05 +01:00
jgrusewski
9f63193351 fix: NUM_ATOMS 51→201 in c51/mse kernels — array overflow when num_atoms=101
Same class of bug as IQN_HIDDEN: compile-time array float local_proj[51]
overflows when hyperopt picks num_atoms=101. Crashed at ~35 min when
PSO explored larger atom counts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 08:19:19 +01:00
jgrusewski
bf2a7ba56d feat: build.rs precompiles all 25 CUDA kernels at cargo build time
Extend build.rs to compile all 25 .cu kernel files to cubins via nvcc.
Common header prepended to 24 kernels; experience_kernels.cu is standalone.
Total cubin size ~1.1 MB embedded in binary.

- cargo:rerun-if-changed tracks all .cu and .cuh files
- CUDA_COMPUTE_CAP env var selects target arch (sm_86, sm_90)
- Graceful skip when nvcc unavailable (non-CUDA builds)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 00:25:56 +01:00
jgrusewski
a2bf5210ec feat: build.rs precompiles epsilon_greedy_kernel.cu — proof of concept for NVRTC elimination
Add build.rs that compiles .cu kernels to cubins at cargo build time via nvcc.
Replace OnceLock<Ptx> + compile_ptx_for_device() in gpu_action_selector.rs with
include_bytes! + Ptx::from_binary() loading from the precompiled cubin.

- build.rs gracefully skips when nvcc is not available (non-CUDA builds)
- CUDA_COMPUTE_CAP env var controls target GPU arch (86=RTX 3050, 90=H100)
- common_device_functions.cuh prepended to kernel sources at build time
- Zero runtime compiler invocations for epsilon_greedy kernel

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 00:07:16 +01:00
jgrusewski
c5961cb766 refactor(cuda): remove all #[cfg(not(feature = "cuda"))] dead CPU paths
Delete every CPU fallback block across 14 files (-286 lines):
- dqn.rs: CPU replay buffer, tensor construction, PER fallback, gradient paths
- hyperopt/adapters/ppo.rs: CPU curiosity modules, trajectory generation
- hyperopt/adapters/dqn.rs: CPU backtest fallback, sync no-op
- trainers/ppo.rs: CPU training error stub
- l2_cache.rs: CPU stub functions (gate callers behind cuda too)
- replay_buffer_type.rs: CPU is_gpu_prioritized fallback
- validation/harness.rs: CPU regime breakdown fallback
- build.rs: cpu_only_build cfg (never referenced)
- evaluate_baseline.rs: CPU gpu_handled fallback
- testing/integration/gpu: CPU test stubs

Zero #[cfg(not(feature = "cuda"))] remains in the codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 16:26:41 +01:00
jgrusewski
9c3d741a08 refactor: restructure repo — crates/, bin/, testing/ layout
Move 17 library crates into crates/, CLI binary into bin/fxt,
consolidate 10 test crates into testing/, split config crate
from deployment config files.

Root directory reduced from 38+ to ~17 directories.
All Cargo.toml paths and build.rs proto refs updated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 11:56:00 +01:00