# concrete.ml.pytest.torch\_models.md

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L0)

## module `concrete.ml.pytest.torch_models`

Torch modules for our pytests.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L16)

### class `SimpleNet`

Fake torch model used to generate some onnx.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L19)

#### method `__init__`

```python
__init__() → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L24)

#### method `forward`

```python
forward(inputs)
```

Forward function.

**Arguments:**

* `inputs`: the inputs of the model.

**Returns:**

* `torch.Tensor`: the result of the computation

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L38)

### class `FCSmall`

Torch model for the tests.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L41)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L47)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L63)

### class `FC`

Torch model for the tests.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L66)

#### method `__init__`

```python
__init__(activation_function, input_output=3072)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L78)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L100)

### class `CNN`

Torch CNN model for the tests.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L103)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L113)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L131)

### class `CNNMaxPool`

Torch CNN model for the tests with a max pool.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L134)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L144)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L162)

### class `CNNOther`

Torch CNN model for the tests.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L165)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L176)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L195)

### class `CNNInvalid`

Torch CNN model for the tests.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L198)

#### method `__init__`

```python
__init__(activation_function, groups)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L214)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L236)

### class `CNNGrouped`

Torch CNN model with grouped convolution for compile torch tests.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L239)

#### method `__init__`

```python
__init__(input_output, activation_function, groups)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L250)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L268)

### 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.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L275)

#### method `__init__`

```python
__init__(activation_function, input_output, n_fc_layers)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L284)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L301)

### class `MultiInputNN`

Torch model to test multiple inputs forward.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L304)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L308)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L321)

### class `MultiInputNNConfigurable`

Torch model to test multiple inputs forward.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L327)

#### method `__init__`

```python
__init__(use_conv, use_qat, input_output, n_bits)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L337)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L352)

### class `MultiInputNNDifferentSize`

Torch model to test multiple inputs with different shape in the forward pass.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L355)

#### method `__init__`

```python
__init__(
    input_output,
    activation_function=None,
    is_brevitas_qat=False,
    n_bits=3
)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L387)

#### method `forward`

```python
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.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L407)

### class `BranchingModule`

Torch model with some branching and skip connections.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L411)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L416)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L428)

### class `BranchingGemmModule`

Torch model with some branching and skip connections.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L431)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L437)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L449)

### class `UnivariateModule`

Torch model that calls univariate and shape functions of torch.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L453)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L458)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L474)

### class `StepActivationModule`

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

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L478)

#### method `__init__`

```python
__init__(input_output, activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L483)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L514)

### class `NetWithConcatUnsqueeze`

Torch model to test the concat and unsqueeze operators.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L517)

#### method `__init__`

```python
__init__(activation_function, input_output, n_fc_layers)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L526)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L545)

### class `MultiOpOnSingleInputConvNN`

Network that applies two quantized operations on a single input.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L548)

#### method `__init__`

```python
__init__(can_remove_input_tlu: bool)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L554)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L574)

### class `FCSeq`

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

This network generates additions with a constant scalar

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L580)

#### method `__init__`

```python
__init__(input_output, act)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L598)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L612)

### class `FCSeqAddBiasVec`

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

This network tests the addition with a constant vector

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L618)

#### method `__init__`

```python
__init__(input_output, act)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L636)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L650)

### class `TinyCNN`

A very small CNN.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L653)

#### method `__init__`

```python
__init__(n_classes, act) → None
```

Create the tiny CNN with two conv layers.

**Args:**

* `n_classes`: number of classes
* `act`: the activation

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L668)

#### method `forward`

```python
forward(x)
```

Forward the two layers with the chosen activation function.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L682)

### class `TinyQATCNN`

A 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.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L689)

#### method `__init__`

```python
__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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L759)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L784)

#### method `test_torch`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L727)

#### method `toggle_pruning`

```python
toggle_pruning(enable)
```

Enable or remove pruning.

**Args:**

* `enable`: if we enable the pruning or not

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L826)

### class `SimpleQAT`

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

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L829)

#### method `__init__`

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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L865)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L909)

### class `QATTestModule`

Torch model that implements a simple non-uniform quantizer.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L912)

#### method `__init__`

```python
__init__(activation_function)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L917)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L947)

### class `SingleMixNet`

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

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L952)

#### method `__init__`

```python
__init__(use_conv, use_qat, inp_size, n_bits)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L984)

#### method `forward`

```python
forward(x)
```

Execute the single convolution.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L997)

