question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use updated PyTorch 0.4 tensor creation functions

See original GitHub issue

Right 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:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobrgardnercommented, Aug 15, 2018

They already have a device property – I assume he means dtype.

1reaction
gpleisscommented, Aug 15, 2018

LazyVariables should also get a device property, and we should get rid of the tensor_cls method.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found