style: clear the fmt gate and two lib clippy warnings
CI / Format Check (push) Canceled after 0s
Performance Benchmarks / Run Benchmarks (push) Canceled after 0s
CI / Clippy Check (push) Canceled after 0s
CI / Build (macos-latest) (push) Canceled after 0s
CI / Build (ubuntu-latest) (push) Canceled after 0s
CI / Test (macos-latest) (push) Canceled after 0s
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Build CPU-Only (Explicit) (push) Canceled after 0s
CI / Python Bindings (maturin) (macos-latest) (push) Canceled after 0s
CI / Python Bindings (maturin) (ubuntu-latest) (push) Canceled after 0s
CI / WASM Build + Size Check (push) Canceled after 0s
CI / Distributed Training Tests (push) Canceled after 0s
CI / CI Success (push) Canceled after 0s
Documentation / Build API Documentation (push) Canceled after 0s
Documentation / Build User Guide (push) Canceled after 0s

Deferred deliberately while the TWIN-2B/2C campaign had live marches:
each march is a fresh `cargo test` invocation, so reformatting
`turek_hron_fsi2.rs` mid-campaign would have forced a test-binary
rebuild and cost comparability for a cosmetic gate. The family closed,
so this is now free.

- `cargo fmt --all` across 8 files that had drifted (including the
  FSI2/FSI3 harnesses touched by the UMEAN/ES override commits).
