Commit Graph
393 Commits
Author SHA1 Message Date
Omar SobhandClaude Sonnet 4.6 80d7c7fb6c feat(flash-attention): add varlen packed-sequence support
Implements variable-length (varlen) FlashAttention that processes
mixed-length batches without padding waste:

- New CUDA kernel flash_attention_varlen_forward with BLOCK_Q=64 /
  BLOCK_K=64 tiling; grid=(ceil(max_seqlen_q/64), num_heads, 1).
  Each block uses a linear scan over cu_seqlens_q to identify its
  owning sequence and exits early when past sequence end.
- New Rust module flash_varlen_forward: always-compiled CPU simulation
  (varlen_attention_cpu) for testing + #[cfg(cuda)] FlashVarlenKernel.
- SdpaBackend::VarLen variant added to backend_selector.
- 8 new CPU-only tests; total test count: 50.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-27 01:09:39 +00:00
Omar SobhandClaude Sonnet 4.6 311eb23dbd feat(perf): GPU perf batch 3 — W4A16 AWQ matmul, FSDP2 hooks, RMSNorm+SwiGLU fused kernel
CI / Format Check (push) Failing after 5s
CI / Clippy Check (push) Failing after 7s
CI / Build CPU-Only (Explicit) (push) Failing after 7s
Documentation / Build User Guide (push) Successful in 5s
CI / Build (ubuntu-latest) (push) Failing after 7m36s
Documentation / Build API Documentation (push) Failing after 8s
Performance Benchmarks / Run Benchmarks (push) Successful in 1m51s
CI / Python Bindings (maturin) (macos-latest) (push) Has been skipped
CI / Python Bindings (maturin) (ubuntu-latest) (push) Has been skipped
CI / WASM Build + Size Check (push) Has been skipped
CI / Distributed Training Tests (push) Has been skipped
CI / Build (macos-latest) (push) Failing after 49s
CI / Test (macos-latest) (push) Has been skipped
CI / Test (ubuntu-latest) (push) Has been skipped
CI / CI Success (push) Failing after 1s
W4A16 AWQ on-the-fly dequantize+GEMM (rtx-compress)
- `w4a16_matmul.rs`: `AWQQuantizedWeightExt` trait + `matmul_cpu()` — group-aligned
  inner loop, f64 accumulation, low-nibble-first INT4 unpacking matching mx_kernels.cu
- `cuda_kernels/w4a16_gemm.cu`: `w4a16_dequant_gemm` kernel, one thread per (batch, out_col),
  8-INT4-per-iteration inner loop with `__ldg()` cache hints, BF16 scale decode, f32 accumulate
- `quantization/mod.rs`: exports `w4a16_matmul_cpu`, `AWQQuantizedWeightExt`
- Fixed 2 pre-existing pruning compile errors
- 12 tests: nibble unpack, identity weights, shape, vs-dequant (tol=1e-3), batch=1, zeros

FSDP2 forward/backward hooks (rtx-distributed)
- `fsdp2.rs`: `update_local_shard()` on `Fsdp2ShardedParam`; sync `all_gather()` +
  `reduce_scatter_gradient()` using `ProcessGroup::{all_gather,reduce_scatter}`
- `pre_forward_hook()` — all-gathers every param (or copies shard in single-process)
- `post_backward_hook()` — reduce-scatters gradients, zero_grad, re-shards cache
- `step(optimizer_fn)` — applies optimizer closure to each local shard
- `make_fsdp2_module()` top-level factory; `Fsdp2MemoryStats` gains 5 new fields
  incl. `memory_reduction_ratio ≈ world_size`
- 6 new tests (end-to-end training step included); total 444 pass

RMSNorm+SwiGLU fused CUDA kernel (rtx-fusion)
- `cuda/rms_norm_swiglu_fused.cu`: `rms_norm_kernel` + `rms_norm_swiglu_fused`;
  shared-mem warp reduction (block_x floats), launch: grid=(batch,1,1), block=(min(hidden,1024),1,1)
- `cuda_kernels/rms_norm_fused.rs`: CPU reference `rms_norm_cpu`/`swiglu_cpu`/
  `rms_norm_swiglu_cpu`; `#[cfg(feature="cuda")] RmsNormFusedKernel` NVRTC wrapper
- `codegen/cubecl.rs`: replaced RmsNorm comment stub with cfg-gated NVRTC dispatch
- `backend.rs` + `tensor.rs`: added 15 missing `Backend` trait impls (sin/cos/relu/conv2d/…)
  that blocked test compilation
- `Cargo.toml`: added rtx-fusion to workspace members
- 8 new tests (PyTorch-formula verified: x=[1,2,3,4] → [0.365, 0.730, 1.095, 1.461]);
  total 103 pass

Test results: 12 + 444 + 103 = 559 tests, 0 failures

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-27 00:18:20 +00:00
Omar SobhandClaude Sonnet 4.6 a670045f46 feat(perf): GPU perf batch 2 — EAGLE-3 dynamic draft trees + GaLore-2 optimizer
CI / Format Check (push) Failing after 8s
GPU Tests / Check GPU Availability (push) Successful in 0s
CI / Build (ubuntu-latest) (push) Failing after 8s
Performance Benchmarks / Run Benchmarks (push) Successful in 10s
Documentation / Build User Guide (push) Successful in 8s
Documentation / Build API Documentation (push) Failing after 10s
CI / Clippy Check (push) Failing after 18s
CI / Build CPU-Only (Explicit) (push) Failing after 1m22s
GPU Tests / CUDA Tests (11.8) (push) Has been skipped
GPU Tests / CUDA Tests (12.1) (push) Has been skipped
CI / Test (macos-latest) (push) Has been skipped
CI / Test (ubuntu-latest) (push) Has been skipped
CI / Python Bindings (maturin) (macos-latest) (push) Has been skipped
CI / Python Bindings (maturin) (ubuntu-latest) (push) Has been skipped
CI / WASM Build + Size Check (push) Has been skipped
CI / Distributed Training Tests (push) Has been skipped
CI / Build (macos-latest) (push) Failing after 1m1s
CI / CI Success (push) Failing after 1s
GPU Tests / Metal Tests (push) Has been skipped
EAGLE-3 dynamic draft trees (rtx-inference)
- `eagle3.rs`: `Eagle3Config` (min_depth=1, max_depth=6, expansion_threshold=0.4,
  beam_width=3, self_consistency=true, prune_threshold=0.05), `DynamicDraftTree` with
  confidence-gated BFS expansion + iterative bottom-up cascade pruning + `all_paths()` /
  `accept_path()`, `Eagle3Decoder::build_draft_tree()` with cheap hidden-state proxy
  for child nodes (parent states scaled by child probability)
- `tree.rs`: added `path_probability(leaf)`, `leaves()` (tombstone-safe DFS)
- `types.rs`: added `DraftModelType::Eagle3` variant
- 10 new unit tests via `FixedProbDraftModel` mock (no GPU required); total 85 pass

GaLore-2 low-rank optimizer state (rtx-transformers)
- `galore.rs`: `GaLoreConfig` (rank=128, update_proj_gap=200, scale=0.25,
  min_param_size=4096, momentum_inheritance=true), `GaLoreParamState` (proj_matrix
  [rows×rank], m_lr/v_lr [rank×cols]), `GaLoreAdamW` implementing `Optimizer` trait
- Randomized range-finder sketched SVD: Ω~N(0,1) via LCG, Y=G@Ω, Gram-Schmidt QR
- Momentum inheritance: project old m_lr onto new subspace on refresh
- Automatic fallback to standard AdamW for params smaller than `min_param_size`
- Memory ratio at rank=64, param=256×256: 2×(64×256) vs 2×(256²) = 25% of full state
- `mod.rs`: `pub mod galore` + re-exports
- 12 unit tests (all CPU); total 102+12 pass

