Skip to content
class

OrthLayer

extendsModule
OrthLayer(size: int, orth: bool = True, mag_b: bool = True, mag_a: bool = True, use_cayley_neumann: bool = False, num_cayley_neumann_terms: int = 5, cayley_neumann_eps: float | None = None, init_weights: bool = True, device: DeviceLike = None, dtype: DTypeLike = None)

The matrix C=diag⁡(β) R diag⁡(α)C = \operatorname{diag}(\beta)\,R\,\operatorname{diag}(\alpha), the parameters that make it, and how to apply it.

Parameters

sizeint
The rank rr of the principal subspace.
orthbool= True
Keep RR orthogonal with the Cayley transform of a skew-symmetric matrix whose r(r−1)/2r(r-1)/2 upper entries are trained; False trains RR itself.
mag_bbool= True
Whether the vector left of (mag_b) or right of (mag_a) RR is trained.
mag_abool= True
Whether the vector left of (mag_b) or right of (mag_a) RR is trained.
use_cayley_neumannbool= False
Build RR from a truncated Neumann series instead of an exact solve.
num_cayley_neumann_termsint= 5
Terms of the series.
cayley_neumann_epsfloat= None
With the series, rescale the generator whenever its Frobenius norm exceeds this.
init_weightsbool= True
Start at the identity (the generator at zero, the vectors at one); False perturbs RR by a normal of standard deviation 0.1.
deviceDeviceLike= None
Where and in what dtype the parameters are made.
dtypeDeviceLike= None
Where and in what dtype the parameters are made.

Used by 2

Constructors

1
dunder

__init__

→None
__init__(size: int, orth: bool = True, mag_b: bool = True, mag_a: bool = True, use_cayley_neumann: bool = False, num_cayley_neumann_terms: int = 5, cayley_neumann_eps: float | None = None, init_weights: bool = True, device: DeviceLike = None, dtype: DTypeLike = None)

Make the generator (or the free matrix) and the two vectors, on device in dtype.

Instance methods

3
fn

extra_repr

→str
extra_repr()

The size and the options that shape the matrix.

fn

forward

→Tensor
forward(input: Tensor)

x C⊤x\,C^\top, with input of width r on its last axis.

fn

get_matrix

→Tensor
get_matrix()

Return CC, the (r, r) matrix the layer applies between its factors.

R=(I+Q)(I−Q)−1R = (I + Q)(I - Q)^{-1}: exact, or the Neumann series I+2Q+2Q2+⋯+Qt−1I + 2Q + 2Q^2 + \dots + Q^{t-1} with its last term halved, built from weight as QQ. The vectors then scale its rows (vector_b) and columns (vector_a).