fix(clippy): ZERO errors across entire workspace — CI ready

Final 31 ml crate fixes: unsafe_code allows, unused vars prefixed,
boolean simplification, dead code removal, integer suffix, drop cleanup.

cargo fix auto-removed ~30 unused imports from ml crate.

Total clippy cleanup: 278 errors → 0 across all ML crates.
Full workspace: `cargo clippy --workspace --lib -- -D warnings` = 0 errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-03-19 01:04:09 +01:00
parent 49602a93a6
commit 09c515e3e9
36 changed files with 39 additions and 60 deletions

View File

@@ -13,7 +13,6 @@
use ml_core::cuda_autograd::GpuTensor;
use ml_core::native_types::NativeDevice;
use ml_core::device::MlDevice;
use ml_core::MLError as MlCoreError;
use std::process::Command;
use std::time::{Duration, Instant};
use thiserror::Error;

View File

@@ -486,7 +486,7 @@ impl Mamba2BenchmarkRunner {
let ml_dev = MlDevice::cuda(0)
.map_err(|e| anyhow::anyhow!("CUDA device required: {}", e))?;
let stream = ml_dev.cuda_stream()
let _stream = ml_dev.cuda_stream()
.map_err(|e| anyhow::anyhow!("No CUDA stream: {}", e))?;
for (input, target) in val_data.iter().take(max_samples) {
@@ -530,7 +530,7 @@ impl Mamba2BenchmarkRunner {
let ml_dev = MlDevice::cuda(0)
.map_err(|e| anyhow::anyhow!("CUDA device required: {}", e))?;
let stream = ml_dev.cuda_stream()
let _stream = ml_dev.cuda_stream()
.map_err(|e| anyhow::anyhow!("No CUDA stream: {}", e))?;
for (input, target) in val_data.iter().take(max_samples) {

View File

@@ -1,4 +1,3 @@
use ml_core::MLError;
/// Metrics describing training stability
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, Default)]

View File

@@ -18,7 +18,6 @@ use cudarc::driver::{CudaFunction, CudaSlice, CudaStream, DevicePtr, DevicePtrMu
use ml_core::cuda_autograd::GpuVarStore;
use tracing::{debug, info};
use ml_core::nvtx::NvtxRange;
use crate::MLError;
use super::gpu_curiosity_trainer::GpuCuriosityTrainer;
use super::gpu_weights::{

View File

@@ -19,7 +19,7 @@
use std::sync::Arc;
use cudarc::driver::{CudaSlice, CudaStream, DevicePtr, DeviceRepr, PushKernelArg};
use ml_core::cuda_autograd::{GpuVarStore, GpuParam};
use ml_core::cuda_autograd::GpuVarStore;
use tracing::info;
use crate::MLError;
@@ -1189,7 +1189,7 @@ pub fn extract_rmsnorm_weights(
) -> Result<Option<RmsNormWeightSet>, MLError> {
// Check if the GpuVarStore contains RMSNorm keys (distributional dueling)
if !vars.get(RMSNORM_WEIGHT_NAMES[0]).is_some() {
if vars.get(RMSNORM_WEIGHT_NAMES[0]).is_none() {
return Ok(None);
}
@@ -1219,7 +1219,7 @@ pub fn sync_rmsnorm_weights(
) -> Result<(), MLError> {
// Only sync if the GpuVarStore has RMSNorm keys
if !vars.get(RMSNORM_WEIGHT_NAMES[0]).is_some() {
if vars.get(RMSNORM_WEIGHT_NAMES[0]).is_none() {
return Ok(());
}

View File

@@ -29,7 +29,7 @@
//! ```
use anyhow::{Context, Result};
use ml_core::native_types::{NativeDevice, NativeDType, NativeTensor};
use ml_core::native_types::NativeDevice;
use ml_core::cuda_autograd::GpuTensor;
use data::providers::databento::dbn_parser::{DbnParser, ProcessedMessage};
use dbn::decode::{DbnDecoder, DbnMetadata};

View File

@@ -39,7 +39,7 @@
//! | Streaming| <512MB | ~95% |
use anyhow::{Context, Result};
use ml_core::native_types::{NativeDevice, NativeDType, NativeTensor};
use ml_core::native_types::NativeDevice;
use ml_core::cuda_autograd::GpuTensor;
use data::providers::databento::dbn_parser::{DbnParser, ProcessedMessage};
use dbn::decode::{DbnDecoder, DbnMetadata, DecodeRecordRef};

View File

@@ -29,7 +29,7 @@
//! ```
use anyhow::{Context, Result};
use ml_core::native_types::{NativeDevice, NativeDType, NativeTensor};
use ml_core::native_types::NativeDevice;
use ml_core::cuda_autograd::GpuTensor;
use dbn::decode::{DbnDecoder, DbnMetadata, DecodeRecordRef};
use dbn::RecordRefEnum;

View File

@@ -1,9 +1,9 @@
#![allow(unsafe_code)] // Required for safetensors f32-to-u8 slice reinterpretation
//! UnifiedTrainable trait implementation for DQN model
//!
//! This adapter wraps the DQN implementation to provide a unified
//! training interface compatible with the ML training orchestration system.
use ml_core::device::MlDevice;
use ml_core::native_types::NativeDevice;
use std::collections::HashMap as StdHashMap;
@@ -297,13 +297,13 @@ impl UnifiedTrainable for DQNTrainableAdapter {
raw_bytes.len() / std::mem::size_of::<f32>(),
)
}.to_vec(); // cpu-side bytes→f32 clone
host_data.insert(name.to_string(), (shape, f32_data));
host_data.insert(name.clone(), (shape, f32_data));
}
// Import checkpoint data into the DQN's VarStore via direct CudaSlice writes.
let vars = self.dqn.get_q_network_vars();
let stream = self.dqn.cuda_stream();
for (name, (shape, f32_data)) in &host_data {
for (name, (_shape, f32_data)) in &host_data {
if let Some(param) = vars.get(name) {
if param.data.len() == f32_data.len() {
// Direct HtoD memcpy into the existing CudaSlice

View File

@@ -44,7 +44,7 @@ use std::sync::Arc;
use cudarc::cublas::CudaBlas;
use cudarc::driver::CudaStream;
use ml_core::native_types::{NativeDevice, NativeDType, NativeTensor};
use ml_core::native_types::NativeDevice;
use ml_core::cuda_autograd::GpuTensor;
use serde::{Deserialize, Serialize};

View File

@@ -425,7 +425,7 @@ impl HyperparameterOptimizable for ContinuousPPOTrainer {
};
// Create continuous PPO agent
let mut ppo_agent = ContinuousPPO::new(ppo_config)
let ppo_agent = ContinuousPPO::new(ppo_config)
.map_err(|e| MLError::TrainingError(format!("Failed to create PPO agent: {}", e)))?;
// Training loop (simplified for hyperopt)

View File

@@ -5,7 +5,6 @@
//! optimization of the Diffusion model via the unified framework.
use std::sync::Arc;
use cudarc::driver::CudaStream;
use ml_core::device::MlDevice;
use std::path::PathBuf;
use tracing::{info, warn};

View File

@@ -1885,7 +1885,6 @@ impl DQNTrainer {
&vars, stream,
)?
};
drop(vars);
info!(
is_branching,

View File

@@ -5,7 +5,6 @@
//! hyperparameter optimization of the KAN model via the unified framework.
use std::sync::Arc;
use cudarc::driver::CudaStream;
use ml_core::device::MlDevice;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

View File

@@ -17,7 +17,6 @@
//! | 7 | batch_size | linear | [8, 512] |
use std::sync::Arc;
use cudarc::driver::CudaStream;
use ml_core::device::MlDevice;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

View File

@@ -52,7 +52,6 @@ use crate::ppo::trajectory_replay::TrajectoryReplayBuffer;
use crate::MLError;
use crate::cuda_pipeline::gpu_backtest_evaluator::{GpuBacktestConfig, GpuBacktestEvaluator};
use ml_core::cuda_autograd::GpuTensor;
use cudarc::driver::CudaSlice;
/// Pure model VRAM in MB (actor + critic + optimizers + gradients).
@@ -1600,7 +1599,7 @@ impl PPOTrainer {
composite_reward: &mut Option<CompositeReward>,
gae_gamma: f32,
gae_lambda: f32,
device: &MlDevice,
_device: &MlDevice,
) -> anyhow::Result<TrajectoryBatch> {
use crate::ppo::trajectories::{Trajectory, TrajectoryStep};
use rand::Rng;

View File

@@ -5,7 +5,6 @@
//! hyperparameter optimization of the TGGN model via the unified framework.
use std::sync::Arc;
use cudarc::driver::CudaStream;
use ml_core::device::MlDevice;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

View File

@@ -5,7 +5,6 @@
//! hyperparameter optimization of the TLOB model via the unified framework.
use std::sync::Arc;
use cudarc::driver::CudaStream;
use ml_core::device::MlDevice;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

View File

@@ -5,7 +5,6 @@
//! hyperparameter optimization of the xLSTM model via the unified framework.
use std::sync::Arc;
use cudarc::driver::CudaStream;
use ml_core::device::MlDevice;
use std::path::PathBuf;
use tracing::{info, warn};

View File

@@ -8,7 +8,6 @@
//! The GpuVarStore holds all trainable parameters and the GpuAdamW optimizer
//! runs the update step entirely on GPU.
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::sync::Arc;

View File

@@ -10,10 +10,8 @@ use std::collections::HashMap;
use std::path::Path;
use tracing::info;
use super::gae::compute_gae_single_trajectory;
use super::ppo::{PPOConfig, PPO};
use super::trajectories::{Trajectory, TrajectoryBatch, TrajectoryStep};
use crate::common::action::FactoredAction;
use super::trajectories::TrajectoryBatch;
use crate::training::unified_trainer::{CheckpointMetadata, TrainingMetrics, UnifiedTrainable};
use crate::MLError;

View File

@@ -745,7 +745,7 @@ impl TFTTrainer {
};
let mut abs_diff_sum = 0.0_f64;
let mut count = 0usize;
let mut count = 0_usize;
for (i, &t) in target_host.iter().enumerate() {
// Map target index to prediction index (extract median quantile)
let pred_idx = i * stride + median_idx;

View File

@@ -1,3 +1,4 @@
#![allow(unsafe_code)] // Required for f32<->u32 CudaSlice reinterpret casts and safetensors serialization
//! DQN Configuration and Hyperparameters
//!
//! Contains all training configuration including learning rates,

View File

@@ -7,8 +7,6 @@ use std::path::Path;
use std::sync::Arc;
use anyhow::{Context, Result};
use ml_core::device::MlDevice;
use ml_core::cuda_autograd::GpuTensor;
use tracing::{debug, info, warn};
use crate::features::extraction::OHLCVBar;

View File

@@ -1,3 +1,4 @@
#![allow(unsafe_code)] // Required for f32->u32 CudaSlice reinterpret cast in PER index path
//! Fused CUDA Training Module
//!
//! High-performance H100-optimized training path that replaces 2,100+ Candle kernel
@@ -311,7 +312,7 @@ impl FusedTrainingCtx {
&mut self,
batch: &BatchSample,
agent: &mut DQNAgentType,
device: &MlDevice,
_device: &MlDevice,
) -> Result<GpuTrainResult> {
let gpu_batch = batch.gpu_batch.as_ref()
.ok_or_else(|| anyhow::anyhow!("Fused training requires gpu_batch (GPU PER)"))?;

View File

@@ -435,6 +435,8 @@ impl DQNTrainer {
best_val = v;
} else if v > second_best {
second_best = v;
} else {
// v <= second_best: no update needed
}
}
gaps.push(best_val - second_best);

View File

@@ -1,3 +1,4 @@
#![allow(unsafe_code)] // Required for safetensors f32-to-u8 slice serialization
//! DQN Trainer Implementation
//!
//! Main training loop and execution logic for Deep Q-Network.
@@ -778,7 +779,7 @@ impl DQNTrainer {
})?;
let vars = head.get_q_network_vars();
let vars_data = vars.data();
let ser_stream = vars.stream();
let _ser_stream = vars.stream();
for (name, param) in vars_data.iter() {
if let Ok(tensor) = GpuTensor::new(param.data.clone(), param.shape.clone()) {
all_tensors.insert(

View File

@@ -359,7 +359,7 @@ impl DQNTrainer {
let r_gn_gpu = result.grad_norm_gpu;
// Get vars for accumulation. Var is an Arc wrapper so cloning is cheap.
let vars: Vec<GpuTensor> = agent
let _vars: Vec<GpuTensor> = agent
.optimizer_vars()
.map_err(|e| anyhow::anyhow!("Failed to get optimizer vars: {}", e))?;
@@ -443,7 +443,7 @@ impl DQNTrainer {
// === Phase 2: Average and apply gradients (single optimizer step) ===
if let Some(ref mut grads) = accumulated_grads {
let vars: Vec<GpuTensor> = agent
let _vars: Vec<GpuTensor> = agent
.optimizer_vars()
.map_err(|e| anyhow::anyhow!("Failed to get optimizer vars: {}", e))?;

View File

@@ -1014,7 +1014,7 @@ impl DQNTrainer {
let r_idx_gpu = result.indices_gpu;
let r_grads = result.grads;
let vars = agent.optimizer_vars()
let _vars = agent.optimizer_vars()
.map_err(|e| anyhow::anyhow!("optimizer vars: {e}"))?;
// Accumulate gradients elementwise
match &mut accumulated_grads {
@@ -1075,7 +1075,7 @@ impl DQNTrainer {
// Scale and apply (single optimizer step)
if let Some(ref mut grads) = accumulated_grads {
let vars = agent.optimizer_vars()
let _vars = agent.optimizer_vars()
.map_err(|e| anyhow::anyhow!("optimizer vars: {e}"))?;
// Scale accumulated gradients by 1/N
let stream_ref = self.cuda_stream.as_ref().ok_or_else(|| anyhow::anyhow!("CUDA stream needed"))?;

View File

@@ -14,7 +14,6 @@ use tracing::{debug, info, warn};
use crate::liquid::adapter::LiquidTrainableAdapter;
use crate::liquid::candle_cfc::{CfCTrainConfig, DeviceConfig};
use crate::training::unified_trainer::UnifiedTrainable;
use crate::MLError;
/// Liquid CfC training hyperparameters (maps to gRPC LiquidParams)

View File

@@ -10,7 +10,6 @@ use std::time::{Duration, Instant, SystemTime};
use ml_core::device::MlDevice;
use ml_core::cuda_autograd::GpuTensor;
use ml_core::cuda_autograd::GpuVarStore;
use ml_core::cuda_autograd::stream_ops::StreamTensor;
/// Convert `GpuTensor` -> `StreamTensor` by moving the internal CudaSlice.
@@ -23,7 +22,6 @@ fn gpu_to_stream(t: GpuTensor, stream: &std::sync::Arc<cudarc::driver::CudaStrea
fn stream_to_gpu(t: StreamTensor) -> Result<GpuTensor, crate::MLError> {
GpuTensor::new(t.data, t.shape)
}
use ndarray::Dimension;
use tokio::sync::mpsc;
use tracing::{debug, error, info, instrument, warn};
@@ -256,16 +254,9 @@ impl TFTTrainer {
// The old candle_optimisers::adam::ParamsAdam has been eliminated.
// For now, return an error indicating the optimizer needs migration.
let _lr = self.training_config.learning_rate;
return Err(MLError::ModelError(
Err(MLError::ModelError(
"TFT optimizer not yet migrated from candle_optimisers to GpuAdamW".to_string(),
));
info!(
"Initialized AdamW optimizer with lr={:.2e}",
self.training_config.learning_rate
);
Ok(())
))
}
/// Check if an error is an OOM (Out of Memory) error
@@ -552,7 +543,7 @@ impl TFTTrainer {
}
// Actually drop optimizer to free 1100MB GPU memory
drop(self.optimizer.take());
self.optimizer.take();
if self.device.is_cuda() {
Self::sync_cuda_device(&self.device).ok();
}
@@ -970,7 +961,7 @@ impl TFTTrainer {
/// Implements pinball loss across multiple quantiles:
/// L(y, q_tau) = sum_i max(tau * (y_i - q_tau), (tau - 1) * (y_i - q_tau))
fn compute_quantile_loss(&self, predictions: &GpuTensor, targets: &GpuTensor) -> MLResult<f64> {
use ml_core::cuda_autograd::GpuTensor;
let stream = self.device.cuda_stream().map_err(|e| {
MLError::DeviceError(format!("quantile_loss requires CUDA: {e}"))

View File

@@ -409,7 +409,7 @@ impl TLOBTrainer {
/// `to_scalar()` synchronisation. A single scalar extraction happens
/// after the loop completes, with a NaN guard every 100 batches.
async fn train_epoch(&mut self, sequences: &[OrderBookSequence]) -> Result<f64> {
let stream = self.device.cuda_stream().map_err(|e| {
let stream = self.device.cuda_stream().map_err(|_e| {
anyhow::anyhow!("TLOB train_epoch requires CUDA stream")
})?;
let stream = Arc::clone(stream);
@@ -451,7 +451,7 @@ impl TLOBTrainer {
/// Loss is accumulated on-device to avoid per-batch `to_scalar()`.
/// MAE already returns `f64` (CPU scalar) so it stays as f64 sum.
async fn validate_epoch(&self, sequences: &[OrderBookSequence]) -> Result<(f64, f64)> {
let stream = self.device.cuda_stream().map_err(|e| {
let stream = self.device.cuda_stream().map_err(|_e| {
anyhow::anyhow!("TLOB validate_epoch requires CUDA stream")
})?;
let stream = Arc::clone(stream);
@@ -510,7 +510,7 @@ impl TLOBTrainer {
/// Calculate gradient norm by downloading parameters (monitoring only).
fn calculate_gradient_norm(&self) -> Result<f64> {
// Parameter norm (not gradient norm) — monitors for weight explosion
let stream = self.device.cuda_stream().map_err(|e| {
let stream = self.device.cuda_stream().map_err(|_e| {
anyhow::anyhow!("TLOB requires CUDA stream")
})?;
let mut total_sq = 0.0_f64;

View File

@@ -13,7 +13,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Instant;
use ml_core::native_types::{NativeDevice, NativeDType, NativeTensor};
use ml_core::native_types::NativeDevice;
use ml_core::cuda_autograd::GpuTensor;
use ml_core::cuda_autograd::GpuAdamW;
use serde::{Deserialize, Serialize};

View File

@@ -350,8 +350,9 @@ impl ValidatableStrategy for PpoLstmStrategy {
fn pad_or_truncate(features: &[f32], target_dim: usize) -> Vec<f32> {
let mut result = vec![0.0_f32; target_dim];
let copy_len = features.len().min(target_dim);
result.get_mut(..copy_len)
.map(|dst| dst.copy_from_slice(features.get(..copy_len).unwrap_or_default()));
if let Some(dst) = result.get_mut(..copy_len) {
dst.copy_from_slice(features.get(..copy_len).unwrap_or_default());
}
result
}

View File

@@ -8,7 +8,6 @@
//! device, reading back only 3 mask vectors for the final grouping.
use std::collections::HashMap;
use std::sync::Arc;
use ml_core::cuda_autograd::GpuTensor;
use ml_core::device::MlDevice;

View File

@@ -10,7 +10,7 @@ use std::sync::Arc;
use cudarc::cublas::CudaBlas;
use cudarc::driver::CudaStream;
use ml_core::cuda_autograd::{AdamWConfig, GpuAdamW, GpuLinear, GpuTensor, GpuVarStore, LossKernels};
use ml_core::cuda_autograd::{AdamWConfig, GpuAdamW, GpuTensor, GpuVarStore, LossKernels};
use ml_core::cuda_autograd::stream_ops::StreamTensor;
use super::config::XLSTMConfig;