Added support for expand in LazyTensor shape inference#77830
Added support for expand in LazyTensor shape inference#77830miladm wants to merge 9 commits intopytorch:masterfrom
expand in LazyTensor shape inference#77830Conversation
🔗 Helpful links
✅ No Failures (0 Pending)As of commit df3f90d (more details on the Dr. CI page): Expand to see more💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
expand in LazyTensor shape inferenceexpand in LazyTensor shape inference
expand in LazyTensor shape inferenceexpand in LazyTensor shape inference
There was a problem hiding this comment.
how do we determine which ops to write SymIntArrayRef versions of? Is it (a) all ops that take size inputs, (b) only ops that we expect to consume outputs of dynamic ops like nonzero in models? or something else
There was a problem hiding this comment.
(b) only ops that we expect to consume outputs of dynamic ops like nonzero in models?
I believe
There was a problem hiding this comment.
ok. relatedly- how does it manifest when one is missing? presumably it would show up as a compile error. but it's not immediately clear to me how that works. Who actually calls the 'compute_shape_expand' variant with symints?
There was a problem hiding this comment.
ok. relatedly- how does it manifest when one is missing? presumably it would show up as a compile error.
I think it would show up as a runtime error when a dispatcher wouldn't be able to find a dispatch that takes a version with SymInts.
Who actually calls the 'compute_shape_expand' variant with symints?
The dispatcher. When a user passes sym ints either in python or c++, the dispatcher should dispatch to the expand overload that takes symints?
There was a problem hiding this comment.
ok. the dispatcher doesn't call compute_shape_* right?
but i think i see your point, that we would specifically implement a .symint version of a nativefunc for lazytensor, and if we did that, then we have to implement this variant of compute_shape.
|
@Krovatkin I will handle the |
Krovatkin
left a comment
There was a problem hiding this comment.
looks gut but there's one thing we need to clarify
There was a problem hiding this comment.
@miladm I thought we decided to keep -1 as a plain integer? @suo added support for this case.
I think your check should say:
_sizes[idx].is_symbolic() then do
auto lazySymIntNode = std::dynamic_pointer_cast<torch::lazy::SymbolicIntNode>(symbolicIntNode);
auto size_node = lazySymIntNode->node_;
auto static_value = std::dynamic_pointer_cast<torch::lazy::DimensionNode>(size_node)->getStaticValue();
otherwise just do _sizes[idx].data() .
There was a problem hiding this comment.
@miladm i was confused by this part, what does it mean to convert to a static value, this is a real int?
There was a problem hiding this comment.
@wconstab that's just my unfortunate naming. staticValue == upperBound.
There was a problem hiding this comment.
@miladm are you sure this is correct?
If I run the example below, PyTorch produces an error:
>>> import torch
>>> a = torch.rand(3)
>>> a.expand(-1, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: The expanded size of the tensor (-1) isn't allowed in a leading, non-existing dimension 0
while your shape inference would silently estimate target_size[0] as 0?
There was a problem hiding this comment.
Interesting. When I test on PT and PT/XLA, I don't hit your observation meaning the code errors out as expected. Perhaps my code flow doesn't hit the shape inference the way it does for you? Let me know what you ran to observe the inconsistency.
Sound good. Let's land this and open follow up issues as needed. @Krovatkin
There was a problem hiding this comment.
I think we need an extra if in here:
} else {
if (_sizes[idx].data() == -1) {
// -1 can't be specified for non-existing dimensions
TORCH_CHECK(idx >= num_new_dimensions);
target_size[idx] = padded_self[idx];
} else {
target_size[idx] = _sizes[idx];
}
}There was a problem hiding this comment.
That's correct.
I think we need to call the .data() method when assigning to target_size[idx]. Let me know if you think differently @Krovatkin.
Krovatkin
left a comment
There was a problem hiding this comment.
we will need to clarify this : https://github.com/pytorch/pytorch/pull/77830/files#r901962659 sooner or later, but let's land this version for now.
d6607c5 to
df3f90d
Compare
|
Thanks for your help @Krovatkin! |
|
@pytorchbot merge |
|
@pytorchbot successfully started a merge job. Check the current status here |
|
@miladm your PR has been successfully merged. |
|
Hey @miladm. |
…7830) Summary: Added support for `expand` in LazyTensor shape inference Fixes #77831 --- **Blockers:** - [x] #77880 - [x] #77882 Pull Request resolved: #77830 Approved by: https://github.com/Krovatkin Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/0922cc024eeafa2158c0d00396494a0ae983f8cb Reviewed By: b0noI Differential Revision: D37523035 fbshipit-source-id: 2e88e9a8a85c0a9e504fec92925cec0a05588892
Added support for `expand` in LazyTensor shape inference Fixes pytorch#77831 --- **Blockers:** - [x] pytorch#77880 - [x] pytorch#77882 Pull Request resolved: pytorch#77830 Approved by: https://github.com/Krovatkin
Added support for
expandin LazyTensor shape inferenceFixes #77831
Blockers:
DimensionNodevisible to LTC core #77880SymIntto support-1as a concreteint#77882