Skip to content

Use fully qualified name as tp_name for tensors and storages#1379

Merged
colesbury merged 1 commit intopytorch:masterfrom
colesbury:names
Apr 27, 2017
Merged

Use fully qualified name as tp_name for tensors and storages#1379
colesbury merged 1 commit intopytorch:masterfrom
colesbury:names

Conversation

@colesbury
Copy link
Member

Currently, AttributeErrors on tensors and storages are ambiguous. It's unclear if they refer to the CUDA, sparse, or regular CPU classes:

>>> torch.FloatTensor().foobar
AttributeError: 'FloatTensor' object has no attribute 'foobar'

Types defined in C don't have this problem because their tp_name field contains the fully qualified name:

>>> torch._C.FloatTensorBase().foobar
AttributeError: 'torch._C.FloatTensorBase' object has no attribute 'foobar'

This changes the tp_name field on the Tensor and Storage classes to be their fully qualified name. The __name__ attribute is still the "simple" class name, which is necessary for pickling in Python 2. This matches the behavior for types defined in C:

>>> torch.FloatTensor().foobar
AttributeError: 'torch.FloatTensor' object has no attribute 'foobar'
>>> torch.cuda.FloatTensor().foobar
AttributeError: 'torch.cuda.FloatTensor' object has no attribute 'foobar'
>>> ~torch.cuda.FloatTensor()
TypeError: bad operand type for unary ~: 'torch.cuda.FloatTensor'

@colesbury
Copy link
Member Author

An alternative way of achieving the same effect would be to define the concrete Tensor and Storage classes in C instead of Python, but you'd be basically doing the same thing: setting the tp_name to the fully qualified name.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@colesbury colesbury merged commit 27990fe into pytorch:master Apr 27, 2017
@colesbury colesbury deleted the names branch April 27, 2017 20:36
Jiaming-Liu pushed a commit to Jiaming-Liu/pytorch that referenced this pull request May 18, 2017
jjsjann123 pushed a commit to jjsjann123/pytorch that referenced this pull request Jan 26, 2022
* Have Kernel Inherit IrContainer (pytorch#1375)
* Kernel<-Fusion Step 1 - Convert ExprSort to StmtSort (pytorch#1376)
* Kernel<-Fusion Step 2 - Mutator refactor (pytorch#1377)
* Kernel<-Fusion Step 3 - Debug print for expr_eval and type promotion fix (pytorch#1379)
* Kernel<-Fusion Step 4 - Have kernel inherit Fusion (pytorch#1380)
* Kernel<-Fusion Step 5 - Move lowering passes into their own files (pytorch#1382)
* Kernel<-Fusion Step 6 - Remove kir::IrBuilder (pytorch#1383)
* Kernel<-Fusion Step 7 - Remove kir functions from ComputeAtMap (pytorch#1384)
* Kernel<-Fusion Step 8 - Clean up [lower/executor] utils (pytorch#1387)
* Kernel<-Fusion Step 9 - Remove TensorView::fuserTv (pytorch#1388)
* Kernel<-Fusion Step 10 - Remove lowerVal/lowerExpr (pytorch#1389)
* Kernel<-Fusion Step 11 - Finish cleaning up kir (pytorch#1390)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants