Skip to content
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

Add support for Intel GPU to MNIST examples #1315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions mnist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,33 @@ def main():
help='learning rate (default: 1.0)')
parser.add_argument('--gamma', type=float, default=0.7, metavar='M',
help='Learning rate step gamma (default: 0.7)')
parser.add_argument('--no-cuda', action='store_true', default=False,
parser.add_argument('--no-cuda', action='store_true',
help='disables CUDA training')
parser.add_argument('--no-mps', action='store_true', default=False,
parser.add_argument('--no-mps', action='store_true',
help='disables macOS GPU training')
parser.add_argument('--dry-run', action='store_true', default=False,
parser.add_argument('--no-xpu', action='store_true',
help='disables Intel GPU training')
parser.add_argument('--dry-run', action='store_true',
help='quickly check a single pass')
parser.add_argument('--seed', type=int, default=1, metavar='S',
help='random seed (default: 1)')
parser.add_argument('--log-interval', type=int, default=10, metavar='N',
help='how many batches to wait before logging training status')
parser.add_argument('--save-model', action='store_true', default=False,
parser.add_argument('--save-model', action='store_true',
help='For Saving the current Model')
args = parser.parse_args()
use_cuda = not args.no_cuda and torch.cuda.is_available()
use_mps = not args.no_mps and torch.backends.mps.is_available()
use_xpu = not args.no_mps and torch.xpu.is_available()

torch.manual_seed(args.seed)

if use_cuda:
device = torch.device("cuda")
elif use_mps:
device = torch.device("mps")
elif use_xpu:
device = torch.device("xpu")
else:
device = torch.device("cpu")

Expand Down
1 change: 1 addition & 0 deletions mnist_forward_forward/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ optional arguments:
--lr LR learning rate (default: 0.03)
--no_cuda disables CUDA training
--no_mps disables MPS training
--no_xpu disables XPU training
--seed SEED random seed (default: 1)
--save_model For saving the current Model
--train_size TRAIN_SIZE
Expand Down
12 changes: 8 additions & 4 deletions mnist_forward_forward/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,20 @@ def train(self, x_pos, x_neg):
help="learning rate (default: 0.03)",
)
parser.add_argument(
"--no_cuda", action="store_true", default=False, help="disables CUDA training"
"--no_cuda", action="store_true", help="disables CUDA training"
)
parser.add_argument(
"--no_mps", action="store_true", default=False, help="disables MPS training"
"--no_mps", action="store_true", help="disables MPS training"
)
parser.add_argument(
"--no_xpu", action="store_true", help="disables XPU training"
)
parser.add_argument(
"--seed", type=int, default=1, metavar="S", help="random seed (default: 1)"
)
parser.add_argument(
"--save_model",
action="store_true",
default=False,
help="For saving the current Model",
)
parser.add_argument(
Expand All @@ -126,7 +128,6 @@ def train(self, x_pos, x_neg):
parser.add_argument(
"--save-model",
action="store_true",
default=False,
help="For Saving the current Model",
)
parser.add_argument(
Expand All @@ -139,10 +140,13 @@ def train(self, x_pos, x_neg):
args = parser.parse_args()
use_cuda = not args.no_cuda and torch.cuda.is_available()
use_mps = not args.no_mps and torch.backends.mps.is_available()
use_xpu = not args.no_xpu and torch.xpu.is_available()
if use_cuda:
device = torch.device("cuda")
elif use_mps:
device = torch.device("mps")
elif use_xpu:
device = torch.device("xpu")
else:
device = torch.device("cpu")

Expand Down
17 changes: 17 additions & 0 deletions mnist_rnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,20 @@ pip install -r requirements.txt
python main.py
# CUDA_VISIBLE_DEVICES=2 python main.py # to specify GPU id to ex. 2
```

```bash
optional arguments:
-h, --help show this help message and exit
--batch_size input batch_size for training (default:64)
--testing_batch_size input batch size for testing (default: 1000)
--epochs EPOCHS number of epochs to train (default: 14)
--lr LR learning rate (default: 0.1)
--gamma learning rate step gamma (default: 0.7)
--cuda enables CUDA training
--xpu enables XPU training
--mps enables macos GPU training
--seed SEED random seed (default: 1)
--save_model For saving the current Model
--log_interval how many batches to wait before logging training status
--dry-run quickly check a single pass
```
10 changes: 7 additions & 3 deletions mnist_rnn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,26 @@ def main():
help='learning rate step gamma (default: 0.7)')
parser.add_argument('--cuda', action='store_true', default=False,
help='enables CUDA training')
parser.add_argument('--mps', action="store_true", default=False,
parser.add_argument('--mps', action="store_true",
help="enables MPS training")
parser.add_argument('--dry-run', action='store_true', default=False,
parser.add_argument('--xpu', action='store_true',
help='enables XPU training')
parser.add_argument('--dry-run', action='store_true',
help='quickly check a single pass')
parser.add_argument('--seed', type=int, default=1, metavar='S',
help='random seed (default: 1)')
parser.add_argument('--log-interval', type=int, default=10, metavar='N',
help='how many batches to wait before logging training status')
parser.add_argument('--save-model', action='store_true', default=False,
parser.add_argument('--save-model', action='store_true',
help='for Saving the current Model')
args = parser.parse_args()

if args.cuda and not args.mps:
device = "cuda"
elif args.mps and not args.cuda:
device = "mps"
elif args.xpu:
device = "xpu"
else:
device = "cpu"

Expand Down