Skip to content

Use torch.accelerator API in Fast Neural Style example #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dvrogozh
Copy link

torch.accelerator API allows to abstract some of the accelerator specifics in the user scripts. This commit modifies Fast Neural Style example with the mentioned API.

Things to note:

  • Commit modifies example command line by replacing accelerator specific flags (--cuda, --mps, --xpu) with the --accel.
  • torch.accelerator API appeared in pytorch 2.6, so commit binds example to this torch version

CC: @malfet, @atalman

Copy link

netlify bot commented Apr 18, 2025

Deploy Preview for pytorch-examples-preview canceled.

Name Link
🔨 Latest commit fc85412
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-examples-preview/deploys/680290d29e392d0008d6d6b3

@msaroufim
Copy link
Member

Cool! Although looks like you're not using the right pytorch version quite yet, you can be explicit see how we use requirements.txt in the repo within given folders

@dvrogozh
Copy link
Author

I think I might need help with the requirements part of the story. Here is a snapshot of what was executed by ci (https://github.com/pytorch/examples/actions/runs/14539355819/job/40795679639?pr=1327):

2025-04-18T18:32:00.6714511Z Collecting torch
2025-04-18T18:32:00.7041753Z   Downloading torch-2.6.0-cp310-cp310-manylinux1_x86_64.whl.metadata (28 kB)
...
2025-04-18T18:33:28.7956634Z installing requirements
...
2025-04-18T18:33:39.0976123Z Collecting torch>=2 (from torchdata==0.9.0->-r /dev/stdin (line 16))
2025-04-18T18:33:39.1017813Z   Downloading torch-2.5.0-cp310-cp310-manylinux1_x86_64.whl.metadata (28 kB)
...
2025-04-18T18:34:04.9822716Z   Attempting uninstall: torch
2025-04-18T18:34:04.9832302Z     Found existing installation: torch 2.6.0
2025-04-18T18:34:05.3568406Z     Uninstalling torch-2.6.0:
2025-04-18T18:34:05.4241262Z       Successfully uninstalled torch-2.6.0
...
2025-04-18T18:34:37.8267387Z AttributeError: module 'torch' has no attribute 'accelerator'

I think that CI attempted to test the latest nightly, at least this implies that:

pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html

Then, test shell script downgraded already installed nightly torch to version 2.5.0. My guess is due to pinned version of torchvision in some of the requirements.txt files:

torchvision==0.20.0

Also note:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants