Tensor Operators

condensa.tensor.aggregate(tensor, blocksize, criteria)

Aggregates tensor dimensions according to criteria.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • blocksize (Tuple(int)) – Size of blocks to aggregate

  • criteria (condensa.functional) – Aggregation criteria

Returns

Aggregated tensor

Return type

torch.Tensor

condensa.tensor.aggregate_filters(tensor, criteria)

Aggregates 3D filters in given weight tensor.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • criteria (condensa.functional) – Aggregation criteria

Returns

Filter-aggregated tensor

Return type

torch.Tensor

condensa.tensor.aggregate_neurons(tensor, criteria)

Aggregates neurons (rows) in given weight matrix.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • criteria (condensa.functional) – Aggregation criteria

Returns

Neuron-aggregated tensor

Return type

torch.Tensor

condensa.tensor.apply_mask(tensor, mask)

Computes masked version of tensor.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • mask (torch.Tensor) – Binary mask

Returns

Masked version of tensor

Return type

torch.Tensor

condensa.tensor.apply_mask_inplace(tensor, mask)

Applies binary mask in-place.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • mask (torch.Tensor) – Binary mask

condensa.tensor.block_mask(tensor, threshold, blocksize, criteria, align=None)

Computes an n-D binary mask for given magnitude threshold.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • threshold (float) – magnitude threshold for pruning

  • blocksize (Tuple) – desired block size (Tuple)

  • criteria (condensa.functional) – aggregation function for thresholding (default: max)

Returns

Mask

Return type

torch.Tensor

condensa.tensor.density(tensor)

Computes the ratio of nonzeros to total elements in a tensor.

Parameters

tensor (torch.Tensor) – PyTorch tensor

Returns

Ratio of nonzeros to total elements

Return type

float

condensa.tensor.simple_mask(tensor, threshold, align=None)

Computes a simple binary mask for given magnitude threshold.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • threshold (float) – magnitude threshold for pruning

Returns

Mask

Return type

torch.Tensor

condensa.tensor.sparsity(tensor)

Computes the ratio of zeros to total elements in a tensor.

Parameters

tensor (torch.Tensor) – PyTorch tensor

Returns

Ratio of zeros to total elements

Return type

float

condensa.tensor.threshold(tensor, density)

Computes a magnitude-based threshold for given tensor.

Parameters
  • tensor (torch.Tensor) – PyTorch tensor

  • density (float) – Desired ratio of nonzeros to total elements

Returns

Magnitude threshold

Return type

float