TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-08

tensorplay.ao.pruning.custom_from_mask

tensorplay.ao.pruning.custom_from_mask(module: Module, name: str, mask: Tensor) → Module[source]

Prune module[name] with a pre-computed binary mask.

Modifies the module in place (and also returns it) by:

  1. adding a named buffer called name + '_mask' holding mask;

  2. replacing the parameter name by its masked version, while the original (unmasked) values are stored in a new parameter named name + '_orig'.

Parameters:
  • module – module containing the tensor to prune.

  • name – parameter name within module on which pruning acts.

  • mask – binary mask to be applied to the parameter.

Returns:

The modified (i.e. pruned) module.

Examples

>>> # xdoctest: +SKIP
>>> m = custom_from_mask(
...     nn.Linear(5, 3), name="bias", mask=tensorplay.tensor([0, 1, 0])
... )
>>> print(m.bias_mask)
tensor([0., 1., 0.])

On this page

Ask DeepWiki