Skip to content

Commit a2922f5

Browse files
authored
[1.6.0] Mark torch.set_deterministic and torch.is_deterministic as experimental (pytorch#41870)
This PR: - renames `torch.set_deterministic` to `torch._set_deterministic` - renames `torch.is_deterministic` to `torch._is_deterministic` - Modifies the docstrings for both to indicate that the feature is not yet complete. We would like to do this because this feature is experimental and the docstrings before this PR are misleading. This PR does not have an accompanying change in master. That is because there still is discussion over what the eventual state of the feature should be: pytorch#15359. I expect that there will be a better plan for this once 1.7 rolls around. Test Plan: - wait for CI
1 parent 8acfeca commit a2922f5

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

test/test_torch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ def test_dir(self):
116116
dir(torch)
117117

118118
def test_deterministic_flag(self):
119-
deterministic_restore = torch.is_deterministic()
119+
deterministic_restore = torch._is_deterministic()
120120

121121
for deterministic in [True, False]:
122-
torch.set_deterministic(deterministic)
123-
self.assertEqual(deterministic, torch.is_deterministic())
122+
torch._set_deterministic(deterministic)
123+
self.assertEqual(deterministic, torch._is_deterministic())
124124

125125
with self.assertRaisesRegex(RuntimeError, r"set_deterministic expects a bool, but got int"):
126-
torch.set_deterministic(1)
126+
torch._set_deterministic(1)
127127

128-
torch.set_deterministic(deterministic_restore)
128+
torch._set_deterministic(deterministic_restore)
129129

130130
def test_type_conversion_via_dtype_name(self):
131131
x = torch.tensor([1])

torch/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'ShortStorage', 'CharStorage', 'ByteStorage', 'BoolStorage',
3535
'DoubleTensor', 'FloatTensor', 'LongTensor', 'IntTensor',
3636
'ShortTensor', 'CharTensor', 'ByteTensor', 'BoolTensor', 'Tensor',
37-
'lobpcg', 'set_deterministic', 'is_deterministic'
37+
'lobpcg', '_set_deterministic', '_is_deterministic'
3838
]
3939

4040
################################################################################
@@ -298,7 +298,7 @@ def set_default_dtype(d):
298298
"""
299299
_C._set_default_dtype(d)
300300

301-
def set_deterministic(d):
301+
def _set_deterministic(d):
302302
r"""Sets a global flag to force all operations to use a deterministic
303303
implementation if available. If an operation that does not have a
304304
deterministic implementation is called while this setting is True, the
@@ -310,12 +310,24 @@ def set_deterministic(d):
310310
Args:
311311
d (:class:`bool`): If True, force operations to be deterministic.
312312
If False, allow non-deterministic operations.
313+
314+
.. warning::
315+
This feature is experimental and not complete. The above docstring
316+
represents what the future behavior is intended to be. Right now,
317+
`_set_deterministic` will only affect `torch.bmm` and convolution
318+
operators.
313319
"""
314320
_C._set_deterministic(d)
315321

316-
def is_deterministic():
322+
def _is_deterministic():
317323
r"""Returns True if the global deterministic flag is turned on and
318324
operations are being forced to use a deterministic implementation.
325+
326+
.. warning::
327+
This feature is experimental and not complete. The above docstring
328+
represents what the future behavior is intended to be. Right now,
329+
the global deterministic flag will only affect `torch.bmm` and
330+
convolution operators.
319331
"""
320332
return _C._get_deterministic()
321333

torch/_overrides.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def get_ignored_functions():
142142
torch.autocast_decrement_nesting,
143143
torch.nn.functional.hardswish,
144144
torch.is_vulkan_available,
145-
torch.is_deterministic,
146-
torch.set_deterministic
145+
torch._is_deterministic,
146+
torch._set_deterministic
147147
)
148148

149149
def get_testing_overrides():

0 commit comments

Comments
 (0)