hxtorch.perceptron
Modules
This module contains layers that can be used in modules together with the building blocks from py:mod:torch.nn. |
Classes
Inference tracer for a linear sequence of operations. |
|
Parameter of hardware mock. |
Functions
-
hxtorch.perceptron.
add
(input: torch.Tensor, other: torch.Tensor, alpha: float = 1, mock: bool = False) → torch.Tensor Elementwise addition operating on int8 value range.
@param input Input tensor @param other Other tensor, which must be broadcastable to input tensor dimension @param alpha The scalar multiplier for other @param mock Enable mock mode
-
hxtorch.perceptron.
argmax
(input: torch.Tensor, dim: Optional[int] = None, keepdim: bool = False, mock: bool = False) → torch.Tensor Arg max operation on int8 value range.
@param input The input tensor @param dim The dimension to reduce. If unspecified, the argmax of the flattened
input is returned.
- @param keepdim Whether the output tensor has @p dim retained or not. Ignored
if @p dim is unspecified.
@param mock Enable mock mode
@return The indices of the maximum values of a tensor across a dimension
-
hxtorch.perceptron.
conv1d
(*args, **kwargs) Overloaded function.
conv1d(input: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: int = 1, num_sends: int = 1, wait_between_events: int = 5, mock: bool = False) -> torch.Tensor
conv1d(input: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: List[int[1]], num_sends: int = 1, wait_between_events: int = 5, mock: bool = False) -> torch.Tensor
-
hxtorch.perceptron.
conv2d
(*args, **kwargs) Overloaded function.
conv2d(input: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: int = 1, num_sends: int = 1, wait_between_events: int = 5, mock: bool = False) -> torch.Tensor
conv2d(input: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: List[int[2]], num_sends: int = 1, wait_between_events: int = 5, mock: bool = False) -> torch.Tensor
-
hxtorch.perceptron.
converting_relu
(input: torch.Tensor, shift: int = 2, mock: bool = False) → torch.Tensor Rectified linear unit operating on int8 value range converting to uint5 value range. The result is bit-shifted by @p shift after applying the ReLU and clipped to the input range of BrainScaleS-2.
@param input Input tensor @param shift Amount of bits to shift before clipping @param mock Enable mock mode
-
hxtorch.perceptron.
expanded_conv1d
(*args, **kwargs) Overloaded function.
expanded_conv1d(input: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: int = 1, num_expansions: int = 1, num_sends: int = 1, wait_between_events: int = 5, mock: bool = False) -> torch.Tensor
1D convolution operation that unrolls the weight matrix for execution on hardware. This maximizes the use of the synapses array.
@note Fixed-pattern noise cannot be individually compensated for during training, because the same weights are used at different locations!
@param input Input tensor of shape (minibatch, in_channels, iW) @param weight Filters of shape (out_channels, in_channels / groups, kW) @param bias Optional bias of shape (out_channels) @param stride Stride of the convolving kernel @param num_expansions Number of enrolled kernels that will be placed side
by side in a single operation
@param num_sends How often to send the (same) input vector @param wait_between_events How long to wait (in FPGA cycles) between events @param mock Enable mock mode
expanded_conv1d(input: torch.Tensor, weight: torch.Tensor, bias: Optional[torch.Tensor] = None, stride: List[int[1]], num_expansions: int = 1, num_sends: int = 1, wait_between_events: int = 5, mock: bool = False) -> torch.Tensor
-
hxtorch.perceptron.
get_mock_parameter
() → hxtorch::perceptron::MockParameter Returns the current mock parameters.
-
hxtorch.perceptron.
inference_trace
(input: torch.Tensor, filename: str) → torch.Tensor Execute inference of stored trace.
@param input Input data to use @param filename Filename to serialized operation trace
-
hxtorch.perceptron.
mac
(x: torch.Tensor, weights: torch.Tensor, num_sends: int = 1, wait_between_events: int = 5, mock: bool = False, madc_recording_neuron_id: int = 0, madc_recording_path: str = '') → torch.Tensor The bare mutliply-accumulate operation of BrainScaleS-2. A 1D input @p x is multiplied by the weight matrix @p weights. If @p x is two-dimensional, the weights are sent only once to the synapse array and the inputs are consecutively multiplied as a 1D vector.
@param x Input tensor @param weights The weights of the synapse array @param num_sends How often to send the (same) input vector @param wait_between_events How long to wait (in FPGA cycles) between events @param mock Enable mock mode
@return Resulting tensor
-
hxtorch.perceptron.
matmul
(input: torch.Tensor, other: torch.Tensor, num_sends: int = 1, wait_between_events: int = 5, mock: bool = False, madc_recording_neuron_id: int = 0, madc_recording_path: str = '') → torch.Tensor Drop-in replacement for the torch.matmul operation that uses BrainScaleS-2.
@note The current implementation only supports @p other to be 1D or 2D.
@param input First input tensor @param other Second input tensor @param num_sends How often to send the (same) input vector @param wait_between_events How long to wait (in FPGA cycles) between events @param mock: Enable mock mode
@return Resulting tensor
-
hxtorch.perceptron.
measure_mock_parameter
() → hxtorch::perceptron::MockParameter Measures the mock parameters, i.e. gain and noise_std, by multiplying a full weight with an artificial test input on the BSS-2 chip. For this purpose a random pattern is used, whose mean value is successively reduced to also work with higher gain factors. The output for the actual calibration is chosen such that it is close to the middle of the available range.
-
hxtorch.perceptron.
relu
(input: torch.Tensor, mock: bool = False) → torch.Tensor Rectified linear unit operating on int8 value range.
@param input Input tensor @param mock Enable mock mode
-
hxtorch.perceptron.
set_mock_parameter
(parameter: hxtorch::perceptron::MockParameter) → None Sets the mock parameters.