Use updated PyTorch 0.4 tensor creation functions
See original GitHub issueRight now, we do the following kind of things to get new tensors:
bar_randn = foo.new(foo.size(-2), foo.size(-1)).normal_()
bar_zeros = foo.new(size1, size2).zeros_()
bar_inds = foo.new(size1, size2).zeros_().long()
PyTorch 0.4.0 added the following ways to do this instead that I prefer:
bar_randn = torch.randn_like(foo)
bar_zeros = foo.new_zeros(size1, size2)
bar_inds = foo.new_zeros(size1, size2, dtype=torch.long)
We could also just by carrying around a device
string instead of a tensor_cls do:
bar = torch.zeros(size1, size2, dtype=torch.long, device=device_str)
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
PyTorch 0.4.0 Migration Guide
Welcome to the migration guide for PyTorch 0.4.0. ... Scalars can be created using the new torch.tensor function (which will be explained in ......
Read more >Pytorch 0.4.0: There are three ways to create tensors on ...
All three methods worked for me. In 1 and 2, you create a tensor on CPU and then move it to GPU when...
Read more >PyTorch 0.4.0 Release & 1.0 Preview | by Ceshine Lee
Use torch.tensor to create new Tensor objects. When calling the function, assign the dtype, device, and layout with the new torch.dtype ...
Read more >documentation for sparse tensor creation after 0.4.0 update
From the 0.4.0 migration guide https://pytorch.org/2018/04/22/0_4_0-migration-guide.html dtypes, devices and NumPy-style creation functions ...
Read more >Use PyTorch with the SageMaker Python SDK
The function of installing packages using requirements.txt is supported for all PyTorch versions during training. When serving a PyTorch model, support for this ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
They already have a
device
property – I assume he meansdtype
.LazyVariables should also get a
device
property, and we should get rid of thetensor_cls
method.