|
15 | 15 | This tutorial is intended as a guide to the functionality that will
|
16 | 16 | be included with the 1.3 launch. By the end of it, you will be able to:
|
17 | 17 |
|
18 |
| -- Create ``Tensor``s with named dimensions, as well as remove or rename those |
| 18 | +- Create Tensors with named dimensions, as well as remove or rename those |
19 | 19 | dimensions
|
20 | 20 | - Understand the basics of how operations propagate dimension names
|
21 | 21 | - See how naming dimensions enables clearer code in two key areas:
|
@@ -192,17 +192,19 @@ def catch_error(fn):
|
192 | 192 | # broadcasted, PyTorch also checks that the names of those dimensions match.
|
193 | 193 | #
|
194 | 194 | # This results in named tensors preventing unintended alignment during
|
195 |
| -# operations that broadcast. Without ``names``, ``per_batch_scale`` would be |
196 |
| -# aligned with the last dimension of ``imgs``, which is not what we intended. |
| 195 | +# operations that broadcast. In the below example, we apply a |
| 196 | +# ``per_batch_scale`` to ``imgs``. |
197 | 197 |
|
198 | 198 | imgs = torch.randn(2, 2, 2, 2, names=('N', 'C', 'H', 'W'))
|
199 | 199 | per_batch_scale = torch.rand(2, names=('N',))
|
200 | 200 | catch_error(lambda: imgs * per_batch_scale)
|
201 | 201 |
|
202 | 202 | ######################################################################
|
203 |
| -# We really wanted to perform the operation by aligning ``per_batch_scale`` |
204 |
| -# with the batch dimension of ``imgs``. |
205 |
| -# See the new explicit broadcasting by names functionality for how to |
| 203 | +# Without ``names``, the ``per_batch_scale`` tensor is aligned with the last |
| 204 | +# dimension of ``imgs``, which is not what we intended. We really wanted to |
| 205 | +# perform the operation by aligning ``per_batch_scale`` with the batch |
| 206 | +# dimension of ``imgs``. |
| 207 | +# See the new "explicit broadcasting by names" functionality for how to |
206 | 208 | # align tensors by name, covered below.
|
207 | 209 | #
|
208 | 210 | # Matrix multiply
|
|
0 commit comments