Skip to content

Commit e0388ff

Browse files
committed
improved test for random matrices for skew bound
Signed-off-by: mikail <mkhona@nvidia.com>
1 parent 2fe3ce3 commit e0388ff

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/test_psgd_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,19 @@ def test_small_skew_symmetric_matrix(self) -> None:
195195
# Bound should be positive for non-zero matrix
196196
self.assertGreater(bound.item(), 0.0)
197197

198-
def test_identity_based_skew_matrix(self) -> None:
199-
"""Test norm_lower_bound_skew with matrix based on identity structure."""
198+
@parameterized.parameters([4, 16, 32])
199+
def test_random_based_skew_matrix_with_different_sizes(self, size: int) -> None:
200+
"""Test norm_lower_bound_skew with random skew-symmetric matrix."""
200201
# Create skew-symmetric matrix from anti-symmetric part of random matrix
201-
n = 4
202+
n = size
202203
B = torch.randn(n, n, device=self.device)
203204
A = B - B.T # This creates a skew-symmetric matrix
204205

205206
bound = norm_lower_bound_skew(A)
206207
actual_norm = torch.linalg.matrix_norm(A, ord=2)
207208

208209
# Bound should be <= actual norm
209-
self.assertLessEqual(bound.item(), actual_norm.item() + 1e-4)
210+
self.assertLessEqual(bound.item(), actual_norm.item() + 1e-3)
210211

211212
@parameterized.product(
212213
dtype=[torch.float32, torch.float64],
@@ -228,7 +229,7 @@ def test_norm_lower_bound_skew_is_lower_bound(self, dtype: torch.dtype, size: in
228229
# Bound should be non-negative
229230
self.assertGreaterEqual(bound.item(), 0.0)
230231

231-
@parameterized.parameters([4, 16, 32])
232+
@parameterized.parameters([4, 16, 32, 64])
232233
def test_different_subspace_dimensions(self, rank: int) -> None:
233234
"""Test norm_lower_bound_skew with different subspace dimensions."""
234235
# Create a skew-symmetric matrix

0 commit comments

Comments
 (0)