Concrete ML
WebsiteLibrariesProducts & ServicesDevelopersSupport
0.6
0.6
  • What is Concrete ML?
  • Getting Started
    • Installation
    • Key Concepts
    • Inference in the Cloud
    • Demos and Tutorials
  • Built-in Models
    • Linear Models
    • Tree-based Models
    • Neural Networks
    • Pandas
    • Built-in Model Examples
  • Deep Learning
    • Using Torch
    • Using ONNX
    • Step-by-step Guide
    • Deep Learning Examples
    • Debugging Models
  • Advanced topics
    • Quantization
    • Pruning
    • Compilation
    • Production Deployment
    • Advanced Features
  • Developer Guide
    • Workflow
      • Set Up the Project
      • Set Up Docker
      • Documentation
      • Support and Issues
      • Contributing
    • Inner Workings
      • Importing ONNX
      • Quantization Tools
      • FHE Op-graph Design
      • External Libraries
    • API
      • concrete.ml.common.check_inputs.md
      • concrete.ml.common.debugging.custom_assert.md
      • concrete.ml.common.debugging.md
      • concrete.ml.common.md
      • concrete.ml.common.utils.md
      • concrete.ml.deployment.fhe_client_server.md
      • concrete.ml.deployment.md
      • concrete.ml.onnx.convert.md
      • concrete.ml.onnx.md
      • concrete.ml.onnx.onnx_impl_utils.md
      • concrete.ml.onnx.onnx_model_manipulations.md
      • concrete.ml.onnx.onnx_utils.md
      • concrete.ml.onnx.ops_impl.md
      • concrete.ml.pytest.md
      • concrete.ml.pytest.torch_models.md
      • concrete.ml.pytest.utils.md
      • concrete.ml.quantization.base_quantized_op.md
      • concrete.ml.quantization.md
      • concrete.ml.quantization.post_training.md
      • concrete.ml.quantization.quantized_module.md
      • concrete.ml.quantization.quantized_ops.md
      • concrete.ml.quantization.quantizers.md
      • concrete.ml.sklearn.base.md
      • concrete.ml.sklearn.glm.md
      • concrete.ml.sklearn.linear_model.md
      • concrete.ml.sklearn.md
      • concrete.ml.sklearn.protocols.md
      • concrete.ml.sklearn.qnn.md
      • concrete.ml.sklearn.rf.md
      • concrete.ml.sklearn.svm.md
      • concrete.ml.sklearn.torch_modules.md
      • concrete.ml.sklearn.tree.md
      • concrete.ml.sklearn.tree_to_numpy.md
      • concrete.ml.sklearn.xgb.md
      • concrete.ml.torch.compile.md
      • concrete.ml.torch.md
      • concrete.ml.torch.numpy_module.md
      • concrete.ml.version.md
Powered by GitBook

Libraries

  • TFHE-rs
  • Concrete
  • Concrete ML
  • fhEVM

Developers

  • Blog
  • Documentation
  • Github
  • FHE resources

Company

  • About
  • Introduction to FHE
  • Media
  • Careers
On this page
  • module concrete.ml.pytest.torch_models
  • class FCSmall
  • class FC
  • class CNN
  • class CNNMaxPool
  • class CNNOther
  • class CNNInvalid
  • class CNNGrouped
  • class NetWithLoops
  • class MultiInputNN
  • class BranchingModule
  • class BranchingGemmModule
  • class UnivariateModule
  • class StepActivationModule
  • class NetWithConcatUnsqueeze
  • class MultiOpOnSingleInputConvNN
  • class FCSeq
  • class FCSeqAddBiasVec
  • class TinyCNN
  • class TinyQATCNN
  • class SimpleQAT
  • class QATTestModule
  • class SingleMixNet
  • class TorchSum
  • class TorchSumMod

Was this helpful?

Export as PDF
  1. Developer Guide
  2. API

concrete.ml.pytest.torch_models.md

Previousconcrete.ml.pytest.mdNextconcrete.ml.pytest.utils.md

Last updated 2 years ago

Was this helpful?

module concrete.ml.pytest.torch_models

Torch modules for our pytests.


class FCSmall

Torch model for the tests.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class FC

Torch model for the tests.

method __init__

__init__(activation_function, input_output=3072)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class CNN

Torch CNN model for the tests.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class CNNMaxPool

Torch CNN model for the tests with a max pool.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class CNNOther

Torch CNN model for the tests.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class CNNInvalid

