mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
See #127836 for details. Pull Request resolved: https://github.com/pytorch/pytorch/pull/127841 Approved by: https://github.com/oulgen
30 lines
702 B
Python
30 lines
702 B
Python
# mypy: allow-untyped-defs
|
|
import sys
|
|
import types
|
|
|
|
import torch
|
|
|
|
|
|
class _XNNPACKEnabled:
|
|
def __get__(self, obj, objtype):
|
|
return torch._C._is_xnnpack_enabled()
|
|
|
|
def __set__(self, obj, val):
|
|
raise RuntimeError("Assignment not supported")
|
|
|
|
|
|
class XNNPACKEngine(types.ModuleType):
|
|
def __init__(self, m, name):
|
|
super().__init__(name)
|
|
self.m = m
|
|
|
|
def __getattr__(self, attr):
|
|
return self.m.__getattribute__(attr)
|
|
|
|
enabled = _XNNPACKEnabled()
|
|
|
|
|
|
# This is the sys.modules replacement trick, see
|
|
# https://stackoverflow.com/questions/2447353/getattr-on-a-module/7668273#7668273
|
|
sys.modules[__name__] = XNNPACKEngine(sys.modules[__name__], __name__)
|