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.

Replace mentions of `.type_as()` in our docs

See original GitHub issue

📚 Documentation

As a follow up to #2585, we should consider removing mentions of the .type_as() syntax in our docs and replace it with best practices for device placement and type conversion.


If you enjoy Lightning, check out our other projects! ⚡

  • Metrics: Machine learning metrics for distributed, scalable PyTorch applications.

  • Lite: enables pure PyTorch users to scale their existing code on any kind of device while retaining full control over their own loops and optimization logic.

  • Flash: The fastest way to get a Lightning baseline! A collection of tasks for fast prototyping, baselining, fine-tuning, and solving problems with deep learning.

  • Bolts: Pretrained SOTA Deep Learning models, callbacks, and more for research and production with PyTorch Lightning and PyTorch.

  • Lightning Transformers: Flexible interface for high-performance research using SOTA Transformers leveraging PyTorch Lightning, Transformers, and Hydra.

cc @borda @rohitgr7 @Felonious-Spellfire

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nsarangcommented, Sep 6, 2022

Tensor.to can be used as a safe replacement for type_as. It also accepts another tensor as input.

From the documentation:

torch.to(other, non_blocking=False, copy=False) → Tensor Returns a Tensor with same torch.dtype and torch.device as the Tensor other. When non_blocking, tries to convert asynchronously with respect to the host if possible, e.g., converting a CPU Tensor with pinned memory to a CUDA Tensor. When copy is set, a new Tensor is created even when the Tensor already matches the desired conversion.

1reaction
yipliucommented, Sep 6, 2022

For me, I often use the following methods

# As the LightningModule, self.deivce is known
torch.zeros(B, S, device=self.device)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Find and Replace Any Text in Your Documents - Zapier
Type in what you're looking for, and Docs will highlight every mention in your document. You can then replace everything at once, ...
Read more >
Search and use find and replace - Google Docs Editors Help
You can find and replace words in a document, spreadsheet, or presentation with Google Docs, Sheets, and Slides. You can also search within...
Read more >
Find and replace in project | CLion Documentation - JetBrains
In the Find in Files dialog, select the File Mask checkbox and from the list of file types, select the one you need....
Read more >
String.prototype.replaceAll() - JavaScript - MDN Web Docs
The replaceAll() method returns a new string with all matches of a pattern replaced by a replacement . The pattern can be a...
Read more >
Switch between relative, absolute, and mixed references
In the formula bar Button image , select the reference that you want to change. Press F4 to switch between the reference types....
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