Torch CNN model for the tests.

method __init__

__init__(activation_function, padding, groups, gather_slice)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class CNNGrouped

Torch CNN model with grouped convolution for compile torch tests.

method __init__

__init__(input_output, activation_function, groups)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class NetWithLoops

Torch 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__(activation_function, input_output, n_fc_layers)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class MultiInputNN

Torch model to test multiple inputs forward.

method __init__

__init__(input_output, activation_function)

method forward

forward(x, y)

Forward pass.

Args:

  • x: the first input of the NN

  • y: the second input of the NN

Returns: the output of the NN


class BranchingModule

Torch model with some branching and skip connections.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class BranchingGemmModule

Torch model with some branching and skip connections.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class UnivariateModule

Torch model that calls univariate and shape functions of torch.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class StepActivationModule

Torch model implements a step function that needs Greater, Cast and Where.

method __init__

__init__(input_output, activation_function)

method forward

forward(x)

Forward pass with a quantizer built into the computation graph.

Args:

  • x: the input of the NN

Returns: the output of the NN


class NetWithConcatUnsqueeze

Torch model to test the concat and unsqueeze operators.

method __init__

__init__(activation_function, input_output, n_fc_layers)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class MultiOpOnSingleInputConvNN

Network that applies two quantized operations on a single input.

method __init__

__init__()

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class FCSeq

Torch model that should generate MatMul->Add ONNX patterns.

This network generates additions with a constant scalar

method __init__

__init__(input_output, act)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class FCSeqAddBiasVec

Torch model that should generate MatMul->Add ONNX patterns.

This network tests the addition with a constant vector

method __init__

__init__(input_output, act)

method forward

forward(x)

Forward pass.

Args:

  • x: the input of the NN

Returns: the output of the NN


class TinyCNN

A very small CNN.

method __init__

__init__(n_classes, act) → None

Create the tiny CNN with two conv layers.

Args:

  • n_classes: number of classes

  • act: the activation


method forward

forward(x)

Forward the two layers with the chosen activation function.

Args:

  • x: the input of the NN

Returns: the output of the NN


class TinyQATCNN

A very small QAT CNN to classify the sklearn digits dataset.

This class also allows pruning to a maximum of 10 active neurons, which should help keep the accumulator bit-width low.

method __init__

__init__(n_classes, n_bits, n_active, signed, narrow) → None

Construct the CNN with a configurable number of classes.

Args:

  • n_classes (int): number of outputs of the neural net

  • n_bits (int): number of weight and activation bits for quantization

  • n_active (int): number of active (non-zero weight) neurons to keep

  • signed (bool): whether quantized integer values are signed

  • narrow (bool): whether the range of quantized integer values is narrow/symmetric


method forward

forward(x)

Run 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_torch(test_loader)

Test 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_pruning(enable)

Enable or remove pruning.

Args:

  • enable: if we enable the pruning or not


class SimpleQAT

Torch model implements a step function that needs Greater, Cast and Where.

method __init__

__init__(input_output, activation_function, n_bits=2, disable_bit_check=False)

method forward

forward(x)

Forward pass with a quantizer built into the computation graph.

Args:

  • x: the input of the NN

Returns: the output of the NN


class QATTestModule

Torch model that implements a simple non-uniform quantizer.

method __init__

__init__(activation_function)

method forward

forward(x)

Forward pass with a quantizer built into the computation graph.

Args:

  • x: the input of the NN

Returns: the output of the NN


class SingleMixNet

Torch model that with a single conv layer that produces the output, e.g. a blur filter.

method __init__

__init__(use_conv, use_qat, inp_size, n_bits)

method forward

forward(x)

Execute the single convolution.

Args:

  • x: the input of the NN

Returns: the output of the NN


class TorchSum

Torch model to test the ReduceSum ONNX operator in a leveled circuit.

method __init__

__init__(dim=(0,), keepdim=True)

Initialize the module.

Args:

  • dim (Tuple[int]): The axis along which the sum should be executed

  • keepdim (bool): If the output should keep the same dimension as the input or not


method forward

forward(x)

Forward 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

Torch model to test the ReduceSum ONNX operator in a circuit containing a PBS.

method __init__

__init__(dim=(0,), keepdim=True)

Initialize the module.

Args:

  • dim (Tuple[int]): The axis along which the sum should be executed

  • keepdim (bool): If the output should keep the same dimension as the input or not


method forward

forward(x)

Forward 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