Combined: 85 + 114 = 199 lib tests pass across rtx-inference and rtx-transformers

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 22:43:09 +00:00
Omar SobhandClaude Sonnet 4.6 a7d9969702 feat(galore2): implement GaLore-2 optimizer with 12 pure-CPU tests
Adds GaLoreAdamW to crates/training/rtx-transformers — a memory-efficient
AdamW variant that reduces optimizer state by projecting gradients to a
low-rank subspace and periodically refreshing it via randomised SVD.

Key facts verified by tests:
- Memory formula: for [rows×cols] param with rank r,
    GaLore stores: rows*r + 2*r*cols f32 elements
    AdamW stores:  2*rows*cols f32 elements
    For [256×256] r=64: ratio=0.375 (62.5% reduction)
    For [4096×4096] r=128: ratio<10% (>90% reduction)
- Subspace refresh triggers when (step - last_refresh) >= update_proj_gap
- Momentum inheritance: m_new = new_Q^T @ old_Q @ m_old preserves direction
- Small params (< min_param_size=4096 elements) fall back to standard AdamW

Files changed:
- crates/training/rtx-transformers/src/optimizers/galore.rs (new)
- crates/training/rtx-transformers/src/optimizers/mod.rs (mod + re-exports)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 22:41:42 +00:00
Omar SobhandClaude Sonnet 4.6 082a50e3a0 feat(perf): GPU perf batch 1 — wire GPU execution paths for FP8, FA3, CUDA Graphs, SnapKV
CI / Build (ubuntu-latest) (push) Failing after 8s
Performance Benchmarks / Run Benchmarks (push) Successful in 8s
CI / Clippy Check (push) Failing after 8s
CI / Build CPU-Only (Explicit) (push) Failing after 8s
Documentation / Build API Documentation (push) Failing after 7s
CI / Format Check (push) Failing after 9s
GPU Tests / Check GPU Availability (push) Successful in 0s
Documentation / Build User Guide (push) Successful in 7s
GPU Tests / CUDA Tests (11.8) (push) Has been skipped
GPU Tests / CUDA Tests (12.1) (push) Has been skipped
CI / Build (macos-latest) (push) Failing after 14s
CI / Test (macos-latest) (push) Has been skipped
CI / Test (ubuntu-latest) (push) Has been skipped
CI / Python Bindings (maturin) (macos-latest) (push) Has been skipped
CI / Python Bindings (maturin) (ubuntu-latest) (push) Has been skipped
CI / WASM Build + Size Check (push) Has been skipped
CI / Distributed Training Tests (push) Has been skipped
CI / CI Success (push) Failing after 0s
GPU Tests / Metal Tests (push) Has been skipped
FP8 GPU FFI (rtx-tensor)
- `fp8_cast.rs`: replaced `not_implemented` stubs with real cudarc 0.18.2 PTX launches;
  `cast_bf16_to_fp8_e4m3` and `cast_fp8_e4m3_to_bf16` now dispatch to NVCC-compiled
  `fp8_cast.ptx` via `LazyLock` module cache, matching the `inplace_ops` pattern
- `build.rs`: `create_dummy_ptx` now emits `fp8_cast.ptx` alongside `element_wise.ptx`
  so `include_str!` resolves cleanly when NVCC is absent

FlashAttention-3 typed kernel launch (rtx-flash-attention)
- `flash_v3_forward.rs`: `forward()` now takes typed `CudaSlice<bf16>` Q/K/V/O + `CudaSlice<f32>`
  LSE buffer; dispatches via `stream.launch_builder` with block_dim=(128,1,1),
  grid_dim=(ceil(seq_len/64), batch*heads, 1), shared_mem_bytes=0 (PTX metadata-resolved)
- `simple.rs`: added `has_flash_v3()` + `flash_attention_v3_forward_raw()` dispatch
- `Cargo.toml`: `half` added as optional cuda-gated dependency

CUDA Graphs stream threading (rtx-transformers)
- `training_loop.rs`: added `cuda_stream: Option<CudaStreamHandle>` field; `set_cuda_backend()`
  now creates a non-default capture stream; capture step calls real `begin_capture(stream)` +
  `end_capture(stream)`; added `set_cuda_stream()` override; replay unchanged (no stream needed)

SnapKV + prefix cache BatchScheduler wiring (rtx-inference)
- `scheduler.rs`: added `prefix_hit_pages: Option<Vec<PageId>>` + `evicted_positions: Vec<usize>`
  to `SchedulerRequest`; `BatchScheduler` gains `kv_cache` + `snapkv_eviction` fields;
  `submit_request` does non-blocking `try_lock` prefix lookup; added `notify_prefill_complete`
  (registers prefix + runs `select_evict_positions`), `set_kv_cache`, `set_snapkv_eviction`,
  `get_evicted_positions`, `get_prefix_hit_pages` — +5 new integration tests

Test results: 22 + 42 + 75 + 102 = 241 tests, 0 failures

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 20:39:58 +00:00
Omar SobhandClaude Sonnet 4.6 1eb89c5b2b feat(perf): GPU perf batch 1 — FP8, FA3 Blackwell, CUDA Graphs, SnapKV, prefix cache
CI / Build CPU-Only (Explicit) (push) Failing after 8s
CI / Clippy Check (push) Failing after 12s
GPU Tests / Check GPU Availability (push) Successful in 0s
CI / Format Check (push) Failing after 14s
Performance Benchmarks / Run Benchmarks (push) Failing after 15s
Documentation / Build User Guide (push) Successful in 6s
Documentation / Build API Documentation (push) Failing after 16s
GPU Tests / CUDA Tests (11.8) (push) Has been skipped
GPU Tests / CUDA Tests (12.1) (push) Has been skipped
CI / Build (ubuntu-latest) (push) Failing after 1m20s
CI / Build (macos-latest) (push) Failing after 1m26s
CI / Test (macos-latest) (push) Has been skipped
CI / Test (ubuntu-latest) (push) Has been skipped
CI / Python Bindings (maturin) (macos-latest) (push) Has been skipped
CI / Python Bindings (maturin) (ubuntu-latest) (push) Has been skipped
CI / WASM Build + Size Check (push) Has been skipped
CI / Distributed Training Tests (push) Has been skipped
CI / CI Success (push) Failing after 0s
GPU Tests / Metal Tests (push) Has been skipped
Item 1 — CUDA Graphs wiring (rtx-transformers)
- Added `enable_cuda_graphs: bool` (default false) + `cuda_graph_warmup_iters: usize`
  (default 3) to `TrainingConfig`
- Wired 3-phase state machine into `training_loop.rs` (warmup → capture → replay)
  gated on `#[cfg(feature = "cuda")]`; stream plumbing stubbed with TODO pending
  `CudaStreamHandle` threading

Item 2 — FP8 E4M3/E5M2 training infrastructure (rtx-tensor, rtx-transformers)
- `fp8_cast.cu`: dual-path CUDA kernels — SM_89+ uses `<cuda_fp8.h>` native
  `__nv_cvt_*` intrinsics; older SM uses software bit-manipulation fallback
- `fp8_cast.rs`: host-side CPU casting + `#[cfg(feature = "cuda")]` GPU stubs
- `fp8_gemm.rs`: bit-accurate E4M3 decoder/encoder, BF16 round-trip utils, CPU
  reference matmul with cuBLASLt GPU path documented inline; 12 unit tests
- `training_config.rs`: `fp8_training: bool`, `fp8_e4m3_forward: bool`
- `linear.rs` (modular): `fp8_mode: bool` field + forward dispatch stub
- build.rs: registers `fp8_cast.cu` alongside existing `element_wise.cu`
- 22 FP8 unit tests — all pass

