xbtorch.deployment.encoding

Weight encoding schemes for mapping software weight matrices to crossbar conductance arrays.

This module implements different strategies for converting software weights into positive/negative conductance matrices (G_pos, G_neg), including support for fault tolerance in the presence of device-level stuck-at defects.

Functions

References

  • LEA schemes: D. Niu et al., “Ensemble Learning for Memristive Neural Networks”, ACM, 2023.

  • MAO scheme: C. Yu et al., “Mapping Algorithm With Fault-Tolerance for Memristor Crossbar”, IEEE TVLSI, 2016.

Functions

encode_LEA1(accelerator, sw_weight[, ...])

Encode weights using Layer Ensemble Averaging (LEA-1).

encode_LEA2(accelerator, sw_weight[, ...])

Encode weights using Layer Ensemble Averaging (LEA-2).

encode_MAO(accelerator, sw_weight[, ...])

Encode weights using the Mapping Algorithm with inner Fault-tOlerance (MAO).

encode_simple_binary(accelerator, sw_weight)

Encode weights using a simple binary scheme.

quantize_to_nearest(x, G_min, d, n)

Quantize a conductance value to the nearest available state.

xbtorch.deployment.encoding.encode_LEA1(accelerator, sw_weight, pos_idxs=[], neg_idxs=[], additional_args={})[source]

Encode weights using Layer Ensemble Averaging (LEA-1).

In LEA-1, each weight is redundantly mapped across multiple crossbar rows/columns (beta copies). Rows corresponding to the most defective devices are masked out, preserving accuracy while reducing hardware variability impact.

Parameters:
  • accelerator (GenericAccelerator) – Crossbar accelerator instance.

  • sw_weight (torch.Tensor) – Software weight matrix.

  • pos_idxs (list of tuple[int, int]) – Mapping indices for redundant weight placement.

  • neg_idxs (list of tuple[int, int]) – Mapping indices for redundant weight placement.

  • additional_args (dict) – Must include: - alpha (int): Number of rows to keep. - beta (int): Total number of redundant rows.

Returns:

Positive and negative conductance matrices, and corresponding row masks.

Return type:

list[torch.Tensor], list[torch.Tensor], torch.Tensor, torch.Tensor

xbtorch.deployment.encoding.encode_LEA2(accelerator, sw_weight, pos_idxs=[], neg_idxs=[], states=2, additional_args={}, log=False)[source]

Encode weights using Layer Ensemble Averaging (LEA-2).

LEA-2 adaptively adjusts conductances in the presence of stuck-at defects. Each weight is distributed across redundant devices, with defective elements compensated by tuning remaining devices toward nearest available conductance states.

Parameters:
  • accelerator (GenericAccelerator) – Crossbar accelerator instance.

  • sw_weight (torch.Tensor) – Software weight matrix.

  • pos_idxs (list of tuple[int, int]) – Mapping indices for redundant weight placement.

  • neg_idxs (list of tuple[int, int]) – Mapping indices for redundant weight placement.

  • states (int, optional) – Number of available conductance states (default: 2).

  • additional_args (dict, optional) – Extra configuration parameters.

  • log (bool, optional) – If True, prints debugging information during adjustment.

Returns:

Positive and negative conductance matrices, and row masks.

Return type:

list[torch.Tensor], list[torch.Tensor], torch.Tensor, torch.Tensor

xbtorch.deployment.encoding.encode_MAO(accelerator, sw_weight, pos_idxs=[], neg_idxs=[], states=2, additional_args={}, log=False)[source]

Encode weights using the Mapping Algorithm with inner Fault-tOlerance (MAO).

MAO (Yu et al., 2016) is a defect-aware mapping scheme where conductance values are analytically adjusted in redundant devices to approximate the target software weight even when some devices are stuck.

Parameters:
  • accelerator (GenericAccelerator) – Crossbar accelerator instance.

  • sw_weight (torch.Tensor) – Software weight matrix.

  • pos_idxs (list of tuple[int, int]) – Mapping indices for redundant weight placement.

  • neg_idxs (list of tuple[int, int]) – Mapping indices for redundant weight placement.

  • states (int, optional) – Number of available conductance states (default: 2).

  • additional_args (dict, optional) – Extra configuration parameters.

  • log (bool, optional) – If True, prints debugging information during adjustment.

Returns:

Adjusted positive and negative conductance matrices.

Return type:

list[torch.Tensor], list[torch.Tensor]

xbtorch.deployment.encoding.encode_simple_binary(accelerator, sw_weight, pos_idxs=[], neg_idxs=[], additional_args={})[source]

Encode weights using a simple binary scheme.

Each software weight is represented by two possible conductance states: - Positive weights → G_pos = g_max, G_neg = g_min - Negative weights → G_pos = g_min, G_neg = g_max - Near-zero weights → G_pos = G_neg = g_min

Parameters:
  • accelerator (GenericAccelerator) – Crossbar accelerator instance providing hardware parameters (g_min, g_max).

  • sw_weight (torch.Tensor) – Software weight matrix.

  • pos_idxs (list of tuple[int, int], optional) – Array mapping positions for positive and negative conductances.

  • neg_idxs (list of tuple[int, int], optional) – Array mapping positions for positive and negative conductances.

  • additional_args (dict, optional) – Extra parameters, supports: - zero_tol (float): Threshold below which weights are treated as zero.

Returns:

Lists of positive and negative conductance matrices.

Return type:

list[torch.Tensor], list[torch.Tensor]

xbtorch.deployment.encoding.quantize_to_nearest(x, G_min, d, n)[source]

Quantize a conductance value to the nearest available state.

Parameters:
  • x (float) – Target conductance value.

  • G_min (float) – Minimum conductance.

  • d (float) – Step size between quantization levels.

  • n (int) – Number of quantization levels.

Returns:

Quantized conductance value.

Return type:

float