Skip to content

Commit 1a75689

Browse files
committed
Add test cases
1 parent 894857e commit 1a75689

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

test/sparsity/test_sparse_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,32 @@ def test_sparse(self, compile):
267267

268268
torch.testing.assert_close(reference, sparse_result, rtol=1e-1, atol=1e-1)
269269

270+
# TODO: Remove this test once the deprecated API has been removed
271+
def test_sparse_deprecated(self):
272+
import sys
273+
import warnings
274+
275+
# We need to clear the cache to force re-importing and trigger the warning again.
276+
modules_to_clear = [
277+
"torchao.dtypes.uintx.block_sparse_layout",
278+
"torchao.dtypes",
279+
]
280+
for mod in modules_to_clear:
281+
if mod in sys.modules:
282+
del sys.modules[mod]
283+
284+
with warnings.catch_warnings(record=True) as w:
285+
from torchao.dtypes import BlockSparseLayout
286+
warnings.simplefilter("always") # Ensure all warnings are captured
287+
self.assertTrue(
288+
any(
289+
issubclass(warning.category, DeprecationWarning)
290+
and "BlockSparseLayout" in str(warning.message)
291+
for warning in w
292+
),
293+
f"Expected deprecation warning for BlockSparseLayout, got: {[str(w.message) for w in w]}",
294+
)
295+
270296

271297
common_utils.instantiate_parametrized_tests(TestSemiStructuredSparse)
272298
common_utils.instantiate_parametrized_tests(TestQuantSemiSparse)

torchao/dtypes/uintx/block_sparse_layout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
warnings.warn(
1111
"Importing BlockSparseLayout from torchao.dtypes is deprecated. "
1212
"Please use 'from torchao.prototype.dtypes import BlockSparseLayout' instead. "
13-
"This import path will be removed in torchao v0.16.0.",
13+
"This import path will be removed in torchao v0.16.0. "
14+
"Please check issue: https://github.com/pytorch/ao/issues/2752 for more details. ",
1415
DeprecationWarning,
1516
stacklevel=2,
1617
)

0 commit comments

Comments
 (0)