Skip to content

Use torch.accelerator API in GAT example #1335

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

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions gat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ options:
--concat-heads wether to concatinate attention heads, or average over them (default: False)
--val-every VAL_EVERY
epochs to wait for print training and validation evaluation (default: 20)
--no-cuda disables CUDA training
--no-mps disables macOS GPU training
--no-accel disables accelerator
--dry-run quickly check a single pass
--seed S random seed (default: 13)
```
Expand Down
18 changes: 7 additions & 11 deletions gat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,25 @@ def test(model, criterion, input, target, mask):
help='dimension of the hidden representation (default: 64)')
parser.add_argument('--num-heads', type=int, default=8,
help='number of the attention heads (default: 4)')
parser.add_argument('--concat-heads', action='store_true', default=False,
parser.add_argument('--concat-heads', action='store_true',
help='wether to concatinate attention heads, or average over them (default: False)')
parser.add_argument('--val-every', type=int, default=20,
help='epochs to wait for print training and validation evaluation (default: 20)')
parser.add_argument('--no-cuda', action='store_true', default=False,
parser.add_argument('--no-accel', action='store_true',
help='disables CUDA training')
parser.add_argument('--no-mps', action='store_true', default=False,
help='disables macOS GPU training')
parser.add_argument('--dry-run', action='store_true', default=False,
parser.add_argument('--dry-run', action='store_true',
help='quickly check a single pass')
parser.add_argument('--seed', type=int, default=13, metavar='S',
help='random seed (default: 13)')
args = parser.parse_args()

torch.manual_seed(args.seed)
use_cuda = not args.no_cuda and torch.cuda.is_available()
use_mps = not args.no_mps and torch.backends.mps.is_available()

use_accel = not args.no_accel and torch.accelerator.is_available()

# Set the device to run on
if use_cuda:
device = torch.device('cuda')
elif use_mps:
device = torch.device('mps')
if use_accel:
device = torch.accelerator.current_accelerator()
else:
device = torch.device('cpu')
print(f'Using {device} device')
Expand Down
2 changes: 1 addition & 1 deletion gat/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
torch
requests
numpy<2
numpy