Skip to content

Commit

Permalink
Added one liner to set device pytorch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupJoseph committed Jul 22, 2023
1 parent 8e1845c commit 2ae1603
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
File renamed without changes.
2 changes: 1 addition & 1 deletion config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title = "Utils"

# Theme i18n support
# Available values: en, fr, id, ja, ko, pt-br, zh-cn, zh-tw, es, de, nl, it, th, el, uk, ar
DefaultContentLanguage = "en"
defaultContentLanguage = "en"

# Set hasCJKLanguage to true if DefaultContentLanguage is in [zh-cn ja ko]
# This will make .Summary and .WordCount behave correctly for CJK languages.
Expand Down
26 changes: 26 additions & 0 deletions content/post/device_oneliner/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Setting device in Torch
description: Simplest method to have device specific Pytorch code
slug: device_oneline
date: 22-07-2023 00:00:00+0000
categories:
- Python
- Pytorch
tags:
- python
- torch
---

A simple onliner to set device in PyTorch.
```python
import torch

device = (
"cuda"
if torch.cuda.is_available()
else "mps"
if torch.backends.mps.is_available()
else "cpu"
)
print(f"Using {device} device")
```

0 comments on commit 2ae1603

Please sign in to comment.