Define sparse tensors with Sparse*Tensor naming for better errors.#1361
Define sparse tensors with Sparse*Tensor naming for better errors.#1361ezyang wants to merge 2 commits intopytorch:masterfrom
Conversation
53d6a2c to
01aaa11
Compare
Previously, when you got a type error involving a tensor,
you got the following message:
AttributeError: type object 'FloatTensor' has no attribute 'foo'
This error would be the same whether or not you had a sparse or
regular tensor.
With this commit, by defining the sparse tensor classes with sparse
in their name, and then creating aliases, means that now we will
see 'SparseFloatTensor' if there is an error.
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
01aaa11 to
38de41e
Compare
|
Sigh, there seems to be some magic involving names of classes which breaks when I rename to Sparse. Not sure how to proceed; fixing this might be more trouble than it's worth. |
|
I don't think it's worth giving up our name conventions just to improve these messages. We have |
|
@apaszke It would be nice if we could get errors like AttributeError to disambiguate. It can't possibly be this difficult... |
|
I agree it would be nice, but I don't think that's the correct way to do it. |
|
Maybe we could just implement our own |
|
Yes, that sounds like it could work. |
|
We could change the For example: >>> f = torch.cuda.FloatTensor()
>>> f.foobar
AttributeError: 'FloatTensor' object has no attribute 'foobar'
>>> torch.cuda.FloatTensor.__name__ = 'torch.cuda.FloatTensor'
>>> f.foobar
AttributeError: 'torch.cuda.FloatTensor' object has no attribute 'foobar'
>>> ~f
TypeError: bad operand type for unary ~: 'torch.cuda.FloatTensor' |
|
Doesn't it break pickling? I don't think playing with |
|
No, pickling doesn't use the |
|
I take that back -- it's not used by Python 3 (for any protocol), but is used by Python 2 |
…c0898c Summary: Previous import was bae6333e149a59a3faa9c4d9c44974373dcf5256 Included changes: - **[1b09eb1](onnx/onnx@1b09eb1)**: Fix the shape inference for concat (pytorch#1361) <Lu Fang> - **[7b9b3ee](onnx/onnx@7b9b3ee)**: ONNX v1.3.0 release (pytorch#1359) <bddppq> Differential Revision: D9615844 fbshipit-source-id: 65cb813a332859d95e9dd9dc7e089e2badb04039
…c0898c (#11153) Summary: Pull Request resolved: #11153 Previous import was bae6333e149a59a3faa9c4d9c44974373dcf5256 Included changes: - **[1b09eb1](onnx/onnx@1b09eb1)**: Fix the shape inference for concat (#1361) <Lu Fang> - **[7b9b3ee](onnx/onnx@7b9b3ee)**: ONNX v1.3.0 release (#1359) <bddppq> Reviewed By: Ac2zoom Differential Revision: D9615844 fbshipit-source-id: f1d4e2d6ef72a269d6ab3c1c347b272b5bdc4f2a
…c0898c (pytorch#11153) Summary: Pull Request resolved: pytorch#11153 Previous import was bae6333e149a59a3faa9c4d9c44974373dcf5256 Included changes: - **[1b09eb1](onnx/onnx@1b09eb1)**: Fix the shape inference for concat (pytorch#1361) <Lu Fang> - **[7b9b3ee](onnx/onnx@7b9b3ee)**: ONNX v1.3.0 release (pytorch#1359) <bddppq> Reviewed By: Ac2zoom Differential Revision: D9615844 fbshipit-source-id: f1d4e2d6ef72a269d6ab3c1c347b272b5bdc4f2a
Previously, when you got a type error involving a tensor,
you got the following message:
This error would be the same whether or not you had a sparse or
regular tensor.
With this commit, by defining the sparse tensor classes with sparse
in their name, and then creating aliases, means that now we will
see 'SparseFloatTensor' if there is an error.
Signed-off-by: Edward Z. Yang ezyang@fb.com