Add Swin Transformer Example #1346
Conversation
✅ Deploy Preview for pytorch-examples-preview canceled.
|
swin_transformer/swin_transformer.py
Outdated
| use_cuda = torch.cuda.is_available() | ||
| device = torch.device("cuda" if use_cuda else "cpu") |
There was a problem hiding this comment.
It would be better to use the accelerator API
| use_cuda = torch.cuda.is_available() | |
| device = torch.device("cuda" if use_cuda else "cpu") | |
| use_accel = torch.accelerator.is_available() | |
| device = torch.accelerator.current_accelerator() if use_accel else torch.device("cpu") | |
| print(f"Using device: {device}") |
swin_transformer/README.md
Outdated
| Install dependencies: | ||
|
|
||
| ```bash | ||
| pip install torch torchvision |
There was a problem hiding this comment.
Use requirements.txt to be consistent with other examples
swin_transformer/README.md
Outdated
| Testing is done automatically after each epoch. To only test, run with: | ||
|
|
||
| ```bash | ||
| python swin_transformer.py --epochs 0 |
There was a problem hiding this comment.
I guess this should be 1 epoch
|
@jafraustro , Thanks for the review. I've updated my PR. Please have a look and lemme know if something else is needed. :)) |
|
@jafraustro can this be merged ? or does it require something else from my end? |
|
Hi @msaroufim, could you give a look to this PR? |
swin_transformer/requirements.txt
Outdated
| @@ -0,0 +1,2 @@ | |||
| torch | |||
There was a problem hiding this comment.
| torch | |
| torch>=2.6 |
Due to usage of torch.accelerator.
run_python_examples.sh
Outdated
| word_language_model/model.pt \ | ||
| gcn/cora/ \ | ||
| gat/cora/ || error "couldn't clean up some files" | ||
| swin_transformer/swin_cifar10.pt || error "couldn't clean up some files" |
There was a problem hiding this comment.
It will be failing with "command swin_transformer/swin_cifar10.pt" not found. You need to add to the list. I can't suggest the change since it touches non-modified cmdline, but code should be:
gat/cora/ \
swin_transformer/swin_cifar10.pt || error "couldn't clean up some files"
I.e. line break on gat/cora/ line.
There was a problem hiding this comment.
yep, i ran the examples and yes I had to also change the swin to swin_transformer in Line 228
swin_transformer/swin_transformer.py
Outdated
| @@ -0,0 +1,207 @@ | |||
| from __future__ import print_function | |||
There was a problem hiding this comment.
It seems script does not actually use print_function. Can this be dropped?
swin_transformer/swin_transformer.py
Outdated
| torch.save(model.state_dict(), "swin_cifar10.pt") | ||
|
|
||
| if __name__ == '__main__': | ||
| main() No newline at end of file |
There was a problem hiding this comment.
| main() | |
| main() | |
|
@dvrogozh Thanks for your reviwes, I've made the changes :) |
Co-authored-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Co-authored-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
|
@dvrogozh I have fixed as suggested. Can you PTAL? |
|
@dvrogozh can this be merged ? I can start working on another example that way |
There was a problem hiding this comment.
LGTM
@msaroufim : can you, please, take a look?
@sumantro93 : PR looks good to me now. But we need someone with merge rights to do the actual merge. I hope @msaroufim will have time to review it. |
|
Hey folks!! Any updates on this ? :) |
This reverts commit 892eca0.
Solves part of #1131
@msaroufim