fix: Handle wide matrices in orthogonal initializer#629
Open
blasphemetheus wants to merge 1 commit intoelixir-nx:mainfrom
Open
fix: Handle wide matrices in orthogonal initializer#629blasphemetheus wants to merge 1 commit intoelixir-nx:mainfrom
blasphemetheus wants to merge 1 commit intoelixir-nx:mainfrom
Conversation
QR decomposition of an {m, n} matrix produces Q of shape {m, m},
which fails when n > m (e.g. LSTM weights {hidden, 4*hidden}).
Generate a {max(m,n), max(m,n)} square random matrix so QR always
produces enough orthogonal columns, then slice to {m, n}.
Adds tests for wide 2D and high-rank shapes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title: Fix orthogonal initializer for wide matrices
Summary
orthogonal_implto generate a{max(m,n), max(m,n)}square random matrix instead of{m, n}, so QR decomposition produces enough orthogonal columns for wide shapes{8, 32}with orthonormality assertion{2, 8}Fixes #628
Test plan
{8, 32}produces orthonormal rows (t * t^T ≈ I){2, 8}returns correct shape