From 113d9a1a678ed3fbaa87c7efe13f512af0556049 Mon Sep 17 00:00:00 2001 From: Yuanhao Ji Date: Fri, 20 Sep 2024 10:31:47 +0800 Subject: [PATCH 1/6] add --device - dcgan - gat - gcn - language_translation --- dcgan/README.md | 3 ++- dcgan/main.py | 3 ++- gat/README.md | 3 ++- gat/main.py | 4 +++- gcn/main.py | 4 +++- language_translation/main.py | 8 ++++---- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/dcgan/README.md b/dcgan/README.md index 3f7bdef6b1..b921bb7e22 100644 --- a/dcgan/README.md +++ b/dcgan/README.md @@ -24,7 +24,7 @@ usage: main.py [-h] --dataset DATASET --dataroot DATAROOT [--workers WORKERS] [--batchSize BATCHSIZE] [--imageSize IMAGESIZE] [--nz NZ] [--ngf NGF] [--ndf NDF] [--niter NITER] [--lr LR] [--beta1 BETA1] [--cuda] [--ngpu NGPU] [--netG NETG] - [--netD NETD] [--mps] + [--netD NETD] [--mps] [--device DEVICE] optional arguments: -h, --help show this help message and exit @@ -41,6 +41,7 @@ optional arguments: --beta1 BETA1 beta1 for adam. default=0.5 --cuda enables cuda --mps enables macOS GPU + --device backend device --ngpu NGPU number of GPUs to use --netG NETG path to netG (to continue training) --netD NETD path to netD (to continue training) diff --git a/dcgan/main.py b/dcgan/main.py index 2f45b2dbd2..9416893856 100644 --- a/dcgan/main.py +++ b/dcgan/main.py @@ -34,6 +34,7 @@ parser.add_argument('--manualSeed', type=int, help='manual seed') parser.add_argument('--classes', default='bedroom', help='comma separated list of classes for the lsun data set') parser.add_argument('--mps', action='store_true', default=False, help='enables macOS GPU training') +parser.add_argument('--device', type=str, default='cpu', help='backend device') opt = parser.parse_args() print(opt) @@ -112,7 +113,7 @@ elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(opt.device) ngpu = int(opt.ngpu) nz = int(opt.nz) diff --git a/gat/README.md b/gat/README.md index 7bb71bc17b..f4d6848331 100644 --- a/gat/README.md +++ b/gat/README.md @@ -69,7 +69,7 @@ python main.py --epochs 300 --lr 0.005 --l2 5e-4 --dropout-p 0.6 --num-heads 8 - In more detail, the `main.py` script recieves following arguments: ``` usage: main.py [-h] [--epochs EPOCHS] [--lr LR] [--l2 L2] [--dropout-p DROPOUT_P] [--hidden-dim HIDDEN_DIM] [--num-heads NUM_HEADS] [--concat-heads] [--val-every VAL_EVERY] - [--no-cuda] [--no-mps] [--dry-run] [--seed S] + [--no-cuda] [--no-mps] [--dry-run] [--seed S] [--device DEVICE] PyTorch Graph Attention Network @@ -89,6 +89,7 @@ options: epochs to wait for print training and validation evaluation (default: 20) --no-cuda disables CUDA training --no-mps disables macOS GPU training + --device DEVICE backend device --dry-run quickly check a single pass --seed S random seed (default: 13) ``` diff --git a/gat/main.py b/gat/main.py index 9c143af8ec..d70e380c94 100644 --- a/gat/main.py +++ b/gat/main.py @@ -311,6 +311,8 @@ def test(model, criterion, input, target, mask): help='disables CUDA training') parser.add_argument('--no-mps', action='store_true', default=False, help='disables macOS GPU training') + parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--dry-run', action='store_true', default=False, help='quickly check a single pass') parser.add_argument('--seed', type=int, default=13, metavar='S', @@ -327,7 +329,7 @@ def test(model, criterion, input, target, mask): elif use_mps: device = torch.device('mps') else: - device = torch.device('cpu') + device = torch.device(args.device) print(f'Using {device} device') # Load the dataset diff --git a/gcn/main.py b/gcn/main.py index 5c8362b576..049129f64b 100644 --- a/gcn/main.py +++ b/gcn/main.py @@ -220,6 +220,8 @@ def test(model, criterion, input, target, mask): help='disables CUDA training') parser.add_argument('--no-mps', action='store_true', default=False, help='disables macOS GPU training') + parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--dry-run', action='store_true', default=False, help='quickly check a single pass') parser.add_argument('--seed', type=int, default=42, metavar='S', @@ -236,7 +238,7 @@ def test(model, criterion, input, target, mask): elif use_mps: device = torch.device('mps') else: - device = torch.device('cpu') + device = torch.device(args.device) print(f'Using {device} device') cora_url = 'https://linqs-data.soe.ucsc.edu/public/lbc/cora.tgz' diff --git a/language_translation/main.py b/language_translation/main.py index 2b4fbb94c3..3e82748556 100644 --- a/language_translation/main.py +++ b/language_translation/main.py @@ -272,9 +272,9 @@ def main(opts): help="Default learning rate") parser.add_argument("--batch", type=int, default=128, help="Batch size") - parser.add_argument("--backend", type=str, default="cpu", - help="Batch size") - + parser.add_argument("--device", type=str, default="cpu", + help="backend device") + # Transformer settings parser.add_argument("--attn_heads", type=int, default=8, help="Number of attention heads") @@ -298,7 +298,7 @@ def main(opts): args = parser.parse_args() - DEVICE = torch.device("cuda" if args.backend == "gpu" and torch.cuda.is_available() else "cpu") + DEVICE = torch.device("cuda" if args.device == "gpu" and torch.cuda.is_available() else args.device) if args.inference: inference(args) From 60e926ff63aa90bd2fe08bd4f316028f9afe2d53 Mon Sep 17 00:00:00 2001 From: Yuanhao Ji Date: Fri, 20 Sep 2024 09:38:38 +0800 Subject: [PATCH 2/6] add --device for legacy/snli --- legacy/snli/README.md | 2 +- legacy/snli/train.py | 2 +- legacy/snli/util.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/legacy/snli/README.md b/legacy/snli/README.md index 2da5104975..a7d2927c10 100644 --- a/legacy/snli/README.md +++ b/legacy/snli/README.md @@ -25,7 +25,7 @@ spacy Start the training process with: ```bash -python train.py --lower --word-vectors [PATH_TO_WORD_VECTORS] --vector-cache [PATH_TO_VECTOR_CACHE] --epochs [NUMBER_OF_EPOCHS] --batch-size [BATCH_SIZE] --save-path [PATH_TO_SAVE_MODEL] --gpu [GPU_NUMBER] +python train.py --lower --word-vectors [PATH_TO_WORD_VECTORS] --vector-cache [PATH_TO_VECTOR_CACHE] --epochs [NUMBER_OF_EPOCHS] --batch-size [BATCH_SIZE] --save-path [PATH_TO_SAVE_MODEL] --gpu [GPU_NUMBER] --device [BACKEND_DEVICE] ``` ## 🏋️‍♀️ Training diff --git a/legacy/snli/train.py b/legacy/snli/train.py index aa70aef45a..f664ffdfbd 100644 --- a/legacy/snli/train.py +++ b/legacy/snli/train.py @@ -20,7 +20,7 @@ elif torch.backends.mps.is_available(): device = torch.device('mps') else: - device = torch.device('cpu') + device = torch.device(args.device) inputs = data.Field(lower=args.lower, tokenize='spacy') answers = data.Field(sequential=False) diff --git a/legacy/snli/util.py b/legacy/snli/util.py index 1bc8e0b2cc..4e2b488767 100644 --- a/legacy/snli/util.py +++ b/legacy/snli/util.py @@ -20,6 +20,8 @@ def makedirs(name): def get_args(): parser = ArgumentParser(description='PyTorch/torchtext SNLI example') + parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--epochs', type=int, default=50, help='the number of total epochs to run.') parser.add_argument('--batch_size', type=int, default=128, From afd756cd361b31620a6bd4c2927dd83d098693c7 Mon Sep 17 00:00:00 2001 From: Yuanhao Ji Date: Fri, 20 Sep 2024 09:32:14 +0800 Subject: [PATCH 3/6] add --device for mnist --- mnist/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mnist/main.py b/mnist/main.py index 184dc4744f..d00cbb67c0 100644 --- a/mnist/main.py +++ b/mnist/main.py @@ -86,6 +86,8 @@ def main(): help='disables CUDA training') parser.add_argument('--no-mps', action='store_true', default=False, help='disables macOS GPU training') + parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--dry-run', action='store_true', default=False, help='quickly check a single pass') parser.add_argument('--seed', type=int, default=1, metavar='S', @@ -105,7 +107,7 @@ def main(): elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(args.device) train_kwargs = {'batch_size': args.batch_size} test_kwargs = {'batch_size': args.test_batch_size} From bdb4fc580dcf7402cf7dde93b1d3175b756ead67 Mon Sep 17 00:00:00 2001 From: Yuanhao Ji Date: Thu, 19 Sep 2024 20:18:26 +0800 Subject: [PATCH 4/6] add --device for mnist_rnn --- mnist_rnn/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mnist_rnn/main.py b/mnist_rnn/main.py index 2fa64c00d6..c77191ce8c 100644 --- a/mnist_rnn/main.py +++ b/mnist_rnn/main.py @@ -95,6 +95,8 @@ def main(): help='enables CUDA training') parser.add_argument('--mps', action="store_true", default=False, help="enables MPS training") + parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--dry-run', action='store_true', default=False, help='quickly check a single pass') parser.add_argument('--seed', type=int, default=1, metavar='S', @@ -110,7 +112,7 @@ def main(): elif args.mps and not args.cuda: device = "mps" else: - device = "cpu" + device = args.device device = torch.device(device) From fd0417f53739867110aa87a5651ed598902ce8ba Mon Sep 17 00:00:00 2001 From: Yuanhao Ji Date: Fri, 20 Sep 2024 09:28:57 +0800 Subject: [PATCH 5/6] add --device for mnist_forward_forward --- mnist_forward_forward/README.md | 1 + mnist_forward_forward/main.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mnist_forward_forward/README.md b/mnist_forward_forward/README.md index f6ae12e56d..6a8f70aace 100644 --- a/mnist_forward_forward/README.md +++ b/mnist_forward_forward/README.md @@ -18,6 +18,7 @@ optional arguments: --lr LR learning rate (default: 0.03) --no_cuda disables CUDA training --no_mps disables MPS training + --device DEVICE backend device --seed SEED random seed (default: 1) --save_model For saving the current Model --train_size TRAIN_SIZE diff --git a/mnist_forward_forward/main.py b/mnist_forward_forward/main.py index f137dee48a..3702b213ea 100644 --- a/mnist_forward_forward/main.py +++ b/mnist_forward_forward/main.py @@ -108,6 +108,9 @@ def train(self, x_pos, x_neg): parser.add_argument( "--no_mps", action="store_true", default=False, help="disables MPS training" ) + parser.add_argument( + '--device', type=str, default='cpu', help='backend device' + ) parser.add_argument( "--seed", type=int, default=1, metavar="S", help="random seed (default: 1)" ) @@ -145,7 +148,7 @@ def train(self, x_pos, x_neg): elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(args.device) train_kwargs = {"batch_size": args.train_size} test_kwargs = {"batch_size": args.test_size} From 6b50ebc9f7acbc6e82d47a8d63fa351825dd2531 Mon Sep 17 00:00:00 2001 From: Yuanhao Ji Date: Fri, 20 Sep 2024 09:23:52 +0800 Subject: [PATCH 6/6] add --device for mnist_hogwild --- mnist_hogwild/README.md | 1 + mnist_hogwild/main.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mnist_hogwild/README.md b/mnist_hogwild/README.md index 5f12161d53..361ff43415 100644 --- a/mnist_hogwild/README.md +++ b/mnist_hogwild/README.md @@ -21,6 +21,7 @@ optional arguments: --log_interval how many batches to wait before logging training status --num_process how many training processes to use (default: 2) --cuda enables CUDA training + --device DEVICE backend device --dry-run quickly check a single pass --save-model For Saving the current Model ``` diff --git a/mnist_hogwild/main.py b/mnist_hogwild/main.py index 6fa449233d..6af0c4da71 100644 --- a/mnist_hogwild/main.py +++ b/mnist_hogwild/main.py @@ -31,6 +31,8 @@ help='enables CUDA training') parser.add_argument('--mps', action='store_true', default=False, help='enables macOS GPU training') +parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--save_model', action='store_true', default=False, help='save the trained model to state_dict') parser.add_argument('--dry-run', action='store_true', default=False, @@ -65,7 +67,7 @@ def forward(self, x): elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(args.device) transform=transforms.Compose([ transforms.ToTensor(),