Skip to content

Conversation

namgyu-youn
Copy link
Contributor

@namgyu-youn namgyu-youn commented Jun 6, 2025

Replaces torch.norm() with torch.linalg.vector_norm() for upcoming PyTorch update.

Based on PyTorch - docs, torch.norm() will no longer be used

Following is the test code:

import torch

# Create test tensors
torch.manual_seed(42)
X = torch.randn(10, 10)
X_hat, A_reg = torch.randn(10, 10), torch.randn(5, 5)

print("X shape:", X.shape)
print("A_reg shape:", A_reg.shape)
print()

# Old Version (torch.norm)
print("=== torch.norm ===")
relative_error = torch.dist(X, X_hat, p=torch.inf) / torch.norm(X, p=torch.inf)
norm_result = torch.norm(A_reg, p=torch.inf)

print("Relative error:", relative_error.item())
print("A_reg infinity norm:", norm_result.item())
print()

# New Version (torch.linalg.vector_norm)
print("=== (torch.linalg.vector_norm ===")
relative_error = torch.dist(X, X_hat, p=torch.inf) / torch.linalg.vector_norm(X, ord=torch.inf)
norm_result = torch.linalg.vector_norm(A_reg, ord=torch.inf)

print("Relative error:", relative_error.item())
print("A_reg infinity norm:", norm_result.item())

And the result is:

X shape: torch.Size([10, 10])
A_reg shape: torch.Size([5, 5])

=== torch.norm ===
Relative error: 1.512144684791565
A_reg infinity norm: 1.9775909185409546

=== torch.linalg.vector_norm ===
Relative error: 1.512144684791565
A_reg infinity norm: 1.9775909185409546

- torch.norm will no longer be used for norm computation
- torch.linalg.vector_norm will be used instead
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 6, 2025
Copy link
Contributor

@tsunghsienlee tsunghsienlee left a comment

Choose a reason for hiding this comment

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

Great! Really appreciated that you look-ahead for this!

@facebook-github-bot
Copy link
Contributor

@tsunghsienlee has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@tsunghsienlee merged this pull request in abb683d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants