Skip to content

Commit 08a9bcd

Browse files
authored
Fix python custom ops tutorial (#3299)
We tightned invariants in PyTorch 2.7 that exposed a bug with the python custom ops tutorial. This PR fixes said bug. Test Plan: - tested locally
1 parent 270db76 commit 08a9bcd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

advanced_source/python_custom_ops.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ def crop(pic: torch.Tensor, box: Sequence[int]) -> torch.Tensor:
112112
def _(pic, box):
113113
channels = pic.shape[0]
114114
x0, y0, x1, y1 = box
115-
return pic.new_empty(channels, y1 - y0, x1 - x0)
115+
result = pic.new_empty(y1 - y0, x1 - x0, channels).permute(2, 0, 1)
116+
# The result should have the same metadata (shape/strides/``dtype``/device)
117+
# as running the ``crop`` function above.
118+
return result
116119

117120
######################################################################
118121
# After this, ``crop`` now works without graph breaks:

0 commit comments

Comments
 (0)