concrete.ml.pytest.torch_models.md
module concrete.ml.pytest.torch_models
concrete.ml.pytest.torch_modelsTorch modules for our pytests.
class SimpleNet
SimpleNetFake torch model used to generate some onnx.
method __init__
__init____init__() → Nonemethod forward
forwardforward(inputs)Forward function.
Arguments:
inputs: the inputs of the model.
Returns:
torch.Tensor: the result of the computation
class FCSmall
FCSmallTorch model for the tests.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class FC
FCTorch model for the tests.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class CNN
CNNTorch CNN model for the tests.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class CNNMaxPool
CNNMaxPoolTorch CNN model for the tests with a max pool.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class CNNOther
CNNOtherTorch CNN model for the tests.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class CNNInvalid
CNNInvalidTorch CNN model for the tests.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class CNNGrouped
CNNGroupedTorch CNN model with grouped convolution for compile torch tests.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class NetWithLoops
NetWithLoopsTorch model, where we reuse some elements in a loop.
Torch model, where we reuse some elements in a loop in the forward and don't expect the user to define these elements in a particular order.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class MultiInputNN
MultiInputNNTorch model to test multiple inputs forward.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the first input of the NNy: the second input of the NN
Returns: the output of the NN
class MultiInputNNConfigurable
MultiInputNNConfigurableTorch model to test multiple inputs forward.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the first input of the NNy: the second input of the NN
Returns: the output of the NN
class MultiInputNNDifferentSize
MultiInputNNDifferentSizeTorch model to test multiple inputs with different shape in the forward pass.
method __init__
__init__method forward
forwardForward pass.
Args:
x: The first input of the NN.y: The second input of the NN.
Returns: The output of the NN.
class BranchingModule
BranchingModuleTorch model with some branching and skip connections.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class BranchingGemmModule
BranchingGemmModuleTorch model with some branching and skip connections.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class UnivariateModule
UnivariateModuleTorch model that calls univariate and shape functions of torch.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class StepActivationModule
StepActivationModuleTorch model implements a step function that needs Greater, Cast and Where.
method __init__
__init__method forward
forwardForward pass with a quantizer built into the computation graph.
Args:
x: the input of the NN
Returns: the output of the NN
class NetWithConcatUnsqueeze
NetWithConcatUnsqueezeTorch model to test the concat and unsqueeze operators.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class MultiOpOnSingleInputConvNN
MultiOpOnSingleInputConvNNNetwork that applies two quantized operations on a single input.
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class FCSeq
FCSeqTorch model that should generate MatMul->Add ONNX patterns.
This network generates additions with a constant scalar
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class FCSeqAddBiasVec
FCSeqAddBiasVecTorch model that should generate MatMul->Add ONNX patterns.
This network tests the addition with a constant vector
method __init__
__init__method forward
forwardForward pass.
Args:
x: the input of the NN
Returns: the output of the NN
class TinyCNN
TinyCNNA very small CNN.
method __init__
__init__Create the tiny CNN with two conv layers.
Args:
n_classes: number of classesact: the activation
method forward
forwardForward the two layers with the chosen activation function.
Args:
x: the input of the NN
Returns: the output of the NN
class TinyQATCNN
TinyQATCNNA very small QAT CNN to classify the sklearn digits data-set.
This class also allows pruning to a maximum of 10 active neurons, which should help keep the accumulator bit-width low.
method __init__
__init__Construct the CNN with a configurable number of classes.
Args:
n_classes(int): number of outputs of the neural netn_bits(int): number of weight and activation bits for quantizationn_active(int): number of active (non-zero weight) neurons to keepsigned(bool): whether quantized integer values are signednarrow(bool): whether the range of quantized integer values is narrow/symmetric
method forward
forwardRun inference on the tiny CNN, apply the decision layer on the reshaped conv output.
Args:
x: the input to the NN
Returns: the output of the NN
method test_torch
test_torchTest the network: measure accuracy on the test set.
Args:
test_loader: the test loader
Returns:
res: the number of correctly classified test examples
method toggle_pruning
toggle_pruningEnable or remove pruning.
Args:
enable: if we enable the pruning or not
class SimpleQAT
SimpleQATTorch model implements a step function that needs Greater, Cast and Where.
method __init__
__init__method forward
forwardForward pass with a quantizer built into the computation graph.
Args:
x: the input of the NN
Returns: the output of the NN
class QATTestModule
QATTestModuleTorch model that implements a simple non-uniform quantizer.
method __init__
__init__method forward
forwardForward pass with a quantizer built into the computation graph.
Args:
x: the input of the NN
Returns: the output of the NN
class SingleMixNet
SingleMixNetTorch model that with a single conv layer that produces the output, e.g., a blur filter.
method __init__
__init__method forward
forwardExecute the single convolution.
Args:
x: the input of the NN
Returns: the output of the NN
class DoubleQuantQATMixNet
DoubleQuantQATMixNetTorch model that with two different quantizers on the input.
Used to test that it keeps the input TLU.
method __init__
__init__method forward
forwardExecute the single convolution.
Args:
x: the input of the NN
Returns: the output of the NN
class TorchSum
TorchSumTorch model to test the ReduceSum ONNX operator in a leveled circuit.
method __init__
__init__Initialize the module.
Args:
dim(Tuple[int]): The axis along which the sum should be executedkeepdim(bool): If the output should keep the same dimension as the input or not
method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model
Returns:
torch_sum(torch.tensor): The sum of the input's tensor elements along the given axis
class TorchSumMod
TorchSumModTorch model to test the ReduceSum ONNX operator in a circuit containing a PBS.
method __init__
__init__Initialize the module.
Args:
dim(Tuple[int]): The axis along which the sum should be executedkeepdim(bool): If the output should keep the same dimension as the input or not
method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model
Returns:
torch_sum(torch.tensor): The sum of the input's tensor elements along the given axis
class NetWithConstantsFoldedBeforeOps
NetWithConstantsFoldedBeforeOpsTorch QAT model that does not quantize the inputs.
method __init__
__init__method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model
Returns:
torch.tensor: Output of the network
class ShapeOperationsNet
ShapeOperationsNetTorch QAT model that reshapes the input.
method __init__
__init__method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model
Returns:
torch.tensor: Output of the network
class PaddingNet
PaddingNetTorch QAT model that applies various padding patterns.
method __init__
__init__method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model
Returns:
torch.tensor: Output of the network
class QNNFashionMNIST
QNNFashionMNISTA small quantized network with Brevitas for FashionMNIST classification.
method __init__
__init__Quantized Torch Model with Brevitas.
Args:
n_bits(int): Bit of quantizationquant_weight(brevitas.quant): Quantization protocol of weightsact_quant(brevitas.quant): Quantization protocol of activations.
method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model.
Returns:
torch.tensor: Output of the network.
class QuantCustomModel
QuantCustomModelA small quantized network with Brevitas, trained on make_classification.
method __init__
__init__Quantized Torch Model with Brevitas.
Args:
input_shape(int): Input sizeoutput_shape(int): Output sizehidden_shape(int): Hidden sizen_bits(int): Bit of quantizationweight_quant(brevitas.quant): Quantization protocol of weightsact_quant(brevitas.quant): Quantization protocol of activations.
method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model.
Returns:
torch.tensor: Output of the network.
class TorchCustomModel
TorchCustomModelA small network with Brevitas, trained on make_classification.
method __init__
__init__Torch Model.
Args:
input_shape(int): Input sizeoutput_shape(int): Output sizehidden_shape(int): Hidden size
method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model.
Returns:
torch.tensor: Output of the network.
class ConcatFancyIndexing
ConcatFancyIndexingConcat with fancy indexing.
method __init__
__init__Torch Model.
Args:
input_shape(int): Input sizeoutput_shape(int): Output sizehidden_shape(int): Hidden sizen_bits(int): Number of bitsn_blocks(int): Number of blocks
method forward
forwardForward pass.
Args:
x(torch.tensor): The input of the model.
Returns:
torch.tensor: Output of the network.
Last updated
Was this helpful?