- `rtx-feature-store/tests/integration_tests.rs` had trailing
  whitespace rustfmt refused to format around ("left behind trailing
  whitespace" internal error), so the whole file was being skipped;
  stripped it and the file formats now.
- Two `unnecessary_parentheses` warnings in the rtx-transformers lib
  (`continual/progressive.rs`, `curriculum/mod.rs`) — these were the
  only rustytorch warnings surfacing through omni-cortex's workspace
  clippy gate, which is how they were found.

No behaviour change. rtx-fsi test binaries still build.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01B1feFAQxjbCRHePUdxuNra
This commit is contained in:
Omar Sobh
2026-09-02 19:15:53 -07:00
co-authored by Claude Opus 5
parent 045e145962
commit 9575b84803
11 changed files with 44 additions and 35 deletions
@@ -514,7 +514,10 @@ fn abs_backward_zero_input_is_zero_not_nan() {
) )
.expect("backward"); .expect("backward");
let g = grad2(&storage, x_id); let g = grad2(&storage, x_id);
assert!(g.iter().all(|v| v.is_finite()), "abs grad has non-finite values: {g:?}"); assert!(
g.iter().all(|v| v.is_finite()),
"abs grad has non-finite values: {g:?}"
);
assert_eq!(g[0], 1.0); assert_eq!(g[0], 1.0);
assert_eq!(g[1], 0.0, "sign(0) must be 0"); assert_eq!(g[1], 0.0, "sign(0) must be 0");
assert_eq!(g[2], -1.0); assert_eq!(g[2], -1.0);
@@ -37,11 +37,7 @@ pub fn conv2d(
// groups 1. Dispatch to it when possible. // groups 1. Dispatch to it when possible.
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
if stride[0] == stride[1] if stride[0] == stride[1] && padding[0] == padding[1] && dilation == [1, 1] && groups == 1 {
&& padding[0] == padding[1]
&& dilation == [1, 1]
&& groups == 1
{
let mut output = MetalBuffer::new(device, out_numel, MetalBufferUsage::Shared) let mut output = MetalBuffer::new(device, out_numel, MetalBufferUsage::Shared)
.expect("Failed to allocate output buffer for conv2d"); .expect("Failed to allocate output buffer for conv2d");
nn::conv2d( nn::conv2d(
+4 -13
View File
@@ -16,7 +16,7 @@ use crate::MetalTensorPrimitive;
use rtx_metal::{MetalBuffer, MetalBufferUsage}; use rtx_metal::{MetalBuffer, MetalBufferUsage};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use rtx_metal::sparse::{spmm_csr, CsrMatrix}; use rtx_metal::sparse::{CsrMatrix, spmm_csr};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use std::cell::RefCell; use std::cell::RefCell;
@@ -69,8 +69,7 @@ fn cached_select_csr(
let row_ptr: Vec<i32> = (0..=e as i32).collect(); let row_ptr: Vec<i32> = (0..=e as i32).collect();
let col_indices: Vec<i32> = indices.iter().map(|&i| i as i32).collect(); let col_indices: Vec<i32> = indices.iter().map(|&i| i as i32).collect();
let values = vec![1.0f32; e]; let values = vec![1.0f32; e];
let csr = let csr = CsrMatrix::new(device, e, num_src_rows, &row_ptr, &col_indices, &values).ok()?;
CsrMatrix::new(device, e, num_src_rows, &row_ptr, &col_indices, &values).ok()?;
let csr = Rc::new(csr); let csr = Rc::new(csr);
if cache.len() >= CSR_CACHE_CAP { if cache.len() >= CSR_CACHE_CAP {
cache.clear(); cache.clear();
@@ -203,11 +202,7 @@ pub fn index_select<const D: usize>(
MetalBuffer::new(device, out_numel, MetalBufferUsage::Shared) MetalBuffer::new(device, out_numel, MetalBufferUsage::Shared)
{ {
if spmm_csr(device, &csr, tensor.data(), &mut output, row_len).is_ok() { if spmm_csr(device, &csr, tensor.data(), &mut output, row_len).is_ok() {
return MetalTensorPrimitive::new( return MetalTensorPrimitive::new(output, out_shape, tensor.device.clone());
output,
out_shape,
tensor.device.clone(),
);
} }
} }
} }
@@ -267,11 +262,7 @@ pub fn index_add<const D: usize>(
MetalBuffer::new(device, out_numel, MetalBufferUsage::Shared) MetalBuffer::new(device, out_numel, MetalBufferUsage::Shared)
{ {
if spmm_csr(device, &csr, tensor.data(), &mut output, row_len).is_ok() { if spmm_csr(device, &csr, tensor.data(), &mut output, row_len).is_ok() {
return MetalTensorPrimitive::new( return MetalTensorPrimitive::new(output, out_shape, tensor.device.clone());
output,
out_shape,
tensor.device.clone(),
);
} }
} }
} }
+13 -4
View File
@@ -171,8 +171,11 @@ pub fn pow<const D: usize>(tensor: &MetalTensorPrimitive<D>, exp: f32) -> MetalT
/// ///
/// rtx-metal has no dedicated kernel for this op; computed on host /// rtx-metal has no dedicated kernel for this op; computed on host
/// (same fallback pattern as `reduction::sum_dim`). /// (same fallback pattern as `reduction::sum_dim`).
pub fn clamp<const D: usize>(tensor: &MetalTensorPrimitive<D>, min: f32, pub fn clamp<const D: usize>(
max: f32) -> MetalTensorPrimitive<D> { tensor: &MetalTensorPrimitive<D>,
min: f32,
max: f32,
) -> MetalTensorPrimitive<D> {
let device = tensor.device.metal_device(); let device = tensor.device.metal_device();
let data = tensor.to_vec(); let data = tensor.to_vec();
let result: Vec<f32> = data.iter().map(|x| x.clamp(min, max)).collect(); let result: Vec<f32> = data.iter().map(|x| x.clamp(min, max)).collect();
@@ -184,10 +187,16 @@ pub fn clamp<const D: usize>(tensor: &MetalTensorPrimitive<D>, min: f32,
/// ///
/// rtx-metal has no dedicated kernel for this op; computed on host /// rtx-metal has no dedicated kernel for this op; computed on host
/// (same fallback pattern as `reduction::sum_dim`). /// (same fallback pattern as `reduction::sum_dim`).
pub fn gt_scalar<const D: usize>(tensor: &MetalTensorPrimitive<D>, value: f32) -> MetalTensorPrimitive<D> { pub fn gt_scalar<const D: usize>(
tensor: &MetalTensorPrimitive<D>,
value: f32,
) -> MetalTensorPrimitive<D> {
let device = tensor.device.metal_device(); let device = tensor.device.metal_device();
let data = tensor.to_vec(); let data = tensor.to_vec();
let result: Vec<f32> = data.iter().map(|&x| if x > value { 1.0 } else { 0.0 }).collect(); let result: Vec<f32> = data
.iter()
.map(|&x| if x > value { 1.0 } else { 0.0 })
.collect();
let output = MetalBuffer::from_slice(device, &result).expect("Failed to create buffer"); let output = MetalBuffer::from_slice(device, &result).expect("Failed to create buffer");
MetalTensorPrimitive::new(output, tensor.shape, tensor.device.clone()) MetalTensorPrimitive::new(output, tensor.shape, tensor.device.clone())
} }
@@ -616,7 +616,10 @@ fn test_parity_transpose_2d() {
let t = creation::from_data(&data, [3, 4], &device); let t = creation::from_data(&data, [3, 4], &device);
let tt = shape::transpose(&t); let tt = shape::transpose(&t);
// physical transpose: result must be contiguous row-major [4, 3] // physical transpose: result must be contiguous row-major [4, 3]
assert!(tt.is_contiguous(), "transpose must return a contiguous tensor"); assert!(
tt.is_contiguous(),
"transpose must return a contiguous tensor"
);
let got = dev_ops::copy_to_host(&tt); let got = dev_ops::copy_to_host(&tt);
let mut want = vec![0.0f32; 12]; let mut want = vec![0.0f32; 12];
for i in 0..3 { for i in 0..3 {
@@ -671,6 +674,9 @@ fn test_parity_matmul_after_transpose() {
} }
} }
for (g, w) in got.iter().zip(want.iter()) { for (g, w) in got.iter().zip(want.iter()) {
assert!((g - w).abs() < 1e-4, "matmul-after-transpose mismatch: {got:?} vs {want:?}"); assert!(
(g - w).abs() < 1e-4,
"matmul-after-transpose mismatch: {got:?} vs {want:?}"
);
} }
} }
@@ -172,7 +172,9 @@ fn test_index_select_large() {
let dev = device(); let dev = device();
let n = 5000usize; let n = 5000usize;
let f = 64usize; let f = 64usize;
let data: Vec<f32> = (0..n * f).map(|x| ((x * 2654435761) % 1000) as f32 * 0.001).collect(); let data: Vec<f32> = (0..n * f)
.map(|x| ((x * 2654435761) % 1000) as f32 * 0.001)
.collect();
let t = MetalBackend::from_data(&data, [n, f], &dev); let t = MetalBackend::from_data(&data, [n, f], &dev);
// Pseudo-random gather with repeats, GNN-edge style. // Pseudo-random gather with repeats, GNN-edge style.
let indices: Vec<usize> = (0..3 * n).map(|i| (i * 40503) % n).collect(); let indices: Vec<usize> = (0..3 * n).map(|i| (i * 40503) % n).collect();
@@ -190,7 +192,9 @@ fn test_index_add_large() {
let e = 15000usize; let e = 15000usize;
let n = 5000usize; let n = 5000usize;
let f = 64usize; let f = 64usize;
let data: Vec<f32> = (0..e * f).map(|x| ((x * 2246822519) % 1000) as f32 * 0.001 - 0.5).collect(); let data: Vec<f32> = (0..e * f)
.map(|x| ((x * 2246822519) % 1000) as f32 * 0.001 - 0.5)
.collect();
let t = MetalBackend::from_data(&data, [e, f], &dev); let t = MetalBackend::from_data(&data, [e, f], &dev);
let indices: Vec<usize> = (0..e).map(|i| (i * 40503) % n).collect(); let indices: Vec<usize> = (0..e).map(|i| (i * 40503) % n).collect();
let out = MetalBackend::index_add(t, &indices, n); let out = MetalBackend::index_add(t, &indices, n);
@@ -256,8 +256,8 @@ fn fsi2_flapping_flag() {
// pins nothing here — those bands live in the campaigns' composition // pins nothing here — those bands live in the campaigns' composition
// harnesses. The machinery invariants above stay asserted at every // harnesses. The machinery invariants above stay asserted at every
// inflow and stiffness. // inflow and stiffness.
let benchmark_case = case.u_mean.to_bits() == FSI2.u_mean.to_bits() let benchmark_case =
&& case.e_s.to_bits() == FSI2.e_s.to_bits(); case.u_mean.to_bits() == FSI2.u_mean.to_bits() && case.e_s.to_bits() == FSI2.e_s.to_bits();
let default_coupling = benchmark_case && smooth_in_h == 0.0 && config.coupler == "aitken"; let default_coupling = benchmark_case && smooth_in_h == 0.0 && config.coupler == "aitken";
let mode2_coupling = let mode2_coupling =
benchmark_case && smooth_in_h == 0.0 && config.coupler == "iqn" && subcycle == 2; benchmark_case && smooth_in_h == 0.0 && config.coupler == "iqn" && subcycle == 2;
@@ -226,8 +226,8 @@ fn fsi3_added_mass_flag() {
// (`RTX_FSI3_UMEAN`) or e_s (`RTX_FSI3_ES`) pins nothing here. // (`RTX_FSI3_UMEAN`) or e_s (`RTX_FSI3_ES`) pins nothing here.
// Machinery invariants above stay asserted at every inflow and // Machinery invariants above stay asserted at every inflow and
// stiffness. // stiffness.
let benchmark_case = case.u_mean.to_bits() == FSI3.u_mean.to_bits() let benchmark_case =
&& case.e_s.to_bits() == FSI3.e_s.to_bits(); case.u_mean.to_bits() == FSI3.u_mean.to_bits() && case.e_s.to_bits() == FSI3.e_s.to_bits();
let default_release = benchmark_case let default_release = benchmark_case
&& config.subcycle == 2 && config.subcycle == 2
&& config.mask_hysteresis == 0.0 && config.mask_hysteresis == 0.0
@@ -149,9 +149,9 @@ impl AdapterLayer {
// Compute mean and variance along last dimension // Compute mean and variance along last dimension
let mean = input.mean(&[-1i32], true)?; let mean = input.mean(&[-1i32], true)?;
let variance = ((input - &mean)? let variance = (input - &mean)?
.pow_tensor_scalar(2.0)? .pow_tensor_scalar(2.0)?
.mean(&[-1i32], true)?); .mean(&[-1i32], true)?;
// Normalize // Normalize
let eps_tensor = Tensor::full(variance.shape().dims(), eps as f32, variance.device())?; let eps_tensor = Tensor::full(variance.shape().dims(), eps as f32, variance.device())?;
@@ -719,7 +719,7 @@ impl ExponentialSchedule {
impl Schedule for ExponentialSchedule { impl Schedule for ExponentialSchedule {
fn get_difficulty_at_step(&self, step: usize) -> f32 { fn get_difficulty_at_step(&self, step: usize) -> f32 {
let exp_factor = (1.0 - (-self.growth_rate * step as f32).exp()); let exp_factor = 1.0 - (-self.growth_rate * step as f32).exp();
let difficulty = self.initial_difficulty let difficulty = self.initial_difficulty
+ exp_factor * (self.final_difficulty - self.initial_difficulty); + exp_factor * (self.final_difficulty - self.initial_difficulty);
difficulty.min(self.final_difficulty) difficulty.min(self.final_difficulty)