Pytorch Generator

This module defines the PyTorchGenerator class that generates PyTorch code for neural networks based on the B-UML model.

class besser.generators.nn.pytorch.pytorch_code_generator.PytorchGenerator(model: NN, output_dir: str | None = None, generation_type: str = 'subclassing', channel_last: bool = False)[source]

Bases: NNCodeGenerator

PytorchGenerator is a class that inherits from NNCodeGenerator. It generates Pytorch code for neural networks training and evaluation based on the B-UML input model.

model

An instance of the NN Model class representing the B-UML model.

Type:

NN

setup_layer

The class that defines the syntax of layers.

Type:

SetupLayerSyntax

setup_tensorop

The function that defines the syntax of tensorops.

Type:

Callable

output_dir

The output directory where the generated code will be saved. Defaults to None.

Type:

str, optional

file_name

The name of the file where the generated code is stored.

Type:

str

template_dir

The name of the jinja template directory.

Type:

str

generation_type

‘subclassing’ or ‘sequential’

Type:

str

channel_last

If true, PyTorch conv layers will have their input and output permuted to match TF convention.

Type:

bool, optional

_abc_impl = <_abc._abc_data object>