已合并
[sync] PR-35820: fix for unsupported_dtype export #36000
ascend-robot创建于 5月18日
[sync] PR-35820: fix for unsupported_dtype export #36000
已合并
共 2 个文件变更+33-0
| @@ -453,6 +453,38 @@ class TestTorchNpuBootstrap(TestCase): | |||
| 453 | ) | 453 | ) |
| 454 | """ | 454 | """ |
| 455 | ) | 455 | ) |
| 456 | + | ||
| 457 | + def test_08_top_level_unsupported_dtype_compatibility(self): | ||
| 458 | + self._run_python( | ||
| 459 | + """ | ||
| 460 | + import torch | ||
| 461 | + import torch_npu | ||
| 462 | + | ||
| 463 | + # Regression test for external packages such as MindSpeed. | ||
| 464 | + # They access torch_npu.unsupported_dtype directly after importing torch_npu. | ||
| 465 | + expected_unsupported_dtype = [ | ||
| 466 | + torch.quint8, | ||
| 467 | + torch.quint4x2, | ||
| 468 | + torch.quint2x4, | ||
| 469 | + torch.qint32, | ||
| 470 | + torch.qint8, | ||
| 471 | + ] | ||
| 472 | + | ||
| 473 | + unsupported_dtype = torch_npu.unsupported_dtype | ||
| 474 | + | ||
| 475 | + assert unsupported_dtype == expected_unsupported_dtype | ||
| 476 | + assert "unsupported_dtype" in dir(torch_npu) | ||
| 477 | + assert "unsupported_dtype" in torch_npu.__dict__ | ||
| 478 | + | ||
| 479 | + # Simulate MindSpeed-style dtype filtering. | ||
| 480 | + valid_dtype_names = [] | ||
| 481 | + for name, attr in torch.__dict__.items(): | ||
| 482 | + if isinstance(attr, torch.dtype) and attr not in torch_npu.unsupported_dtype: | ||
| 483 | + valid_dtype_names.append(name) | ||
| 484 | + | ||
| 485 | + assert valid_dtype_names, "no valid torch dtype found" | ||
| 486 | + """ | ||
| 487 | + ) | ||
| 456 | 488 | ||
| 457 | 489 | ||
| 458 | if __name__ == "__main__": | 490 | if __name__ == "__main__": |
| @@ -14,6 +14,7 @@ def register_privateuse1_backend(): | |||
| 14 | torch.qint32, | 14 | torch.qint32, |
| 15 | torch.qint8, | 15 | torch.qint8, |
| 16 | ] | 16 | ] |
| 17 | + torch_npu.unsupported_dtype = unsupported_dtype | ||
| 17 | torch.utils.generate_methods_for_privateuse1_backend( | 18 | torch.utils.generate_methods_for_privateuse1_backend( |
| 18 | for_tensor=True, | 19 | for_tensor=True, |
| 19 | for_module=True, | 20 | for_module=True, |