Add tests for torch.ops.load_library (#158838)

According to this [comment](https://github.com/pytorch/pytorch/pull/157524#issuecomment-3097899129), adding a related test to keep BC.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158838
Approved by: https://github.com/zou3519
This commit is contained in:
FFFrog
2025-07-24 11:32:17 +08:00
committed by PyTorch MergeBot
parent 64cb349b81
commit c60d382870

View File

@ -2333,6 +2333,14 @@ TORCH_LIBRARY(test_autograd_function_backed_op, m) {
loss.backward()
self.assertEqual(x.grad, temp)
# Using a non-existent DSO is a quick way to trigger an OSError,
# which can be used to not break BC.
def test_load_library(self):
with self.assertRaisesRegex(
OSError, "Could not load this library: .*libnoexist.so"
):
torch.ops.load_library("libnoexist.so")
def op_with_incorrect_schema(testcase, name):
lib = testcase.lib()