Item 3 — FlashAttention-3 Blackwell (WGMMA + TMA + warp specialization)
- `flash_attention_v3_forward.cu`: SM_90+ warp-specialised producer/consumer
  kernel (producer TMA-loads K/V tiles, consumers run WMMA as portable WGMMA
  proxy); SM_89+ FP8 header path; SM<90 standard FA2-style WMMA fallback
- `flash_v3_forward.rs`: NVRTC wrapper (`compile_ptx` via `include_str!`),
  `FlashV3ForwardKernel::new/is_supported/forward`; 6 unit tests
- `backend_selector.rs`: `SdpaBackend::FlashAttentionV3`, `for_compute_capability`,
  `supports_flash_v3` (major >= 9), FA3 scoring (0.98/0.90/0.70), 2× speedup estimate
- `kernels/simple.rs`: `v3_kernel: Option<FlashV3ForwardKernel>` in `FlashCudaKernels`
- Fixed pre-existing `Device::Cpu` cfg-gate bug in `tensor/creation.rs`
- 8 new FA3 backend tests + 6 kernel unit tests; 50 total pass

Item 4 — SnapKV attention-score eviction + prefix caching (rtx-inference, rtx-serving-api)
- `prefix_index.rs`: `PrefixIndex` with 8MB Zobrist hash table (Knuth MMIX LCG seed),
  `compute_hash/lookup/insert/remove/remove_page`; 10 unit tests
- `eviction.rs`: `AttentionScoreEviction` struct — `accumulate_scores` +
  `select_evict_positions` (retain top keep_ratio + last recent_window); 7 unit tests
- `types.rs`: `EvictionPolicy::AttentionScore { keep_ratio, recent_window }` +
  `KvCacheConfig::enable_prefix_caching`
- `paged_kv_cache.rs`: `prefix_index: Option<PrefixIndex>` + `lookup_prefix /
  register_prefix / unregister_prefix_page / prefix_caching_enabled` methods
- `config.rs` (serving-api): `enable_prefix_sharing: true` (was false),
  `snapkv_keep_ratio: 0.6`, `snapkv_recent_window: 32`
- Fixed 12 pre-existing test errors (spurious `.await` on sync constructors)
- 17 SnapKV/prefix tests pass

Total: 918 lib tests pass across rtx-tensor, rtx-flash-attention, rtx-transformers,
rtx-inference. Zero new failures.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 19:56:39 +00:00
Omar SobhandClaude Sonnet 4.6 c82d26d6e7 style: rustfmt formatting pass on rtx-tensor and rtx-flash-attention
CI / Format Check (push) Failing after 13s
Performance Benchmarks / Run Benchmarks (push) Successful in 8m13s
CI / Clippy Check (push) Failing after 11s
CI / Build (ubuntu-latest) (push) Failing after 7m37s
GPU Tests / Check GPU Availability (push) Successful in 0s
Documentation / Build User Guide (push) Successful in 15s
Documentation / Build API Documentation (push) Failing after 17s
CI / Build CPU-Only (Explicit) (push) Failing after 3m21s
GPU Tests / CUDA Tests (11.8) (push) Has been skipped
GPU Tests / CUDA Tests (12.1) (push) Has been skipped
CI / Build (macos-latest) (push) Failing after 9s
CI / Test (macos-latest) (push) Has been skipped
CI / Test (ubuntu-latest) (push) Has been skipped
CI / Python Bindings (maturin) (macos-latest) (push) Has been skipped
CI / Python Bindings (maturin) (ubuntu-latest) (push) Has been skipped
CI / WASM Build + Size Check (push) Has been skipped
CI / Distributed Training Tests (push) Has been skipped
CI / CI Success (push) Failing after 1s
GPU Tests / Metal Tests (push) Has been skipped
Import reordering, long-line reformatting — no logic changes.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 18:11:10 +00:00
Omar SobhandClaude Sonnet 4.6 39b7ef12f4 fix(tests): green-bar rtx-transformers and rtx-distributed test suites
- Fix 35 doctest failures in Phase 2/3 modules (no_run annotations, missing
  imports, wrong API calls, Result context issues)
- Fix test_validation_framework_creation: assert updated to 1e-3 default
- Fix test_report_serialization: replace exact f64 equality with epsilon comparison
- Fix rtx-distributed recovery/tests.rs: add missing ProcessGroup import,
  use recovery_stats().wal_buffer_size instead of private field access

All rtx-transformers and rtx-distributed tests now pass.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 17:56:39 +00:00
Omar SobhandClaude Sonnet 4.6 b60caf042c fix(gaps): G7/CI — ONNX constant codegen, DLPack exhaustiveness, 3 new CI jobs
G7 (Low):
- rtx-onnx-codegen: replace todo!("Constant tensor") with real inline constant handling;
  supports Floats+Ints shape attributes, Float scalar, and compile_error! for unknown cases
