fix tests caused by has_triton (#161737)

Summary: this will only cause it in the event that we are serializing a triton hop. there are a few tests that do weird mocking stuff that this function doesn't like, so this will prevent it from being called there.

Test Plan:
att

Rollback Plan:

Differential Revision: D81261486

Pull Request resolved: https://github.com/pytorch/pytorch/pull/161737
Approved by: https://github.com/angelayi
This commit is contained in:
Dylan Maloy 2025-08-29 02:25:35 +00:00 committed by PyTorch MergeBot
parent 5cb1d71e59
commit c1cb1cb26e

View File

@ -94,14 +94,6 @@ from .schema import ( # type: ignore[attr-defined]
from .union import _Union from .union import _Union
if has_triton():
from triton.runtime.autotuner import Autotuner
else:
class Autotuner: # type: ignore[no-redef]
pass
__all__ = [ __all__ = [
"serialize", "serialize",
"GraphModuleSerializer", "GraphModuleSerializer",
@ -684,6 +676,7 @@ class GraphModuleSerializer(metaclass=Final):
is torch._higher_order_ops.triton_kernel_wrap.triton_kernel_wrapper_functional is torch._higher_order_ops.triton_kernel_wrap.triton_kernel_wrapper_functional
): ):
assert has_triton(), "triton required to serialize triton kernels" assert has_triton(), "triton required to serialize triton kernels"
from triton.runtime.autotuner import Autotuner
meta_val = node.meta["val"] meta_val = node.meta["val"]
assert isinstance(meta_val, dict) assert isinstance(meta_val, dict)