Utilities
TorchApprox Helper functions
get_approx_modules(net)
Retrieve all approximate layers from a model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
net |
Module
|
PyTorch neural network model |
required |
Returns:
Type | Description |
---|---|
List[Tuple[str, ApproxLayer]]
|
A list of tuples with name and reference to each Approximate layer instance in the model |
Source code in src/torchapprox/utils/conversion.py
wrap_quantizable(net, wrappable_layers=None, qconfig=None)
Performs in-place upgrade of layers in a vanilla PyTorch network to TorchApprox approximate layer implementations. Regular insertion of quant/dequant stubs does not work because the activation quantization parameters are required inside the quantized layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
net |
Module
|
PyTorch neural network model |
required |
wrappable_layers |
Optional[List[ApproxLayer]]
|
Layer types to be wrapped |
None
|
Returns:
Type | Description |
---|---|
Module
|
An identical model with target layers replaced by Approximate Layer implementations |