Skip to content

Commit 6470b37

Browse files
malfetpytorchmergebot
authored andcommitted
torch.backends.mkldnn.flags() CM should not warn (pytorch#150358)
By returning `None` rather than `False` from `THPModule_allowTF32OneDNN` when USE_XPU is not defined Added regression test Fixes pytorch#149829 Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#150358 Approved by: https://github.com/atalman
1 parent 5cb5675 commit 6470b37

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/test_mkldnn.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import itertools
55
import functools
66
import unittest
7+
import warnings
78
from contextlib import nullcontext
89

910
try:
@@ -1612,6 +1613,16 @@ def common(self, shape1, shape2, op, dtype):
16121613
]:
16131614
common(self, shape1, shape2, op, dtype)
16141615

1616+
def test_mkldnn_setflags_nowarn(self, device):
1617+
# Regression test for https://github.com/pytorch/pytorch/issues/149829
1618+
with warnings.catch_warnings(record=True) as w:
1619+
rc = torch.backends.mkldnn.set_flags()
1620+
# torch.backends.mkldnn. returns previously set flags
1621+
# That one should be able to set back without cauinsg a warning
1622+
torch.backends.mkldnn.set_flags(*rc)
1623+
# Above should trigger no warnings regardless of configuration
1624+
self.assertEqual(len(w), 0)
1625+
16151626

16161627
instantiate_device_type_tests(TestMkldnn, globals(), only_for=('cpu',))
16171628

torch/csrc/Module.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,10 +965,14 @@ static PyObject* THPModule_setAllowTF32OneDNN(
965965
static PyObject* THPModule_allowTF32OneDNN(
966966
PyObject* _unused,
967967
PyObject* noargs) {
968+
#ifdef USE_XPU
968969
if (at::globalContext().allowTF32OneDNN())
969970
Py_RETURN_TRUE;
970971
else
971972
Py_RETURN_FALSE;
973+
#else
974+
Py_RETURN_NONE;
975+
#endif
972976
}
973977

974978
static PyObject* THPModule_deterministicAlgorithms(

0 commit comments

Comments
 (0)