TensorTonic
Study Plans
Study Plan
Orthogonalize a Muon Momentum Update
Language ModelsOptimizationLinear Algebra
Easy

Apply one momentum and spectral update to a parameter matrix. Let WtW_tWt​ be parameter, GtG_tGt​ gradient, Bt−1B_{t-1}Bt−1​ previous_momentum, μ\muμ momentum_coefficient and η\etaη learning_rate. The updated momentum is:

Bt=μBt−1+Gt.B_t=\mu B_{t-1}+G_t.Bt​=μBt−1​+Gt​.

For a matrix with mmm rows and nnn columns, let r=min⁡(m,n)r=\min(m,n)r=min(m,n). Its compact singular value decomposition (SVD) is:

Bt=UΣVT.B_t=U\Sigma V^{\mathsf T}.Bt​=UΣVT.

Here, UUU has shape (m,r)(m,r)(m,r) and VVV has shape (n,r)(n,r)(n,r); their columns are singular vectors, and diagonal matrix Σ\SigmaΣ contains the singular values. Replacing those values with one defines the spectral update OtO_tOt​:

Ot=UVT.O_t=UV^{\mathsf T}.Ot​=UVT.

The new parameter is:

Wt+1=Wt−ηOt.W_{t+1}=W_t-\eta O_t.Wt+1​=Wt​−ηOt​.

Return a Python dictionary with new_parameter, new_momentum and orthogonalized_update, each a PyTorch tensor with the parameter's shape, dtype and device.

Loading visualization...

Examples

Input: parameter = [[1,0],[0,1]], gradient = [[1,0],[0,2]], previous_momentum = [[0,0],[0,0]], momentum_coefficient = 0.9, learning_rate = 0.1

Output: {"new_parameter":[[0.9,0],[0,0.9]],"new_momentum":[[1,0],[0,2]],"orthogonalized_update":[[1,0],[0,1]]}

Explanation: Momentum equals the diagonal gradient, and replacing its positive singular values with one produces the identity update.

Input: parameter = [[0,0],[0,0],[0,0]], gradient = [[1,0],[0,1],[0,0]], previous_momentum = [[0,0],[0,0],[0,0]], momentum_coefficient = 0, learning_rate = 0.1

Output: {"new_parameter":[[-0.1,0],[0,-0.1],[0,0]],"new_momentum":[[1,0],[0,1],[0,0]],"orthogonalized_update":[[1,0],[0,1],[0,0]]}

Input: parameter = [[0,0,0],[0,0,0]], gradient = [[1,0,0],[0,1,0]], previous_momentum = [[0,0,0],[0,0,0]], momentum_coefficient = 0, learning_rate = 0.2

Output: {"new_parameter":[[-0.2,0,0],[0,-0.2,0]],"new_momentum":[[1,0,0],[0,1,0]],"orthogonalized_update":[[1,0,0],[0,1,0]]}

Hint 1

torch.linalg.svd provides singular vectors and singular values.

Hint 2

The @ operator multiplies two matrices.

Hint 3

Tensor.to can match another tensor’s dtype.

Requirements

  • Use PyTorch, computing the SVD and singular-vector product in float32.
  • Momentum and parameter arithmetic use the input dtype; restore the spectral update to that dtype before the parameter update.
  • Do not modify input tensors.

Constraints

  • parameter, gradient, and previous_momentum are same-shaped rank-two PyTorch tensors with the same dtype and device.
  • Both matrix dimensions are positive; square, tall, and wide matrices are supported.
  • momentum_coefficient lies in [0, 1), and learning_rate is nonnegative.
  • Supported tensor dtypes are float32 and bfloat16.
  • Inputs contain finite values and may be noncontiguous.
  • Updated momentum has full rank: its rank equals the smaller matrix dimension.
Try Similar Problems
Generate a Warmup-Stable-Decay ScheduleMediumFit Learning-Rate and Batch-Size ScalingHardMixed-Precision Training Memory AccountantEasyParallel and Recurrent Linear AttentionMediumMamba 2 Gated State ScanMediumDiagnose muP Width InvariantsMediumRecover an IsoFLOP Compute-Optimal FrontierHardGated DeltaNet State UpdateHardConvexity Certificate via the HessianMediumClassify a Critical Point from the HessianMediumConvex Polytope MembershipMediumHessian Matrix & Convexity of Linear Regression LossMedium

Accepts: array

Accepts: array

Accepts: array

Accepts: number

Accepts: number

