Skip to content

torchscan.modules

The modules subpackage contains tools for inspecting modules. See Understanding results for counting conventions and Model and input support for the capability matrix.

FLOPs

Related to the number of floating-point operations performed during model inference.

module_flops

module_flops(module: Module | Callable[..., Tensor], inputs: Tuple[Any, ...], out: Any) -> int

Estimate the number of floating point operations performed by the module

Parameters:

Name Type Description Default
module Module | Callable[..., Tensor]

PyTorch module

required
inputs Tuple[Any, ...]

input to the module

required
out Any

output of the module

required

Returns: number of FLOPs

MACs

Related to the number of multiply-accumulate operations performed during model inference.

module_macs

module_macs(module: Module, inp: Tensor, out: Tensor) -> int

Estimate the number of multiply-accumulation operations performed by the module

Parameters:

Name Type Description Default
module Module

PyTorch module

required
inp Tensor

input to the module

required
out Tensor

output of the module

required

Returns: int: number of MACs

DMAs

Related to the number of direct memory accesses during model inference.

module_dmas

module_dmas(module: Module, inp: Tensor, out: Tensor) -> int

Estimate the number of direct memory accesses by the module. The implementation overhead is neglected.

Parameters:

Name Type Description Default
module Module

PyTorch module

required
inp Tensor

input to the module

required
out Tensor

output of the module

required

Returns: int: number of DMAs

Receptive field

Related to the effective receptive field of a layer.

module_rf

module_rf(module: Module, inp: Tensor, out: Tensor) -> Tuple[float, float, float]

Estimate the spatial receptive field of the module

Parameters:

Name Type Description Default
module Module

PyTorch module

required
inp Tensor

input to the module

required
out Tensor

output of the module

required

Returns: receptive field effective stride effective padding