mirror of
https://github.com/hanzoai/ml.git
synced 2026-11-20 23:08:29 +00:00
The backend ran u32 storage through its f32 kernels and answered in F32: reduce_op for sum, max and min, and binary_impl for add, sub, mul, div, maximum and minimum. The kernels read a u32's bits as a float, which RADV flushes to zero, so the sum of [1, 1, 1, 1, 0] was 0.0. The CPU, CUDA and ROCm answer U32. ModernBert's YaRN path reads row lengths as a u32 mask's sum and shifts u32 positions by broadcast_add before an index_select, so on Vulkan a pass past the trained positions failed with "unexpected dtype, expected: U32, got: F32" and, past that, "index_select requires u32 ids, got F32". A u32 reduction now runs in integer arithmetic in reduce_u32.comp: sum (wrapping mod 2^32), min, max, and argmin and argmax keeping the first extreme index as the CPU does. It reads the storage itself when contiguous from offset 0, else a bit-exact contiguous_u32 copy. A reduction of any other storage dtype is refused rather than answered in f32. A binary op on u32 takes the CPU fallback that ops without a kernel already take: its operands are ids, positions and masks, small, and a broadcast one would be copied bit-exactly on the CPU anyway. f32 storage is unchanged. vulkan_dtype_tests compares every reduction over each axis and a transposed view, and every binary op by a broadcast column and a contiguous tensor, with the CPU, in dtype and value, for tensors uploaded as U32, I64, F32 and BF16 (held as u32, u32, f32 and f32). It passes on evo's Radeon 8060S; the old reduce_op answers a U32 sum in F32, and the old binary_impl a U32 add. hanzo-ml 0.11.110. Claude-Session: https://claude.ai/code/session_01HdGTLzC2y2CATAiF1pD1KE