From 7f43963d2f0b9bbfb63d2ff0313c7918aa95a417 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Thu, 19 Mar 2026 00:39:03 +0100 Subject: [PATCH] =?UTF-8?q?fix(clippy):=20ml-supervised=20+=20ml-core=20+?= =?UTF-8?q?=20thin=20crates=20=E2=80=94=2034=20errors=20fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ml-supervised: doc backticks, const fn, removed redundant clones, underscore-prefixed params that were actually used ml-labeling: const fn on gpu_acceleration::new() ml-core/ml-ensemble/ml-explainability: already clean Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/ml-labeling/src/gpu_acceleration.rs | 2 +- crates/ml-supervised/src/liquid/training.rs | 14 +++++++------- crates/ml-supervised/src/mamba/mod.rs | 16 +++++++--------- crates/ml-supervised/src/mamba/ssd_layer.rs | 2 +- crates/ml-supervised/src/tft/mod.rs | 11 ++++++----- .../ml-supervised/src/tft/temporal_attention.rs | 15 ++++++++------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/ml-labeling/src/gpu_acceleration.rs b/crates/ml-labeling/src/gpu_acceleration.rs index 8b79610c4..58d4cf76c 100644 --- a/crates/ml-labeling/src/gpu_acceleration.rs +++ b/crates/ml-labeling/src/gpu_acceleration.rs @@ -17,7 +17,7 @@ pub struct GPULabelingEngine { impl GPULabelingEngine { /// Create new `GPU` labeling engine - pub fn new(device: MlDevice) -> Result { + pub const fn new(device: MlDevice) -> Result { Ok(Self { device }) } diff --git a/crates/ml-supervised/src/liquid/training.rs b/crates/ml-supervised/src/liquid/training.rs index a5cd60c28..e6dd7ebb3 100644 --- a/crates/ml-supervised/src/liquid/training.rs +++ b/crates/ml-supervised/src/liquid/training.rs @@ -589,7 +589,7 @@ impl Default for CfCTrainerConfig { /// grad(w) ~= (loss(w + eps) - loss(w - eps)) / (2 * eps) /// /// This is computationally expensive but correct for training small -/// CfC networks on GPU without a tape-based AD system. +/// `CfC` networks on GPU without a tape-based AD system. #[allow(missing_debug_implementations)] pub struct CandleCfCTrainer { network: TrainerCfCNetwork, @@ -620,9 +620,9 @@ impl CandleCfCTrainer { /// Train one epoch over the given data /// - /// Uses forward-mode MSE loss since GpuTensor lacks autograd. + /// Uses forward-mode MSE loss since `GpuTensor` lacks autograd. /// Weight updates use a simple perturbation-based gradient estimate - /// on the output layer only (sufficient for small CfC nets). + /// on the output layer only (sufficient for small `CfC` nets). pub fn train_epoch( &mut self, data: &[(GpuTensor, GpuTensor)], @@ -665,10 +665,10 @@ impl CandleCfCTrainer { /// Perturbation-based gradient update for the output linear layer. /// /// For each weight w in the output layer: - /// w += eps -> compute loss_plus - /// w -= 2*eps -> compute loss_minus - /// grad = (loss_plus - loss_minus) / (2*eps) - /// w_new = w_original - lr * grad + /// `w += eps` -> compute `loss_plus` + /// `w -= 2*eps` -> compute `loss_minus` + /// `grad = (loss_plus - loss_minus) / (2*eps)` + /// `w_new = w_original - lr * grad` fn perturb_update_linear_layer( &mut self, input: &GpuTensor, diff --git a/crates/ml-supervised/src/mamba/mod.rs b/crates/ml-supervised/src/mamba/mod.rs index 27bbd133c..698d79002 100644 --- a/crates/ml-supervised/src/mamba/mod.rs +++ b/crates/ml-supervised/src/mamba/mod.rs @@ -434,7 +434,7 @@ pub struct TrainingEpoch { /// CUDA-compatible `LayerNorm` wrapper for MAMBA-2 /// -/// Uses `gpu_layer_norm` from the local gpu_tensor module. +/// Uses `gpu_layer_norm` from the local `gpu_tensor` module. #[derive(Debug, Clone)] pub struct CudaLayerNorm { weight: GpuTensor, @@ -509,7 +509,7 @@ impl std::fmt::Debug for Mamba2SSM { } impl Mamba2SSM { - /// Create a scalar 1-element GpuTensor from an f64 value. + /// Create a scalar 1-element `GpuTensor` from an f64 value. #[allow(dead_code)] fn scalar_tensor(value: f64, stream: &Arc) -> Result { GpuTensor::from_vec(vec![value as f32], &[1], stream) @@ -771,7 +771,7 @@ impl Mamba2SSM { let ss_flat = scanned_states.reshape(&[flat_rows, flat_cols])?; let output_flat = gpu_matmul(&ss_flat, &C_t)?; let out_cols = output_flat.dim(1)?; - let mut out_shape = ss_shape.clone(); + let mut out_shape = ss_shape; if let Some(last) = out_shape.last_mut() { *last = out_cols; } @@ -1555,7 +1555,7 @@ impl Mamba2SSM { /// Selective scan algorithm with gradient computation (GPU-native) /// - /// Computes: state_t = state_{t-1} @ A^T + x_t for each timestep. + /// Computes: `state_t = state_{t-1} @ A^T + x_t` for each timestep. /// All matmul and add ops stay on GPU -- zero host downloads. /// /// Mathematical notation: Parameter A represents the state transition matrix @@ -1687,7 +1687,7 @@ impl Mamba2SSM { Ok(Bu) } - /// Compute training loss (MSE). Returns a 1-element GpuTensor. + /// Compute training loss (MSE). Returns a 1-element `GpuTensor`. pub fn compute_loss(&self, output: &GpuTensor, target: &GpuTensor) -> Result { // Mean Squared Error for regression let diff = gpu_sub(output, target)?; @@ -2021,9 +2021,6 @@ impl Mamba2SSM { // Disable dropout for validation for (input, target) in val_data { - // FIXED: Ensure input and target tensors are on the model's device (GPU) - let input = input; - let target = target; let output = self.forward(input)?; let loss = self.compute_loss(&output, target)?; @@ -2189,7 +2186,8 @@ impl Mamba2SSM { /// but discarded the clipped results. Trainable parameter gradients are /// handled by the optimizer step. #[allow(clippy::unnecessary_wraps)] - fn clip_gradients(&mut self, _max_norm: f64) -> Result<(), MLError> { + const fn clip_gradients(&mut self, max_norm: f64) -> Result<(), MLError> { + let _ = max_norm; Ok(()) } diff --git a/crates/ml-supervised/src/mamba/ssd_layer.rs b/crates/ml-supervised/src/mamba/ssd_layer.rs index 468fa108f..55d4fa402 100644 --- a/crates/ml-supervised/src/mamba/ssd_layer.rs +++ b/crates/ml-supervised/src/mamba/ssd_layer.rs @@ -192,7 +192,7 @@ impl SSDLayer { /// State space transformation with proper discretization /// - /// Implements the SSM recurrence: h[t+1] = A_bar * h[t] + B_bar * x[t], y[t] = C * h[t] + /// Implements the SSM recurrence: `h[t+1] = A_bar * h[t] + B_bar * x[t]`, `y[t] = C * h[t]` fn state_space_transform( &mut self, input: &GpuTensor, diff --git a/crates/ml-supervised/src/tft/mod.rs b/crates/ml-supervised/src/tft/mod.rs index 977d3a944..4737ae741 100644 --- a/crates/ml-supervised/src/tft/mod.rs +++ b/crates/ml-supervised/src/tft/mod.rs @@ -404,7 +404,7 @@ impl TemporalFusionTransformer { } /// Get reference to the model's CUDA stream - pub fn stream(&self) -> &Arc { + pub const fn stream(&self) -> &Arc { &self.cuda_stream } @@ -490,7 +490,7 @@ impl TemporalFusionTransformer { /// * `static_features` - Static input features [batch, `num_static_features`] /// * `historical_features` - Historical features [batch, `seq_len`, `num_unknown_features`] /// * `future_features` - Future features [batch, horizon, `num_known_features`] - /// * `_use_checkpointing` - Unused (no autograd in GpuTensor) + /// * `_use_checkpointing` - Unused (no autograd in `GpuTensor`) #[instrument(skip(self, static_features, historical_features, future_features))] #[allow(clippy::cognitive_complexity)] pub fn forward_with_checkpointing( @@ -498,8 +498,9 @@ impl TemporalFusionTransformer { static_features: &GpuTensor, historical_features: &GpuTensor, future_features: &GpuTensor, - _use_checkpointing: bool, + use_checkpointing: bool, ) -> Result { + let _ = use_checkpointing; let start_time = Instant::now(); // Validate input dimensions @@ -560,7 +561,7 @@ impl TemporalFusionTransformer { let attended = self.temporal_attention.forward_with_checkpointing( &combined_temporal, true, - _use_checkpointing, + use_checkpointing, )?; // 6. Apply static context (skip if no static features) @@ -786,7 +787,7 @@ impl TemporalFusionTransformer { /// Training interface with loss-based optimization (no autograd) /// - /// Uses direct forward passes with MSE loss since GpuTensor lacks autograd. + /// Uses direct forward passes with MSE loss since `GpuTensor` lacks autograd. /// The quantile output layer weights are updated via perturbation-based gradients. #[allow(clippy::cognitive_complexity)] pub async fn train( diff --git a/crates/ml-supervised/src/tft/temporal_attention.rs b/crates/ml-supervised/src/tft/temporal_attention.rs index c9e295043..1625a1438 100644 --- a/crates/ml-supervised/src/tft/temporal_attention.rs +++ b/crates/ml-supervised/src/tft/temporal_attention.rs @@ -87,8 +87,8 @@ impl Default for AttentionConfig { /// Multi-head temporal self-attention /// -/// Uses GpuLinear for Q/K/V projections and output projection. -/// Positional encoding is generated on the fly and stored as GpuTensor. +/// Uses `GpuLinear` for Q/K/V projections and output projection. +/// Positional encoding is generated on the fly and stored as `GpuTensor`. #[derive(Debug)] pub struct TemporalSelfAttention { pub config: AttentionConfig, @@ -145,17 +145,18 @@ impl TemporalSelfAttention { } #[instrument(skip(self, x))] - pub fn forward(&self, x: &GpuTensor, _causal_mask: bool) -> Result { - self.forward_with_checkpointing(x, _causal_mask, false) + pub fn forward(&self, x: &GpuTensor, causal_mask: bool) -> Result { + self.forward_with_checkpointing(x, causal_mask, false) } #[instrument(skip(self, x))] pub fn forward_with_checkpointing( &self, x: &GpuTensor, - _causal_mask: bool, - _use_checkpointing: bool, + causal_mask: bool, + use_checkpointing: bool, ) -> Result { + let _ = (causal_mask, use_checkpointing); // x shape: [batch, seq_len, hidden_dim] or [batch, hidden_dim] // For simplicity, if 3D flatten to 2D, process, reshape back if x.shape.len() == 3 { @@ -171,7 +172,7 @@ impl TemporalSelfAttention { } } - /// Core 2D attention forward: [N, hidden_dim] -> [N, hidden_dim] + /// Core 2D attention forward: `[N, hidden_dim]` -> `[N, hidden_dim]` fn forward_2d(&self, x: &GpuTensor) -> Result { let _n = x.dim(0)?; let _hidden_dim = x.dim(1)?;