Skip to content

Fix dimension count in orthogonal initializer error message - #3693

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
Pablosinyores:orthogonal-init-error-message
Jun 16, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
Pablosinyores:orthogonal-init-error-message

Conversation

@Pablosinyores

Copy link
Copy Markdown
Contributor

The error raised by nn.init.orthogonal for a non-2D input never reported the actual number of dimensions. The message was split across two string literals where only the first carried the f prefix:

raise ValueError(
    f"Orthogonal initialization requires a 2D array but got"
    " a {a.ndim}D array."
)

The {a.ndim} lives on the plain (non-f) string, so it was printed verbatim:

Orthogonal initialization requires a 2D array but got a {a.ndim}D array.

Moving the f prefix onto the segment that contains the placeholder fixes the interpolation:

Orthogonal initialization requires a 2D array but got a 3D array.

Added an assertion to test_orthogonal that a 3D input reports 3D array in the message.

The error raised for a non-2D input concatenated a plain string holding
{a.ndim} onto an f-string, so the message printed the literal text
instead of the array's dimension count. Move the interpolation onto the
f-string and add a test asserting the reported dimension.

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zcbenz
zcbenz merged commit 09bab27 into ml-explore:main Jun 16, 2026
16 checks passed
@BrewTestBot BrewTestBot mentioned this pull request Jul 7, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants