Repository navigation
Fix non_zero cast issue - #4243
Conversation
|
Hmm, ok. This fix seems incorrect because this conflicts with the pytorch assumption where While I can cast the |
|
confirmed that in HLO, |
328a2cb to
a31e8ec
Compare
|
ok now on TPU, |
|
Quick question: in your investigation, why did you do |
|
dtype was overwritten by Lines 552 to 556 in f858155 |
a31e8ec to
01abd60
Compare
|
|
||
| def test_nonzero_cast(self): | ||
| t1 = torch.ones(5, 2, device=xm.xla_device()) | ||
| # this cast should not fail |
There was a problem hiding this comment.
mind adding a comment about where the cast happens, such as #4155 (comment).?
| torch::lazy::NodePtr node = | ||
| torch::lazy::MakeNode<NonZero>(input->GetIrValue()); | ||
| return input->CreateFrom(torch::lazy::Value(node, 0), at::ScalarType::Long); | ||
| return input->CreateFrom(torch::lazy::Value(node, 0)); |
There was a problem hiding this comment.
I assume what this CreateFrom does is: input->GetIrValue()(line1878) contains the IR graph before we add the NonZero node; then input->CreateFrom insert the NonZero node to the existing IR graph. Is my understanding correct?
There was a problem hiding this comment.
CreateFrom will create a new XLATensor using the IR node provided but it will use the same logical_element_type and device from the input tensor. I used Create here instead.
01abd60 to
3a29afa
Compare
|
@vanbasten23 Can you test if dynamic input liner model will works on PJRT + TPU? @will-cromar had a bug open for supporting dynamic shape + PJRT so we want to figure out the gap here. |
How can I test it on PJRT+TPU? Is it by setting |
|
Right. All you need to do is set |
|
I am able to repo the GPU failure with and the error is expected I guess I will cast both to s64 before doing the |
|
adding a I will post a fix. |
I tested the forward pass model on PJRT+TPU and it works fine. The model returns a different loss each time I run. But this problem exists for both XRT and PJRT, so I think it might be an issue with the model itself. @JackCaoG @will-cromar |
|
hmm @vanbasten23 if we fixed the input we should see the same result every time. Can you look into why that's not the case? We need to confirm that |
Yeah, I'm already looking into it. Will let you know if I find anything. |
|
Not directly related to this pr but do you know why xla/torch_xla/csrc/ops/nonzero.cpp Line 27 in d668f2c |
if you look at the lowering, it returns 2 XLAOP. However second XLAOP was discarded. I am not sure why that's the case. |
I figured out why the loss varies each time. By default, the weights in each layer has some randomization. So to make the loss deterministic and make it easy to write test, I need to initialize the weights explicitly by myself. I've updated the model here. |
|
@JackCaoG in the first comment of this pr, you mentioned I ran the test in my pr and dump the HLO graph: It looks getDimensionSize returns s32. |
|
yea, I decided to make the SizeNode to be s32 on TPU instead, so we are honest about the real underlying type and avoid additional casting. |
This will fix #4155
TODO: verify if
getDimensionSizeactually return as64, if not I might need to do a cast tos64.FYI @Krovatkin @vanbasten23