Features

class sconce.sconce

Bases: quantization, performance, prune

compress(verbose=True) None

Compresses the neural network model using either Granular-Magnitude Pruning (GMP) or Channel-Wise Pruning (CWP). If GMP is used, the sensitivity of each layer is first scanned and then the Fine-Grained Pruning is applied. If CWP is used, the Channel-Wise Pruning is applied directly. After pruning, the model is fine-tuned using Stochastic Gradient Descent (SGD) optimizer with Cosine Annealing Learning Rate Scheduler. The original dense model and the pruned fine-tuned model are saved in separate files. Finally, the validation accuracy and the size of the pruned model are printed.

Args:

verbose (bool): If True, prints the validation accuracy and the size of the pruned model. Default is True.

Returns:

None

evaluate(model=None, device=None, Tqdm=True, verbose=False)

Evaluates the model on the test dataset and returns the accuracy.

Args:

verbose (bool): If True, prints the test accuracy.

Returns:

float: The test accuracy as a percentage.

evaluate_model(model, test_loader, device, criterion=None)
forward_pass_snn(data, mem_out_rec=None)

Perform a forward pass through the spiking neural network (SNN).

Args:

data: Input data for the SNN. mem_out_rec: Optional tensor to record the membrane potential at each time step.

Returns:

If mem_out_rec is not None, returns a tuple containing the spike outputs and membrane potentials as tensors. Otherwise, returns only the spike outputs as a tensor.

train(model=None) None

Trains the model for a specified number of epochs using the specified dataloader and optimizer. If fine-tuning is enabled, the number of epochs is set to num_finetune_epochs. The function also saves the model state after each epoch if the validation accuracy improves. If model is provided, applies supervised Knowledge Distillation (KD) using the provided teacher model.