Skip to content

Commit fd7d5f8

Browse files
zou3519Chao1Han
authored andcommitted
Improve custom ops aliasing error message (pytorch#134688)
Fixes pytorch#134278 Test Plan: - tested locally Pull Request resolved: pytorch#134688 Approved by: https://github.com/yushangdi ghstack dependencies: pytorch#134466, pytorch#134490, pytorch#134491, pytorch#134690, pytorch#134692
1 parent fdfe7f5 commit fd7d5f8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

torch/_library/custom_ops.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,16 @@ def backend_impl(*args, **kwargs):
332332
fn = self._backend_fns[device_type]
333333
module = inspect.getmodule(fn)
334334
raise RuntimeError(
335-
f"Tensors returned from custom ops (1) must not "
336-
f"be inputs to the custom op and (2) may not alias "
337-
f"any inputs or other returns. Please clone the "
338-
f"the offending output tensors (e.g. output.clone()) "
339-
f"or refactor your code. "
340-
f"Offending op: {self._name} (with implementation in {module})"
335+
f"{self._name} (with implementation in {module}): "
336+
f"The output of this custom operator (1) must not "
337+
f"also be an input to this custom operator and "
338+
f"(2) may not alias any inputs to this custom operator "
339+
f"or other returns. "
340+
f"The most common way to trigger this error is if "
341+
f"we have y = custom_op(x) and y and x are the same Tensor. "
342+
f"Please instead return a clone of the offending output "
343+
f"tensor(s) (e.g. return x.clone()) or refactor the custom "
344+
f"operator to not return y."
341345
)
342346
storages.add(key)
343347
return result

0 commit comments

Comments
 (0)