- rtx-bindings/dlpack: fix non-exhaustive match arms for Device::Cpu (no #[cfg] gate needed)
  and new DType variants (FP8E4M3/E5M2, MX formats → OpaqueHandle); both features compile clean

CI (Sprint 10): Add 3 missing jobs to .gitea/workflows/ci.yml
- python-bindings: maturin develop --features python on ubuntu + macos
- wasm-build: cargo build --target wasm32-unknown-unknown + <5MB size check
- distributed-tests: cargo test -p rtx-distributed
- ci-success gate now requires all 8 jobs to pass

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 16:10:22 +00:00
Omar SobhandClaude Sonnet 4.6 a08adfbf57 fix(gaps): G4 — re-enable all rtx-transformers Phase 2/3 modules (222 compile errors fixed)
Uncommented all deferred modules in lib.rs and fixed API drift across ~60 files in
9 module groups: continual, curriculum, meta, modular, neural_ode, graph, kan,
perceiver, distributed/pipeline_parallelism.

Common patterns fixed across modules:
- Tensor::randn/zeros/ones([a,b]) → (&[a,b], device)? (slice + Result)
- Result<T, TensorError> → .map_err(Into::into)? in TransformerError contexts
- Device by value → &device references
- &Tensor where Tensor expected → .clone()
- tensor.relu()/tanh()/sigmoid() as methods not ops functions
- Tensor arithmetic returning Result: (a + b)? → (a.clone() + b)?
- shape literals → shape.dims() for Shape type
- sum(n) → sum(Some(n)), mean(None) → mean(&[], false)
- i64 indices → usize where required
- backward(x) → backward(x, None)
- Borrow conflicts on self.field resolved by extracting to locals before mut borrow
- BatchingStats private fields → pub(crate)
- TransformerError::Serialization → ::SerializationError
- Add scalar to tensor: (t + 0.1)? → t.add_scalar(0.1)?

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 16:08:02 +00:00
Omar SobhandClaude Sonnet 4.6 448c0a0be5 fix(gaps): G1 — re-enable Python bindings (PyO3 0.25, Python 3.14)
- Upgrade workspace pyo3 0.24 → 0.25 and numpy 0.24 → 0.25 for Python 3.14 support
- rtx-sklearn-py: replace pinned pyo3 0.20 / pyo3-asyncio 0.20 / numpy 0.20 with workspace versions;
  remove broken pyo3-asyncio async feature; update pyo3-build-config to 0.24
- rtx-bindings: uncomment pyo3/numpy/ndarray optional deps; enable python feature in Cargo.toml
- Migrate rtx-bindings python/ to PyO3 0.25 Bound API:
  &PyAny → Bound<'py, PyAny>, downcast/extract on Bound types, remove rtx_runtime import,
  remove InferenceError arm (variant not in enum), fix py_shape_to_shape signature
- Migrate rtx-sklearn-py src/ to PyO3 0.25 Bound API:
  #[pymodule] fn now takes &Bound<'_, PyModule>, &PyDict → &Bound<'py, PyDict>,
  from_array returns Bound (unbind instead of to_owned), PyTuple::new now fallible,
  use numpy::ndarray (0.16) over workspace ndarray (0.15) to resolve trait mismatches

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 13:55:09 +00:00
Omar SobhandClaude Sonnet 4.6 228137555f fix(gaps): G0/G2/G5/G8 — eliminate unimplemented! panics, re-enable rtx-distributed, rtx-tts, fix multimodal forward
G0 (Critical): Replace 45 unimplemented!() panics across three GPU backends
- rtx-backend-cuda: sin/cos/tanh via PTX, relu/sigmoid/leaky_relu/elu via activation.rs,
  pow/clamp/gt_scalar via unary.rs, var/var_dim host-side, conv2d/max_pool2d/avg_pool2d
  CPU fallback in new ops/conv.rs; new PTX kernels in element_wise.cu
- rtx-backend-rocm: all 15 ops via CPU round-trip (to_vec → compute → from_slice)
- rtx-backend-sycl: all 15 ops via CPU round-trip (to_host → compute → from_data)

G2 (High): Re-add rtx-distributed to workspace
- Vendor 4 minimal RNCCL stub crates at crates/vendor/rnccl/*
- Update rtx-distributed RNCCL path deps to point at stubs (../../../../RNCCL/* → ../../vendor/rnccl/*)
- Remove rtx-distributed from workspace exclude list, add to members

G5 (Medium): Re-enable rtx-tts (213 tests restored)
- Fix 15 rtx-nn API drift issues: LayerNorm::new, Conv1d::from_config, Conv1dPadding::Zeros,
  Dropout::new(p, device), tensor methods (relu/tanh/sigmoid/cat/stack), squeeze(Some(n)),
  to_vec() turbofish removal, Tensor::randn with &[...] slices

G8 (Low): Quantum stubs + multimodal forward bug
- rtx-timeseries: remove dead quantum/neuromorphic TODO comment blocks (no module files exist)
- rtx-multimodal/fusion/transformer.rs: wire TransformerBlock loop in forward()
- rtx-multimodal/fusion/strategies.rs: wire bottleneck_layers loop in forward()
- rtx-transformers/architectures/transformer_block.rs: add forward() method (pre-norm residuals;
  full attention+FFN pending when those sub-layers are wired)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 13:40:23 +00:00
Omar SobhandClaude Sonnet 4.6 c2f4796871 fix(rtx-flash-attention): sm_120 for Blackwell, robust nvcc path resolution
build.rs was hardcoded for sm_90 (incorrectly labelled Ada Lovelace/RTX
5090). Fix for RTX 5060 Ti (sm_120, Blackwell):

- Auto-detect SM via CUDA_ARCH env var (default sm_120); compute_ prefix
  derived automatically so compute_120/sm_120 are no longer hardcoded.
- nvcc resolution: try PATH first, then CUDA_PATH/bin/nvcc, CUDA_HOME,
  and common installation prefixes — no longer panics when nvcc is at
  /usr/local/cuda-13.1/bin but not in $PATH.
- PTX version: sm_100+ → .version 8.0 (PTX ISA 8.0 for Blackwell).
- No-GPU branch: remove the warning — CPU fallback is valid, there is
  no reason to warn every build when cuda/metal are intentionally off.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-26 02:33:37 +00:00
Omar SobhandClaude Sonnet 4.6 470fe07144 D350: GPU backbone training benchmark (RTX 5060 Ti)
Adds d350_gpu_backbone_training — 200-step Adam loop on a 4-regime
corpus that prefers Device::cuda(0) and falls back gracefully to CPU.

Measured numbers:
- CPU (DIM=16):  886 steps/s,  MSE 0.2163 → 0.0024
- GPU (DIM=16):  803 steps/s,  MSE 0.2163 → 0.0024

GPU is marginally slower at DIM=16 because the SSM scan and conv1d
remain on CPU in both paths; cuBLAS only helps the four linear
projections, which are tiny at dim=16.  The GPU advantage emerges at
larger dims (≥256) where the projections dominate. Correctness is
identical on both devices.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-23 21:48:04 +00:00
Omar SobhandClaude Sonnet 4.6 f751414c38 D309: fix MambaRecurrence step — conv1d history buffer + new ergonomic API
The single-step recurrence was missing a causal conv1d history buffer, so
stepwise outputs diverged from the full-sequence forward (max_abs_diff ≈ 6e-2).
Add `conv_buf: Vec<f32>` to `MambaState` (oldest-first per channel), thread it
through `MambaRecurrence::step` so the kernel sees the correct `kc-1` prior
x_in values, and shift the buffer after each step.

Ergonomic additions:
- `MambaRecurrence::init_state()` — zero-initialised state with correct dims
- `MambaRecurrence::state_size()` / `d_model()` — accessor methods
- `MambaState::hidden()` — slice accessor for the SSM h vector
- `MambaState: PartialEq` — enables determinism assertions in tests

Both D309 tests now pass: `step_matches_full_forward` and
`fresh_state_is_zero_and_deterministic`.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-23 17:41:27 +00:00
Omar SobhandClaude Sonnet 4.6 32c4def075 D310: enable rtx-backend-cuda for Blackwell sm_120 / CUDA 13.1
Performance Benchmarks / Run Benchmarks (push) Has been cancelled
Documentation / Build API Documentation (push) Has been cancelled
Documentation / Build User Guide (push) Has been cancelled
CI / Format Check (push) Has been cancelled
CI / Clippy Check (push) Has been cancelled
CI / Build (macos-latest) (push) Has been cancelled
CI / Build (ubuntu-latest) (push) Has been cancelled
CI / Build CPU-Only (Explicit) (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / CI Success (push) Has been cancelled
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-22 12:02:37 +00:00
Omar SobhandClaude Sonnet 4.6 24bd5cf9dc feat(layers): add mamba_step, cloned/gated memory updaters, set_encoder_teacher
Performance Benchmarks / Run Benchmarks (push) Has been cancelled
CI / Format Check (push) Has been cancelled
CI / Clippy Check (push) Has been cancelled
CI / Build (macos-latest) (push) Has been cancelled
CI / Build (ubuntu-latest) (push) Has been cancelled
CI / Build CPU-Only (Explicit) (push) Has been cancelled
Documentation / Build API Documentation (push) Has been cancelled
Documentation / Build User Guide (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / CI Success (push) Has been cancelled
Implements four new rtx-transformers layers required by omni-cortex's omni-think
crate: MambaRecurrence/MambaState (single-token S6 recurrent step),
ClonedMemoryUpdater (linear-tanh cell with SGD + rollout refinement),
GatedMemoryUpdater (GRU-style cell with full backward pass), and
SetEncoderTeacher (time-parallel set encoder with named_params persistence API).
Fixes 10 compile errors in omni-think.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-06-22 11:38:42 +00:00
osobhandClaude Opus 4.8 0e3ff0a1b9 SMT D319 (rustytorch): learned-[MEM]-query (content-addressable) teacher pool
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
Adds an opt-in learned-query attention pool to SetEncoderTeacher
(SetEncoderConfig::with_learned_pool): pool = softmax(q_mem·hᵀ)·h instead of the
fixed mean/decay pool — Isola's transformer-teacher [MEM] query. New q_mem param
(threaded through graph/train_step/run/named_params; only updated in learned-pool
mode). Default off → existing teachers byte-unchanged.

Finding (test teacher_content_addresses_selective_retrieval): on a selective-
retrieval task (signal in one marked token among distractors) BOTH the mean-pool
and learned-query teachers recover the marked token to low MSE (~0.0006 / ~0.002)
— because the self-attention layer already routes the marked token's signal to
every position before the pool. So the mean-pool was NOT the recall bottleneck
(correcting the D318 hypothesis): the teacher can content-address; the real
recall bottleneck is the recurrent *cell* that imitates it. The learned-query
pool is shipped as an equally-capable, faithful-to-the-talk alternative.

All 5 teacher unit tests pass; clippy(-D)/fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-17 09:31:18 -07:00
osobhandClaude Opus 4.8 ca3f12c6c8 SMT D316 (rustytorch): train_rollout — truncated K-step BPTT for the memory cell
CI / Format Check (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
ClonedMemoryUpdater::train_rollout rolls the cell forward over K inputs on its
OWN memory (not teacher-forced) and backprops the accumulated predict-the-future
loss through the whole K-step graph — the tape's first multi-step training path,
directly optimizing the free-rollout behavior the cell is evaluated on (vs the
one-step BC/DAgger paths).

To stay within the finite-diff-gated op set (matmul/gelu/add/mul/sub/sum — no
tensor concat), W_in is split into its memory rows (applied to M) and input rows
(applied to x); the two gradient halves are re-stacked for the Adam update.
Non-finite guard + gradient clip as in the other training paths.

Test: rollout training reduces the K-step loss (>2x). clippy(-D)/fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-17 04:12:46 -07:00
osobhandClaude Opus 4.8 6b7b86fe34 SMT D315 (rustytorch): configurable recency-pool decay (sharp vs smooth oracle)
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
SetEncoderConfig gains `recency_decay` (default 0.85) + `with_recency_decay`,
threaded into pool_weights. A smaller decay concentrates the recency pool on the
most recent tokens — a *sharper* oracle that reacts fast to regime switches
(less denoising). Existing teachers default to 0.85 (unchanged). Lets omni-think
tune the teacher's reaction speed for non-stationary streams.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-17 03:59:36 -07:00
osobhandClaude Opus 4.8 96809d48a1 SMT D314 (rustytorch): gradcheck tanh/sigmoid + GatedMemoryUpdater (GRU cell)
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
F.1 — finite-difference gradchecks for tanh, sigmoid, and the exact gated
composite (1-z)*m + z*c (z=sigmoid, c=tanh) added to tape_cpu_gradcheck.rs.
All pass (rel-err < 2e-2) — the activation VJPs that already existed are now
proven correct on the real CpuBackend (E0 discipline), so the gated cell can
rely on them.

F.2 — GatedMemoryUpdater: a GRU-style gated recurrent memory cell.
  z = sigmoid([M‖x]·W_z); c = tanh([M‖x]·W_c); M_t = (1-z)⊙M + z⊙c
The convex update is a non-expansion (|M_t| ≤ max(|M_0|, 1)), so free rollout
stays bounded with NO clamp — and the learned gate can both jump at a regime
switch (z≈1) and hold+denoise in steady state (z≈0), which the residual+leaky
ClonedMemoryUpdater cannot. Same method surface (new/step/predict/train_step/
train_step_memory) so the omni-think facade is cell-generic.

Tests: gated cell trains (loss drops); 500-step free rollout stays in [-1,1]
without a clamp. clippy(-D)/fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 21:09:10 -07:00
osobhandClaude Opus 4.8 efd0dc9f9b SMT D312: timestamp-embedded (recency) mode for the predictive-state teacher
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
SetEncoderConfig gains an opt-in `recency` flag (default false = unchanged
mean-pool stationary behavior). When set, the encoder adds sinusoidal timestamp
embeddings to the token embeddings (so attention can reason about position) and
pools with an exponential-decay (recent-weighted) reduction instead of a uniform
mean — a recent-window sufficient statistic that tracks non-stationary signals.
Both use only existing-VJP tape ops (add + matmul/softmax); no new params.

Test: recency-mode teacher trains end-to-end (loss >5x drop). Existing
stationary tests unchanged. clippy(-D)/fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 18:34:20 -07:00
osobhandClaude Opus 4.8 1d306ba94b SMT E4: stabilize the cloned updater for DAgger (guard/clip + memory-only step)
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
Two robustness additions for on-policy distillation, which trains on the
policy's own (clamped, sometimes extreme) visited states:
- train_step now skips non-finite-loss steps and clips gradients, so an extreme
  rollout state can't poison every weight via Adam.
- train_step_memory: a memory-only correction at a caller-chosen lr — trains
  just the recurrence (W_in, W_mem) to map (prev,x)->target_mem, leaving the
  BC-trained readout (W_read) intact. This is the key to DAgger working: it
  pulls the free-running memory back toward the oracle trajectory without the
  readout retraining that otherwise blows the predictions up.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 16:03:46 -07:00
osobhandClaude Opus 4.8 e888f7fe4c SMT E3b: leaky + clamped memory updater for bounded free rollout
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
Make the cloned updater's recurrence M_t = ρ·M_{t-1} + Δ a contraction (ρ=0.9)
and clamp the free-running state (|M| ≤ 4). One-step BC has no signal against
autoregressive drift (that is E4/DAgger's job); these keep a free rollout
numerically bounded — no 1e25 blow-up — so E4 has a stable base to refine.
Training is teacher-forced on the bounded oracle memory, so neither ever binds
during training.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 14:51:55 -07:00
osobhandClaude Opus 4.8 0ff3fd4e1f SMT E3b: ClonedMemoryUpdater — recurrent updater cloned from the oracle (no BPTT)
A trainable recurrent cell g(M_{t-1}, x_t) -> M_t (gelu MLP, residual memory
update) plus a predict-the-future readout, trained on Autodiff<CpuBackend> with
the same host-Adam pattern as SetEncoderTeacher.

train_step is one-step behavioral cloning, TEACHER-FORCED on the oracle memory:
each example feeds the oracle's previous memory and regresses (new_mem ->
target_mem) + (readout -> next latent) in a single tape graph. No rollout, no
backprop-through-time. Off-tape step/predict use a gelu byte-identical to the
CPU tape's (tanh approx, sqrt(2/pi), 0.044715) so rollout matches training.

The residual update M_t = M_{t-1} + delta lets the recurrence rule stay
length-invariant — the basis for extrapolating past the teacher's horizon (E3b
generalization test, omni-cortex side).

Tests: updater learns a one-step transition (>10x loss drop); off-tape
step/predict shapes + finiteness. clippy(-D)/fmt clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 14:30:20 -07:00
osobhandClaude Opus 4.8 51a9185056 SMT E3a: expose Mamba's recurrent state as a single-step updater (equivalence-pinned)
MambaRecurrence reconstructs MambaBlock's selective-scan as an explicit
step(state, x_t) -> (state', y_t) recurrence over host f32 weights, with the
recurrent state (h, conv-ring) carried between steps. This is the substrate the
SMT memory updater is behaviorally cloned on (E3b) — no BPTT, one step at a time.

Dimensions are derived from the persisted tensor shapes, so mamba.rs is left
untouched (it is near the 1250-LOC cap). silu/softplus are byte-identical copies
of the forward's.

Equivalence pin (the plan's highest-risk item): stepping a window one token at a
time from a zero state reproduces the full-sequence forward EXACTLY —
max_abs_diff = 0.0 (bit-identical), on an active_block with wide Delta so the
scan genuinely drives the output. Plus a fresh-state determinism test.

clippy(-D warnings) + fmt clean on the new module and test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 11:00:12 -07:00
osobhandClaude Opus 4.8 1b1ce0604a SMT E1: SetEncoderTeacher — the predictive-state oracle (time-parallel, tape-trained)
Promotes the proven attention set-encoder smoke test (PR #4,
tape_train_smoke.rs) into a reusable rtx-transformers layer for Supervised
Memory Training. The teacher maps a window of past tokens to a fixed-size
memory M via embed → self-attention → residual → mean-pool → memory
projection, with a decoder head supervised by predict-the-future MSE so that
M becomes a sufficient statistic of the past.

- Trains end-to-end on Autodiff<CpuBackend> (the gradient-correct real backend
  from PR #3), with a self-contained deterministic host-side Adam.
- Time-parallel by construction (one window → one memory, no recurrence to
  unroll) — this is the oracle whose trajectory the recurrent Mamba updater is
  later behaviorally cloned against, so the recurrent net never needs BPTT.
- Exposes named_params/set_named_params so the caller (omni-think's
  PredictiveStateTeacher facade) owns safetensors persistence + BLAKE3 sealing.
- Adds rtx-backend + rtx-backend-cpu deps (the tape needs a concrete backend).

Tests: teacher trains (loss >5x drop), encode is deterministic + fixed-size,
params round-trip. fmt + clippy(-D warnings) clean on the new module.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-16 09:37:55 -07:00
osobhandClaude Opus 4.8 9a31a07cc9 rtx-autograd: training smoke tests proving the tape learns
CI / Format Check (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
End-to-end training on `Autodiff<CpuBackend>` (forward → backward →
extract grads → SGD → repeat), guarding the gradient-correctness fixes:

- `mlp_trains_and_loss_decreases`: 2-layer MLP (matmul + gelu), loss 8.65 → 0.39.
- `attention_set_encoder_learns_window_mean`: a minimal attention set-encoder
  (the SMT predictive-state teacher shape) learns to predict its input window's
  per-dim mean, loss 0.27 → ~0.0. The embedding fans out to Q/K/V and the
  residual (4 uses), so this also regression-guards the fan-out gradient
  accumulation fix inside a real attention block.

All ops used are gradient-checked in `tape_cpu_gradcheck.rs`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-15 21:24:56 -07:00
osobhandClaude Opus 4.8 fc895a2de5 rtx-autograd: make the tape correct + sound on real backends
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
The decorator autograd (`Autodiff<B>`) had never been gradient-checked
against a real tensor backend — the entire test suite runs on a shape-only
`MockBackend` whose ops return their input, so they validate graph structure
but never gradient values. Running it through `CpuBackend` for the first time
(new `tests/tape_cpu_gradcheck.rs`, finite-difference checks) surfaced three
bugs that made the tape unusable for training; this fixes all three.

1. Double-free / UB in the dimension-erasure cast. The backward ops cast a
   tensor to its runtime const-generic dimension via
   `mem::transmute_copy::<_, TensorPrimitive<N>>(&src)` in ~100 sites. That
   bit-copies the owned `Vec` without forgetting the source, so two values own
   one buffer → double-free on any heap-backed backend (and Stacked-Borrows UB
   from the typed pun). Replaced every site with a single `into_dim` helper
   that is now **fully safe** — it round-trips through `to_data`/`from_data`
   and rebuilds the shape with `array::from_fn`, no `unsafe` at all. (This is
   why the whole repo previously bypassed the tape with analytic backward.)

2. Fan-out gradients were silently dropped. `accumulate_gradients` was a stub
   that returned one path and discarded the other, and `AutodiffTensor::clone`
   minted a fresh `TensorId`. Together, reusing a tensor (residuals,
   `mul(s, s)`, shared Q/K/V — universal in transformers) split its gradient
   across two ids and summed neither, yielding a fraction of the true value.
   `accumulate_gradients` now sums via `B::add`; `clone` preserves the id so
   fan-out paths collide on one sink.

3. Softmax backward panicked. `SoftmaxBackward` / `stable_softmax_backward`
   subtracted a keep-dim row-sum from the full-shape grad, but the elementwise
   backends assert equal shapes (no broadcasting). Added `broadcast_along_dim`
   to tile the row-sum to full width first.

Verified: `tape_cpu_gradcheck` (matmul, fan-out add·mul, softmax) passes with
rel-err < 2e-2 vs central differences; full `rtx-autograd` suite green (263
passed, 0 failed); lib clippy `-D warnings` clean.

Known follow-up (out of scope): `cargo miri test` still aborts on a
Stacked-Borrows / integer-to-pointer violation inside `rtx-backend-cpu`'s
buffer internals — a grad-free `from_data`+`add`+`sum` probe reproduces the
identical error, so it is pre-existing backend UB, not an autograd issue.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-15 21:06:32 -07:00
osobh 5c2ee63d53 GPU Mamba forward + rtx-tensor device-pointer API + matrix exponential
Performance Benchmarks / Run Benchmarks (pull_request) Has been cancelled
CI / Format Check (pull_request) Has been cancelled
Documentation / Build User Guide (pull_request) Has been cancelled
CI / Clippy Check (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / Build CPU-Only (Explicit) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
Documentation / Build API Documentation (pull_request) Has been cancelled
GPU Tests / Check GPU Availability (pull_request) Has been cancelled
GPU Tests / CUDA Tests (11.8) (pull_request) Has been cancelled
GPU Tests / CUDA Tests (12.1) (pull_request) Has been cancelled
GPU Tests / Metal Tests (pull_request) Has been cancelled
Persist accumulated WIP across rtx-tensor / rtx-transformers / rtx-runtime.
Two related feature groups:

GPU enablement (unblocks the Phase-3 spec §8 CUDA Mamba path):
- rtx-tensor: `Tensor::cuda_device_ptr()` + storage GPU-buffer accessors
  (`raw_ptr.rs`) expose the raw CUdeviceptr that kernel launches need —
  the "rtx-tensor GPU memory access API" the Mamba CUDA kernels were
  blocked on.
- rtx-transformers: `MambaBlock::forward_cuda` runs the four linear
  projections through cuBLAS on-device (in/out/x/dt_proj), keeping the
  selective scan + conv1d + activations on CPU; dispatched automatically
  from `forward` when on a CUDA device under the `cuda` feature. Updated
  `mamba_cuda_kernels.rs` accordingly.
- supporting plumbing in rtx-runtime stream/bridge and rtx-tensor
  storage/conversion/concatenation/creation + rtx-flash-attention.

Linear algebra (rtx-tensor):
- `linalg/matrix_exp.rs`: real matrix exponential via scaling-and-squaring
  with a degree-13 Padé approximant (Higham 2005), f64 internally.
- `complex/linalg.rs`: complex matmul/adjoint, Hermitian eigendecomposition
  (`ComplexEigenResult`), and the complex matrix exponential, nalgebra-backed.
- tests for both.

Builds verified on the CPU path (`cargo check -p rtx-tensor -p rtx-transformers
-p rtx-runtime -p rtx-flash-attention` clean). The `cuda` feature and the
rtx-backend-cuda NVCC build remain unbuildable on this host (CUDA/glibc header
mismatch) — pre-existing and unrelated to these changes.
2026-06-15 18:51:30 -07:00
omar sobhandClaude Opus 4.8 bc82745d8f Phase 4a: trained real SSM beats memoryless baseline on a temporal task
Performance Benchmarks / Run Benchmarks (pull_request) Successful in 15m17s
CI / Format Check (pull_request) Failing after 58s
CI / Clippy Check (pull_request) Failing after 5m58s
CI / Build (ubuntu-latest) (pull_request) Failing after 7m29s
CI / Build CPU-Only (Explicit) (pull_request) Failing after 18m58s
Documentation / Build API Documentation (pull_request) Failing after 5m46s
Documentation / Build User Guide (pull_request) Successful in 15s
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Test (macos-latest) (pull_request) Has been cancelled
CI / Test (ubuntu-latest) (pull_request) Has been cancelled
CI / CI Success (pull_request) Has been cancelled
End-to-end demonstration that training the real selective-scan Mamba buys
a genuine temporal-modeling win — the payoff of M1–M3.

Task: next-token prediction on a multi-regime sequence (x[t] = μ_regime +
noise). Predicting x[t+1] inside a regime requires integrating recent
history to average out the noise — a memoryless model can't.

Result (same sequence, all three):
  persistence (memoryless)  MSE = 0.0895
  untrained Mamba           MSE = 0.2167
  trained Mamba (400 Adam)  MSE = 0.0002

The trained backbone integrates history to de-noise the regime mean,
beating the memoryless persistence baseline by ~450× and improving
~1000× over its untrained self. (Single-sequence fit: demonstrates the
SSM's temporal-modeling capacity, not held-out generalization.)

This replaces the old non-result ("random Mamba 6.5% vs linear 48%") with
a real "trained SSM exploits temporal structure" demonstration.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-03 12:10:19 +00:00
omar sobhandClaude Opus 4.8 639937e9f5 Mamba M3.5: canonical numerically-stable initialization
Plain randn(0,1) init made A=-exp(A_log) and Δ wildly large, overflowing
the real exp(Δ·A) scan to NaN (the stub never cared — it discarded these
weights). new()/new_seeded() now share a build() with canonical S6 init:
  - A_log = ln(1..=d_state) ⇒ A = -(1..=d_state), bounded
  - dt_bias so softplus(dt_bias) ≈ 0.01 (small, stable Δ; near-identity
    scan at init — intentional for gradient flow)
  - D = 1, zero conv bias, projections scaled by 1/√fan_in (capped 0.5)

This fixes the NaN that broke omni-cortex's d231 action-conditioned
predictor training (now green). Seeded determinism preserved.

Tests: active_block helper (Δ overridden to ≈0.69) exercises the
scan-active regime so the liveness check can observe each weight; the
training test asserts a seed-varying backbone weight (conv1d_weight)
moves. All 6 selective-scan tests green incl. the finite-diff grad check.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-03 11:30:33 +00:00
omar sobhandClaude Opus 4.8 33cf9bf731 Mamba M3: trainable — Adam loop reduces loss and moves weights
Demonstrates end-to-end trainability of the real selective scan. A
self-contained Adam loop (the rtx-transformers AdamOptimizer has no
public gradient setter — the spec permits a bespoke loop) fits a teacher
block's output on a fixed input: forward → MSE → analytic backward →
Adam step → rebuild. Over 200 steps the loss drops >50% and the backbone
weight A_log moves, confirming gradients actually train the model (not
just the head). All 6 selective-scan tests green.

The production AdamOptimizer can be wired once it exposes a gradient
setter; the M2 backward already returns grads in its HashMap shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-03 11:15:45 +00:00
omar sobhandClaude Opus 4.8 199130fa7d Mamba M2: analytic backward (gradient-checked)
Hand-written VJP of the selective-scan forward (Phase-3 spec §5/§7):
MambaBlock::backward(x, d_out) -> per-parameter gradients keyed by
persistence name, summed over the batch. Differentiates the scan
analytically (reverse-time recurrence over the cached h trajectory)
rather than through the immature rtx-tensor autograd tape.

Covers every parameter: in_proj, conv1d_weight, conv1d_bias, A_log
(via A=-exp(A_log) ⇒ dA_log = dA·A), x_proj, dt_proj, dt_bias, D,
out_proj. Adds stable sigmoid_f32 / silu_grad_f32 helpers.

New test analytic_gradients_match_finite_differences: on a small
well-conditioned instance, ≥30 sampled grad elements across all 9
params match central finite differences within (5e-3 + 5e-2·|fd|).
All 5 selective-scan tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-03 11:13:46 +00:00
omar sobhandClaude Opus 4.8 00cd527ed4 Mamba M1: real selective-scan forward (replaces the passthrough stub)
The MambaBlock forward was a stub — SelectiveScan::forward passed input
through, discretize returned zeros, conv1d was a no-op, and B/C were
randn per call, leaving conv1d_weight/dt_proj/A_log as dead weights with
zero temporal mixing. This implements a genuine S6 selective-scan:

- New params: x_proj [d_inner, dt_rank+2*d_state] (data-dependent dt,B,C),
  dt_bias [d_inner], D [d_inner] (skip). Added to new()/new_seeded() and
  the persistence contract (persistence_tensors/from_persistence_tensors).
- Real forward (CPU f32, looped — backbone is small): in_proj -> causal
  depthwise conv1d -> SiLU -> x_proj->(dt,B,C) -> delta=softplus(dt.dt_proj
  +dt_bias) -> A=-exp(A_log) -> sequential scan h=dA.h+dBu, y=sum C.h + D.u
  -> gate by SiLU(z) -> out_proj. Residual moved OUT (canonical).
  Numerically-stable silu_f32/softplus_f32 helpers.
- The scan runs inline (not via the immature rtx-tensor autograd tape);
  the analytic backward lands in M2 per docs/phase3_real_ssm_spec.md.

New tests/real_selective_scan.rs (4 cases, all green): liveness (each
formerly-dead weight now moves the output), causality (no future
leakage), seeded determinism, and finite/non-constant output.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-06-03 11:02:46 +00:00
redclawsystems 96106cf888 Merge pull request 'test(rtx-tensor): add coverage for uncovered GenericTensor ops' (#18) from ci-doctor/coverage-20260514-192156 into main
CI / Format Check (push) Failing after 58s
CI / Build (ubuntu-latest) (push) Failing after 5m52s
Documentation / Build User Guide (push) Successful in 39s
Documentation / Build API Documentation (push) Failing after 5m49s
CI / Clippy Check (push) Failing after 6m16s
Performance Benchmarks / Run Benchmarks (push) Successful in 15m54s
CI / Build CPU-Only (Explicit) (push) Failing after 6m53s
CI / Build (macos-latest) (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / CI Success (push) Has been cancelled
Reviewed-on: #18
2026-05-20 10:48:37 +00:00
Omar Sobh d05e28a449 chore (#19)
Co-authored-by: Omar Sobh <[email protected]>
Co-committed-by: Omar Sobh <[email protected]>
2026-05-16 04:46:41 +00:00
Omar SobhandClaude Opus 4.6 0a17f170e6 test(rtx-tensor): add coverage tests for GenericTensor uncovered branches
Add 10 new tests exercising previously uncovered GenericTensor operations:
leaky_relu, elu, gt_scalar, var, var_dim, conv2d (identity kernel,
stride, grad propagation), max_pool2d, and avg_pool2d. Also add
test_utils.rs module for shared test helpers.

SDLC-Coverage: rtx-tensor generic/tensor.rs 19.6% → targeting ~40%+

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-05-14 19:25:11 -07:00
Omar Sobh ff81df62ce chore: commit local changes before node reformat 2026-05-10 14:11:34 -07:00
redclawsystems ae53983c03 style: cargo fmt --all (18 files)
Auto-merged by ci-doctor.
2026-05-07 16:30:04 +00:00
redclawsystems 737f4669d8 Merge pull request 'rtx-tensor + rtx-transformers: deterministic Mamba init + safetensors persistence' (#16) from feat/mamba-seed-and-persistence into main
Reviewed-on: #16
2026-05-04 12:30:48 +00:00
3e3e8819f6 rtx-tensor + rtx-transformers: deterministic init + Mamba weight persistence
Two coordinated additions for the omni-cortex D249/D250 work:

rtx-tensor: Tensor::randn_seeded(shape, device, seed) — like
randn() but routes through StdRng::seed_from_u64(seed) so two
calls with (shape, device, seed) produce bit-exact identical
tensors. CPU is the canonical generator; GPU calls go via to_device
transfer. Required for reproducible model init.

rtx-transformers: MambaBlock gains:
  - new_seeded(config, device, seed) — every internal weight tensor
    initialised via randn_seeded() with per-tensor SplitMix64-derived
    seeds. Two calls with the same (config, device, seed) → bit-
    exact identical block.
  - persistence_tensors() -> Vec<(&'static str, &Tensor)> — read-only
    view of the six (or seven, with conv_bias) internal weight
    tensors with canonical names (in_proj, conv1d_weight,
    conv1d_bias?, A_log, dt_proj, out_proj). Stable across versions
    so safetensors round-trip works.
  - from_persistence_tensors(config, device, HashMap<String, Tensor>)
    — rebuild a MambaBlock from a name → tensor map. Validates each
    tensor's shape against the config and surfaces clean errors on
    mismatch (so wrong-DIM safetensors loads fail explicitly).

These three primitives together give omni-cortex's D249 (operator-
seeded determinism) and D250 (safetensors round-trip + BLAKE3 hash
pin) clean library hooks without exposing MambaBlock's private
fields.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-04 05:26:27 -07:00
osobhandClaude Opus 4.7 7e576e8d69 rtx-csm: implement LoRA merge + load-from-path
Closes the LoRA inference path that was previously stubbed. Two new
public APIs in rtx-csm:

1. lora::load_lora_set_from_safetensors(path, config) -> LoraSet
   Reads a trained adapter file (produced by training::
   save_lora_adapter[_with_metadata]). Pairs the .lora_a / .lora_b
   tensors by base-weight prefix into LoraAdapter entries.

2. lora::merge_into_safetensors(base, lora, scale, output)
   Reads the base CSM safetensors, folds in the LoRA deltas at the
   given scale (typically alpha/rank from training), writes a merged
   safetensors. Original dtype preserved (F16 on Metal, BF16 on
   CUDA, F32 on CPU). Tensors LoRA doesn't target are passed
   through unchanged.

3. Generator::load_csm_1b_from_path(path, device)
   Variant of load_csm_1b that takes an explicit weights path
   instead of going through the HF cache. Mimi + tokenizer still
   resolve via the hub. This is the path consumers use to load a
   merged checkpoint.

MergeReport struct restructured to expose merged/skipped/passthrough
counts so callers can verify the adapter actually targeted weights.
The previous typed-error test is replaced with a missing-base-file
test that exercises the real code path.

Used by zeroclaw-channel-voice's `--lora-adapter` flag to bake a
LoRA adapter into a per-process merged checkpoint at boot, with
zero per-inference overhead.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-03 10:06:46 -07:00
osobhandClaude Opus 4.7 8a50a1efcd rtx-csm: pre-sentence hook + streaming-safe post-process
Two additions for downstream voice-channel prosody / quality wiring:

1. Converse::with_pre_sentence_hook
   New PreSentenceHook (Box<dyn FnMut(&mut Generator, &str) -> Result<()>>)
   that fires before each sentence's synth call. Receives mutable
   access to the underlying Generator + the sentence text — lets
   callers apply per-sentence steering (e.g. emotion shifts mid-reply)
   without touching crate internals. Wired into both `synthesize` and
   `synthesize_streaming` paths.

2. PostProcess streaming split
   - New StreamingHpfState — stateful biquad whose IIR taps carry
     across chunk boundaries so streaming HPF doesn't click at chunk
     joins. Identical filter coefficients to the one-shot path.
   - PostProcess::apply_chunk_safe(samples, hpf_state) — HPF + declick
     per chunk, no LUFS (needs full utterance).
   - PostProcess::apply_lufs(samples, sample_rate) -> Result<f32> —
     full-utterance loudness gain, returns the linear gain applied
     so streaming pipelines can compensate retroactively if needed.
   - compute_lufs_gain helper extracted from loudness_normalize.

Used by zeroclaw-channel-voice for the Maya-gap-closure pack.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-02 07:33:52 -07:00
redclawsystems e23cdfed58 Merge pull request 'fix(rtx-distributed): ring_allreduce delegates to ProcessGroup for NCCL dispatch' (#13) from fix/rustytorch-ring-allreduce-nccl-dispatch-2026-05-02 into main 2026-05-02 12:58:24 +00:00
Omar Sobh 623e6679d5 fix(rtx-distributed): ring_allreduce delegates to ProcessGroup for NCCL dispatch
ring_allreduce() contained its own simulation that multiplied each gradient
value by world_size (to fake an AllReduce sum), bypassing the ProcessGroup
dispatch entirely. This meant the overlapped synchronization path never used
NCCL or RNCCL, even when those features were compiled in.

Replace the hand-rolled simulation with a call to
self.process_group.allreduce(tensor, ReduceOp::Sum) so the overlapped path
uses the same backend as synchronize_gradients_sequential. The communication
latency sleep is kept for benchmarking purposes.

Add test_ring_allreduce_matches_sequential_path to verify both paths produce
identical gradient values under CPU simulation.

Closes #10
2026-05-02 05:58:10 -07:00
redclawsystems 6eee6f76e4 Merge pull request 'rtx-csm: Converse::with_context for persistent speaker prompt' (#12) from feat/csm-converse-with-context into main 2026-05-01 06:35:40 +00:00
osobhandClaude Opus 4.7 bf5e86c549 rtx-csm: Converse::with_context for persistent speaker prompt
Without a voice anchor, CSM-1B picks a different speaker each turn
and drifts mid-sentence on longer outputs (high-pitch squeaks,
female/male swap mid-utterance). The fix is the standard CSM
speaker-prompt pattern: pass a Segment with reference audio + its
transcript as context to every generate() call.

Previously Converse::synthesize and synthesize_streaming hardcoded
`&[]` for the context arg. Add a `context: Vec<Segment>` field on
Converse plus a builder method:

    let conv = Converse::new(&llm, &mut gen)
        .with_context(vec![Segment::new(0, transcript, audio)]);

Both synth paths now pass `&self.context` instead of `&[]`. Empty
context (default) keeps prior behavior.

Verified end-to-end with zeroclaw-channel-voice + macOS `say`-
generated reference: same input now produces deterministic-length
output across turns (2.64s vs. previously varying 6/19/38s) and the
voice matches the seed throughout.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-04-30 23:32:14 -07:00
builderandClaude Sonnet 4.6 301f223b91 refactor(rustytorch): full clean review 2026-04-30
- fix(workspace): exclude crates/training/rtx-distributed from workspace members
  — RNCCL path deps absent in standalone checkout blocked all cargo operations
- refactor(rtx-backend-webgpu): split compute.rs (1654 lines) into compute/mod.rs
  (1040) + compute/conv.rs (628) — both within 1250-line limit
- fix(rtx-bench): add missing src/bin/main.rs declared in [[bin]] Cargo.toml entry
- fix(gitignore): narrow `bin/` exclusion to /bin/ only; add !**/src/bin/ exception
  to allow Rust source binary directories
- style(rtx-eval): 67x "literal".to_string() → "literal".to_owned() in automation,
  validation, metrics, lib, core, error modules and build.rs

All tests pass (64 tests across rtx-eval + rtx-backend-webgpu, 0 failures).
Clippy clean (-D warnings) on all changed crates.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-04-30 08:27:50 -07:00
osobhandClaude Opus 4.7 fff1b7acd5 rtx-csm: converse_server — deprecation note pointing at zeroclaw-channel-voice
The canonical voice loop now lives in zeroclaw-channel-voice
(`~/projects/zeroclaw/crates/zeroclaw-channel-voice`, binary
`voice_server`). It routes the LLM path through zeroclaw's agent
runtime — multi-turn history, tools, memory, provider routing —
instead of the OpenAI-compatible direct path here.

Same WS wire protocol so `examples/converse_client.rs` drives both;
no client-side migration needed.

This binary is intentionally kept buildable for:
  1. Reproducing perf_history.md Phase 8.10 benches.
  2. Standalone (no-agent) use when zeroclaw isn't desired.

Module doc + main() startup banner updated to point at the new home.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2026-04-30 04:15:11 -07:00