tltorch.factorized_layers
.FactorizedLinear¶

class
tltorch.factorized_layers.
FactorizedLinear
(in_tensorized_features, out_tensorized_features, bias=True, factorization='cp', rank='same', n_layers=1)[source]¶ Tensorized FullyConnected Layers
The weight matrice is tensorized to a tensor of size tensorized_shape. That tensor is expressed as a lowrank tensor. During inference, the full tensor is reconstructed, and unfolded back into a matrix, used for the forward pass in a regular linear layer.
 Parameters
 in_featuresint
 out_featuresint
 tensorized_shapeint tuple
 rankint tuple or str
 biasbool, default is True
Methods
forward
(x[, indices])Defines the computation performed at every call.
from_linear
(linear, in_tensorized_features, …)Class method to create an instance from an existing linear layer
from_linear_list
(linear_list, …[, bias, …])Class method to create an instance from an existing linear layer
get_linear
reset_parameters

forward
(x, indices=0)[source]¶ Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

classmethod
from_linear
(linear, in_tensorized_features, out_tensorized_features, rank, bias=True, factorization='CP', decomposition_kwargs={})[source]¶ Class method to create an instance from an existing linear layer
 Parameters
 lineartorch.nn.Linear
layer to tensorize
 tensorized_shapetuple
shape to tensorized the factorized_weight matrix to. Must verify np.prod(tensorized_shape) == np.prod(linear.factorized_weight.shape)
 rank{rank of the decomposition, ‘same’, float}
if float, percentage of parameters of the original factorized_weights to use if ‘same’ use the same number of parameters
 biasbool, default is True

classmethod
from_linear_list
(linear_list, in_tensorized_features, out_tensorized_features, rank, bias=True, factorization='CP', decomposition_kwargs={'init': 'random'})[source]¶ Class method to create an instance from an existing linear layer
 Parameters
 lineartorch.nn.Linear
layer to tensorize
 tensorized_shapetuple
shape to tensorized the weight matrix to. Must verify np.prod(tensorized_shape) == np.prod(linear.weight.shape)
 rank{rank of the decomposition, ‘same’, float}
if float, percentage of parameters of the original weights to use if ‘same’ use the same number of parameters
 biasbool, default is True