Muon momentum and Newton–Schulz update
Implement a Muon-style step on one matrix parameter.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Given weights, momentum and gradient of equal nonempty rectangular shape, accumulate M=beta×momentum+gradient. Direction is M, or gradient+beta×M when nesterov is true. Transpose a tall direction to make the working matrix no taller than wide, then divide by its Frobenius norm plus epsilon. Repeat iterations of X := aX + b(XXᵀ)X + c(XXᵀ)²X with (a,b,c)=(3.4445,−4.7750,2.0315); transpose back if needed. Return momentum (M), update (the resulting X) and weights=(1−lr×decay)×old_weights−lr×X. This lab omits automatic shape-dependent learning-rate scaling and low-precision casting.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Implement a Muon-style step on one matrix parameter.
Reproduction
{"weights":[[1,2,3],[4,5,6]],"momentum":[[0,1,0],[1,0,1]],"gradient":[[1,2,3],[4,5,6]],"beta":0.8,"lr":0.1,"nesterov":false,"iterations":3,"decay":0,"epsilon":1e-07}{"weights":[[1.039131,1.949977,2.973687],[3.948066,4.97915,5.956366]],"momentum":[[1,2.8,3],[4.8,5,6.8]],"update":[[-0.391306,0.500227,0.263134],[0.519338,0.208502,0.436344]]}{"weights":[[1]],"momentum":[[0]],"gradient":[[0]],"beta":0.9,"lr":0.1,"nesterov":false,"iterations":5,"decay":0,"epsilon":1e-07}{"weights":[[1]],"momentum":[[0]],"update":[[0]]}{"weights":[[1],[2],[3]],"momentum":[[0],[0],[0]],"gradient":[[1],[2],[3]],"beta":0,"lr":0.1,"nesterov":false,"iterations":2,"decay":0,"epsilon":1e-07}{"weights":[[0.970237],[1.940474],[2.910712]],"momentum":[[1],[2],[3]],"update":[[0.297628],[0.595255],[0.892883]]}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.