fix(clippy): ml-supervised + ml-core + thin crates — 34 errors fixed
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) <noreply@anthropic.com>
This commit is contained in:
@@ -17,7 +17,7 @@ pub struct GPULabelingEngine {
|
||||
|
||||
impl GPULabelingEngine {
|
||||
/// Create new `GPU` labeling engine
|
||||
pub fn new(device: MlDevice) -> Result<Self, LabelingError> {
|
||||
pub const fn new(device: MlDevice) -> Result<Self, LabelingError> {
|
||||
Ok(Self { device })
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<CudaStream>) -> Result<GpuTensor, MLError> {
|
||||
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<GpuTensor, MLError> {
|
||||
// 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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -404,7 +404,7 @@ impl TemporalFusionTransformer {
|
||||
}
|
||||
|
||||
/// Get reference to the model's CUDA stream
|
||||
pub fn stream(&self) -> &Arc<CudaStream> {
|
||||
pub const fn stream(&self) -> &Arc<CudaStream> {
|
||||
&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<GpuTensor, MLError> {
|
||||
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(
|
||||
|
||||
@@ -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<GpuTensor, MLError> {
|
||||
self.forward_with_checkpointing(x, _causal_mask, false)
|
||||
pub fn forward(&self, x: &GpuTensor, causal_mask: bool) -> Result<GpuTensor, MLError> {
|
||||
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<GpuTensor, MLError> {
|
||||
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<GpuTensor, MLError> {
|
||||
let _n = x.dim(0)?;
|
||||
let _hidden_dim = x.dim(1)?;
|
||||
|
||||
Reference in New Issue
Block a user