### class `DoubleQuantQATMixNet`

Torch model that with two different quantizers on the input.

Used to test that it keeps the input TLU.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1003)

#### method `__init__`

```python
__init__(use_conv, use_qat, inp_size, n_bits)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1021)

#### method `forward`

```python
forward(x)
```

Execute the single convolution.

**Args:**

* `x`: the input of the NN

**Returns:** the output of the NN

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1036)

### class `TorchSum`

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

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1039)

#### method `__init__`

```python
__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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1055)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1068)

### class `TorchSumMod`

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

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1039)

#### method `__init__`

```python
__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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1071)

#### method `forward`

```python
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

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1088)

### class `NetWithConstantsFoldedBeforeOps`

Torch QAT model that does not quantize the inputs.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1091)

#### method `__init__`

```python
__init__(
    hparams: dict,
    bits: int,
    act_quant=<class 'brevitas.quant.scaled_int.Int8ActPerTensorFloat'>,
    weight_quant=<class 'brevitas.quant.scaled_int.Int8WeightPerTensorFloat'>
)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1118)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model

**Returns:**

* `torch.tensor`: Output of the network

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1137)

### class `ShapeOperationsNet`

Torch QAT model that reshapes the input.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1140)

#### method `__init__`

```python
__init__(is_qat)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1146)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model

**Returns:**

* `torch.tensor`: Output of the network

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1186)

### class `PaddingNet`

Torch QAT model that applies various padding patterns.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1189)

#### method `__init__`

```python
__init__()
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1195)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model

**Returns:**

* `torch.tensor`: Output of the network

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1223)

### class `QNNFashionMNIST`

A small quantized network with Brevitas for FashionMNIST classification.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1269)

#### method `__init__`

```python
__init__(
    n_bits,
    quant_weight=<class 'brevitas.quant.scaled_int.Int8WeightPerTensorFloat'>,
    act_quant=<class 'brevitas.quant.scaled_int.Int8ActPerTensorFloat'>
)
```

Quantized Torch Model with Brevitas.

**Args:**

* `n_bits` (int): Bit of quantization
* `quant_weight` (brevitas.quant): Quantization protocol of weights
* `act_quant` (brevitas.quant): Quantization protocol of activations.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1328)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model.

**Returns:**

* `torch.tensor`: Output of the network.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1342)

### class `QuantCustomModel`

A small quantized network with Brevitas, trained on make\_classification.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1345)

#### method `__init__`

```python
__init__(
    input_shape: int,
    output_shape: int,
    hidden_shape: int = 100,
    n_bits: int = 5,
    act_quant=<class 'brevitas.quant.scaled_int.Int8ActPerTensorFloat'>,
    weight_quant=<class 'brevitas.quant.scaled_int.Int8WeightPerTensorFloat'>
)
```

Quantized Torch Model with Brevitas.

**Args:**

* `input_shape` (int): Input size
* `output_shape` (int): Output size
* `hidden_shape` (int): Hidden size
* `n_bits` (int): Bit of quantization
* `weight_quant` (brevitas.quant): Quantization protocol of weights
* `act_quant` (brevitas.quant): Quantization protocol of activations.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1400)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model.

**Returns:**

* `torch.tensor`: Output of the network.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1418)

### class `TorchCustomModel`

A small network with Brevitas, trained on make\_classification.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1421)

#### method `__init__`

```python
__init__(input_shape, hidden_shape, output_shape)
```

Torch Model.

**Args:**

* `input_shape` (int): Input size
* `output_shape` (int): Output size
* `hidden_shape` (int): Hidden size

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1434)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model.

**Returns:**

* `torch.tensor`: Output of the network.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1449)

### class `ConcatFancyIndexing`

Concat with fancy indexing.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1452)

#### method `__init__`

```python
__init__(
    input_shape,
    hidden_shape,
    output_shape,
    n_bits: int = 4,
    n_blocks: int = 3
) → None
```

Torch Model.

**Args:**

* `input_shape` (int): Input size
* `output_shape` (int): Output size
* `hidden_shape` (int): Hidden size
* `n_bits` (int): Number of bits
* `n_blocks` (int): Number of blocks

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/pytest/torch_models.py#L1480)

#### method `forward`

```python
forward(x)
```

Forward pass.

**Args:**

* `x` (torch.tensor): The input of the model.

**Returns:**

* `torch.tensor`: Output of the network.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zama.org/concrete-ml/1.1/developer-guide/api/concrete.ml.pytest.torch_models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
