Skip to main content

unstructured_pruning

Function unstructured_pruning 

Source
pub fn unstructured_pruning<P: AsRef<Path>>(
    input_path: P,
    output_path: P,
    config: &PruningConfig,
) -> Result<PruningStats>
Expand description

Performs unstructured pruning (removes individual weights)

This function loads a model file, extracts weight tensors, applies unstructured pruning based on the configuration, and saves the modified model.

§Arguments

  • input_path - Path to the input model file
  • output_path - Path to save the pruned model
  • config - Pruning configuration

§Returns

Pruning statistics including original/pruned parameter counts and actual sparsity

§Errors

Returns an error if:

  • Input file cannot be read
  • Output file cannot be written
  • Pruning computation fails

§Example

use oxigdal_ml::optimization::pruning::{unstructured_pruning, PruningConfig, PruningStrategy};
use oxigdal_ml::error::Result;

let config = PruningConfig::builder()
    .strategy(PruningStrategy::Magnitude)
    .sparsity_target(0.5)
    .build();

let stats = unstructured_pruning("model.onnx", "model_pruned.onnx", &config)?;
println!("Achieved {:.1}% sparsity", stats.actual_sparsity * 100.0);