You must run your code first.

Orthogonalize a Muon Momentum Update

Language ModelsOptimizationLinear Algebra
Easy

Apply one momentum and spectral update to a parameter matrix. Let WtW_tWt​ be parameter, GtG_tGt​ gradient, Bt−1B_{t-1}Bt−1​ previous_momentum, μ\muμ momentum_coefficient and η\etaη learning_rate. The updated momentum is:

Bt=μBt−1+Gt.B_t=\mu B_{t-1}+G_t.Bt​=μBt−1​+Gt​.

For a matrix with mmm rows and nnn columns, let r=min⁡(m,n)r=\min(m,n)r=min(m,n). Its compact singular value decomposition (SVD) is:

Bt=UΣVT.B_t=U\Sigma V^{\mathsf T}.Bt​=UΣVT.

Here, UUU has shape (m,r)(m,r)(m,r) and VVV has shape (n,r)(n,r)(n,r); their columns are singular vectors, and diagonal matrix Σ\SigmaΣ contains the singular values. Replacing those values with one defines the spectral update OtO_tOt​:

Ot=UVT.O_t=UV^{\mathsf T}.Ot​=UVT.

The new parameter is:

Wt+1=Wt−ηOt.W_{t+1}=W_t-\eta O_t.Wt+1​=Wt​−ηOt​.

Return a Python dictionary with new_parameter, new_momentum and orthogonalized_update, each a PyTorch tensor with the parameter's shape, dtype and device.

Loading visualization...

Examples

Input: parameter = [[1,0],[0,1]], gradient = [[1,0],[0,2]], previous_momentum = [[0,0],[0,0]], momentum_coefficient = 0.9, learning_rate = 0.1

Output: {"new_parameter":[[0.9,0],[0,0.9]],"new_momentum":[[1,0],[0,2]],"orthogonalized_update":[[1,0],[0,1]]}

Explanation: Momentum equals the diagonal gradient, and replacing its positive singular values with one produces the identity update.

Input: parameter = [[0,0],[0,0],[0,0]], gradient = [[1,0],[0,1],[0,0]], previous_momentum = [[0,0],[0,0],[0,0]], momentum_coefficient = 0, learning_rate = 0.1

Output: {"new_parameter":[[-0.1,0],[0,-0.1],[0,0]],"new_momentum":[[1,0],[0,1],[0,0]],"orthogonalized_update":[[1,0],[0,1],[0,0]]}

Input: parameter = [[0,0,0],[0,0,0]], gradient = [[1,0,0],[0,1,0]], previous_momentum = [[0,0,0],[0,0,0]], momentum_coefficient = 0, learning_rate = 0.2

Output: {"new_parameter":[[-0.2,0,0],[0,-0.2,0]],"new_momentum":[[1,0,0],[0,1,0]],"orthogonalized_update":[[1,0,0],[0,1,0]]}

Hint 1

torch.linalg.svd provides singular vectors and singular values.

Hint 2

The @ operator multiplies two matrices.

Hint 3

Tensor.to can match another tensor’s dtype.

Requirements

  • Use PyTorch, computing the SVD and singular-vector product in float32.
  • Momentum and parameter arithmetic use the input dtype; restore the spectral update to that dtype before the parameter update.
  • Do not modify input tensors.

Constraints

  • parameter, gradient, and previous_momentum are same-shaped rank-two PyTorch tensors with the same dtype and device.
  • Both matrix dimensions are positive; square, tall, and wide matrices are supported.
  • momentum_coefficient lies in [0, 1), and learning_rate is nonnegative.
  • Supported tensor dtypes are float32 and bfloat16.
  • Inputs contain finite values and may be noncontiguous.
  • Updated momentum has full rank: its rank equals the smaller matrix dimension.
Try Similar Problems
Generate a Warmup-Stable-Decay ScheduleMediumFit Learning-Rate and Batch-Size ScalingHardMixed-Precision Training Memory AccountantEasyParallel and Recurrent Linear AttentionMediumMamba 2 Gated State ScanMediumDiagnose muP Width InvariantsMediumRecover an IsoFLOP Compute-Optimal FrontierHardGated DeltaNet State UpdateHardConvexity Certificate via the HessianMediumClassify a Critical Point from the HessianMediumConvex Polytope MembershipMediumHessian Matrix & Convexity of Linear Regression LossMedium

Accepts: array

Accepts: array

Accepts: array

Accepts: number

Accepts: number

You must run your code first.