dymad.modules.linear

Classes

FlexLinear(in_features, out_features[, ...])

A linear layer that can store weights either as a full matrix (MxN) or as low-rank factors (U, V) with efficient matvec operations.

class dymad.modules.linear.FlexLinear(in_features, out_features, bias=True, dtype=None, device=None)

Bases: Module

A linear layer that can store weights either as a full matrix (MxN) or as low-rank factors (U, V) with efficient matvec operations.

In the low-rank mode, the weight matrix is represented as:

W = U @ V^T

where U is (M x r) and V is (N x r).

forward(x)

Define 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.

Return type:

Tensor

set_full(W, b)

Switch to full mode and copy parameters.

set_lora(U, V, b)

Switch to lowrank mode and copy factors. U: out*r, V: in*r.

set_weights(W=None, b=None, U=None, V=None)
Return type:

tuple[Tensor, ...]