-
Notifications
You must be signed in to change notification settings - Fork 4.2k
GH-33923: [Docs] Tensor canonical extension type specification #33925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
af571cb
8231150
884d871
83edd70
16ef6f1
4f4ccce
92fd7c6
7873676
a4219e3
37e83db
5c92ff0
cb5e2dd
b562b8d
c44101b
24e7c28
333ae67
4086dfb
bd2a515
bc07d7a
68c6244
3e2bb25
a49f14f
89d8042
4ff7a65
1daf820
70059d9
6f44296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,4 +72,26 @@ same rules as laid out above, and provide backwards compatibility guarantees. | |
| Official List | ||
| ============= | ||
|
|
||
| No canonical extension types have been standardized yet. | ||
| Fixed size tensor | ||
| ================= | ||
|
|
||
| * Extension name: `arrow.fixed_size_tensor`. | ||
|
|
||
| * The storage type of the extension: ``FixedSizeList``. | ||
|
AlenkaF marked this conversation as resolved.
Outdated
|
||
|
|
||
| * Extension type parameters: | ||
|
|
||
| * **value_type** = Arrow DataType of the tensor elements | ||
| * **shape** = shape of the contained tensors as a tuple | ||
|
AlenkaF marked this conversation as resolved.
Outdated
|
||
| * **is_row_major** = boolean indicating the order of elements | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not store
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Zulip discussion we are leaning towards canonical type always storing row-major and letting applications store strides in metadata. Any arguments for or against from you or your users would be most welcome at this point! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you mean removing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. We would just use the physical layout of the source and not change memory layout when going in and out of the extension. We would provide an option to store the layout as metadata.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My understanding is that contiguous tensors in torch are indeed always row-major, but so that also means that if you have such a contiguous tensor, you don't need any copy to put this in the proposed extension TensorArray (or you can get it out without a copy). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if that helps the discussion: import torch
def get_1d_memory_buffer(tensor):
return "".join(hex(elt) for elt in tensor.storage().untyped().byte())
x = torch.randn(2,3)
y = torch.empty(3,2).transpose(0,1)
# Fill y with x data
y[:] = x
assert x.shape == y.shape
assert get_1d_memory_buffer(x) != get_1d_memory_buffer(y)
# You can try printing `x` and `y` and you'll see that the tensors are the same
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but both of those use row-major / C-contiguous memory layout. What you change is the order of the dimensions (C-H-W or H-W-C), and to do that while keeping row-major layout, changing between channels first/last layout requires actually shuffling the data in memory (and thus requires a copy). But either "physical order" is row-major and thus can be stored in the proposed FixedShapeTensor array without copy.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For your example, But you could still store both x and y without copy in a FixedShapeTensor array. The difference is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw I fixed a bug in my script ...
I understand that there exist a permutation of dimensions that allows me to get a "row major" format. I think it doesn't change how you store the permutation information, ie via dimension names or stride. It felt like a natural concept to me to store
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I understand (we might have been talking past each other a bit, as I was assuming you want to have It's certainly true that we could store strides, but I am not sure it would be a better generalization of (or a full replacement for) dimension names. So my current understanding is that dimension names are the more generalizable information. In addition, pushing the strides logic (how to translate the given dimension order and your desired dimension order to strides) to the application to deal with, keeps the implementation of the FixedShapeTensorType itself simpler, not requiring every implementation to deal with custom strides. |
||
| in memory | ||
|
|
||
| * Description of the serialization: | ||
|
|
||
| The metadata must be a valid JSON object including: | ||
|
|
||
| * shape of the contained tensors as an array with key "shape", | ||
| * boolean indicating the order of elements in memory with key | ||
| "is_row_major". | ||
|
|
||
| For example: `{ "shape": [2, 5], "is_row_major": True }` | ||
Uh oh!
There was an error while loading. Please reload this page.