generated from CaiJimmy/hugo-theme-stack-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added one liner to set device pytorch
- Loading branch information
1 parent
8e1845c
commit 2ae1603
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
``` |