This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Xiang Gao
Recipients Xiang Gao, benjamin.peterson, christian.heimes, eric.snow, rhettinger
Date 2019-02-06.18:55:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549479341.5.0.121977992243.issue35914@roundup.psfhosted.org>
In-reply-to
Content
Hi Eric,

Thanks for your valuable information and fast reply. You understand the problem exactly correct: initially pytorch had codes like `isinstance(x, tuple)` and lots of `PyTuple_Check`, but when we start to change the return type from tuple to structseq, these checks starts to fail.

Yes, I agree generally the impact is small for this issue. Most users of PyTorch would just use the way like `values, indices = a.max(dim=0)`, which works perfectly before or after that PR. The impacts are probably mostly on libraries that use PyTorch as dependency. These libraries might have generic code that should be able to handle returns of most operators, for example, something like:

User code:
```
import torch
import a_deep_learning_library

class MyModel(torch.nn.Module):
    ......
    def forward(self, input_):
        ......
        return tensor.sum(dim=0)

model = MyModel()
a_deep_learning_library.do_something(model)
```

Code of a_deep_learning_library:
```
def do_something(model):
    input_ = prepare_input()
    output = model(input_)
    if torch.is_tensor(output):
        do_something_1(output)
    elif isinstance(output, float):
        do_something_2(output)
    elif isinstance(output, tuple):
        sum_ = sum(output)
        do_something_3(sum_)
    elif ....
```

Unpacking does not always work because it is hard to differentiate these two cases: `a, b = torch.tensor([1, 2])` and `a, b = torch.tensor([1, 2]), torch.tensor([3, 4])`, but your suggestion is very valuable.

I am neither a member of PyTorch team nor a Facebook employee. I am just a community contributor working on that issue. I will open an issue on PyTorch discussing the problem.

Thanks!
History
Date User Action Args
2019-02-06 18:55:42Xiang Gaosetrecipients: + Xiang Gao, rhettinger, christian.heimes, benjamin.peterson, eric.snow
2019-02-06 18:55:41Xiang Gaosetmessageid: <1549479341.5.0.121977992243.issue35914@roundup.psfhosted.org>
2019-02-06 18:55:41Xiang Gaolinkissue35914 messages
2019-02-06 18:55:41Xiang Gaocreate