- orchestrator_core: execute_classical is genuine seeded QKV self-attention; execute_flash_attention delegates to rtx_flash_attention::flash_attention_forward (8-head reshape, clear Err on indivisible hidden); execute_hybrid composes the two; execute_edge/execute_distributed return explicit "modality not implemented" errors instead of fake success — which makes the previously-dead fallback_modalities retry loop real. - tensor_core_kernels: AttentionComputationOptimizer::execute dispatches Standard/Online to scaled_dot_product_attention, Flash to rtx-flash-attention, Approximated to an explicit Err (no approximation kernel exists; refuses to compute exact attention under an approximated label). - 10 new always-on tests incl. flash-vs-standard 1e-3 agreement and an Edge->Distributed->Classical fallback end-to-end. - docs/consolidation.md updated: both entries moved from scaffolding/no-op-stub status to real dispatch descriptions. 982 rtx-transformers lib tests pass. Co-Authored-By: Claude Fable 5 <[email protected]>
7.5 KiB
Duplicate-implementation consolidation notes
Recorded during the 2026-07-09 wiring/dead-code sweep, updated 2026-07-09 during the deferred "rewrite call sites" pass. This pass audited every site listed below; most turned out not to need (or not to be eligible for) a call-site rewrite once actually read in full. Details per item below.
Mixture of Experts
Canonical: rtx-transformers/src/layers/mixture_of_experts/ (MoEConfig,
Router, Expert, MixtureOfExperts).
rtx-transformers/src/layers/metal_moe.rs(Metal-specific) — kept, no change needed. Its types already mirror the canonical naming 1:1 (MetalMoEConfig/MetalExpert/MetalRouter/MetalMoEvs.MoEConfig/Expert/Router/MixtureOfExperts), and its config fields (num_experts,top_k,hidden_dim,expert_hidden_dim,capacity_factor,dropout,aux_loss_weight,activation,bias) are identical toMoEConfig's, plus Metal-only extras (z_loss_weight,jitter_noise,use_metal). This is a backend specialization done right; forcing a shared struct would just add an indirection layer for no benefit.rtx-transformers/src/modular/router.rs— not a duplicate; left as is. This is dynamic module selection (ModuleRouter,TaskConditionedRouter,AttentionRouter,RLRouter) overVec<Box<dyn Module>>for the modular neural network system (modular/modular_network.rs), not token-to-FFN-expert gating. It's wired intoModuleRoutertrait impls inmodular_network.rsand has its own test suite (modular_networks_tests.rs). A genuinely different abstraction — MoE'sRouterroutes tokens to FFN experts by learned gating logits; this routes whole inputs to heterogeneous modules (including RL-policy-based and task-conditioned selection). Not merging.rtx-transformers/src/architectures/glam.rs— out of scope, dead code.mod glamis commented out inarchitectures/mod.rs("Temporarily disabled"), so this file is not part of the build at all. It also does not currently compile on its own:GLaMBlock::forwardreferences an undefinedrouting_infobinding (line ~229) — a pre-existing bug unrelated to consolidation. Migrating its expert layer tolayers::mixture_of_experts::{MixtureOfExperts, MoEConfig, Router}is the right call when someone re-enables this module, but doing that migration on dead, non-compiling code with zero call sites and no test coverage today would be unverifiable busywork. Left as a note for whoever re-enables GLaM.
Deleted in the previous sweep (were orphaned, never declared by mod):
layers/moe_layer.rs, layers/moe_integration.rs.
Flash Attention
Canonical: the rtx-flash-attention crate (v2+v3 kernels, CUDA + Metal,
public API: flash_attention_forward/flash_attention_backward and the
FlashAttention/FlashAttentionBackend types over rtx_tensor::Tensor).
Re-audited the three non-JEPA sites previously flagged as reimplementations.
None of them actually contained duplicate attention math to delegate. Two of
the three (tensor_core_kernels.rs, orchestrator_core.rs) have since been
given real execution paths (2026-07-10); see below.
src/tensor_core_kernels.rs— was config/strategy scaffolding only (AttentionConfig,SoftmaxOptimizationStrategy,AttentionComputationOptimizer) with nocompute/forwardmethod anywhere in the file. Now real:AttentionComputationOptimizer::execute(&self, q, k, v: &Tensor) -> Result<Tensor>dispatches onself.softmax_strategy:Standard/Online→Tensor::scaled_dot_product_attention(rtx_tensormatmul + softmax + matmul). Online softmax is mathematically equivalent to standard softmax (same result, different accumulation order) and no separate online-softmax kernel exists here, so it intentionally shares the standard path rather than faking a distinct computation.FlashAttention→ delegates tortx_flash_attention::flash_attention_forward(the crate's own CUDA/Metal-or-naive-CPU-fallback logic applies unchanged).Approximated→ explicitErr: no approximation kernel is implemented, so this strategy refuses to silently compute exact attention under an "approximated" label.- Accepts 3D
[batch, seq, head_dim]or 4D[batch, heads, seq, head_dim]q/k/v; other ranks are a clearErr. - Tests (
tensor_core_kernels::real_execution_tests, always-on, not feature-gated): standard path is finite and input-dependent; flash vs. standard agree within 1e-3 on a small[1,2,4,8]shape;Approximatederrors; wrong-rank input errors.
src/revolutionary/orchestrator_core.rs—execute_flash_attentionand its siblingsexecute_classical/execute_hybrid/execute_edge/execute_distributedwere all identical no-op stubs (Ok(input.clone())) while the scoring/decision machinery around them was real. Now real:execute_classical: genuine QKV self-attention — deterministic fixed-seed weight matrices (Tensor::randn_seeded) project the input, thenscaled_dot_product_attention, then an output projection. Input-dependent, reproducible, not an identity.execute_flash_attention: reshapes[batch, seq, hidden]into flash's[batch, heads, seq, head_dim]convention (8 heads;Errifhiddendoesn't divide evenly) and callsrtx_flash_attention::flash_attention_forwarddirectly.execute_hybrid: real composition —execute_classical's projection feeds intoexecute_flash_attention's attention step, not either path run alone.execute_edge/execute_distributed: explicitErr("modality not implemented: ...")— these need a target-device runtime handle / cluster communicator that this orchestrator has no way to obtain, so they no longer fake success. This also makes the orchestrator'sfallback_modalitiesmachinery real:execute_taskalready retried the next modality onErr, but previously nothing ever errored, so the fallback path was dead code; now Edge/Distributed failures genuinely exercise it.- Tests (
orchestrator_core::real_modality_execution_tests, always-on): classical/flash/hybrid produce finite, input-dependent output (not equal to the input, different for different inputs, deterministic for the same input); flash rejects an indivisible hidden dim; edge/distributed error; a decision withprimary_modality: Edgeandfallback_modalities: [Distributed, Classical]ends up executed via Classical withresult.success == true.
src/training/training_loop.rs— the only mention ofFlashAttentionis a doc comment listing it as an example LLM op; no implementation present.
src/ssl/jepa_gpu.rs is intentionally not in this list: its attention is
part of the fused GPU-resident ViT block written for the JEPA platform, not
a standalone duplicate of rtx-flash-attention's API — the fusion is the
point (avoids materializing intermediate tensors across the ViT block same
as flash attention's inner loop does, but tied to ViT-specific tensor
layouts). Revisit only if rtx-flash-attention grows a fused-block API that
covers this shape.
Speculative decoding
Layering is intentional (documented in rtx-inference/src/speculative/mod.rs):
speculative/ is the orchestration layer (traits/configs/trees);
rtx-inference/src/medusa.rs and src/lookahead.rs are the concrete
implementations. Not a duplication to remove, but keep the two MedusaConfig
types (orchestration vs implementation, re-exported as MedusaHeadsConfig)
from drifting.