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/fast_neural_style/README.md b/fast_neural_style/README.md index 8057847214..674cf7e7f0 100644 --- a/fast_neural_style/README.md +++ b/fast_neural_style/README.md @@ -28,6 +28,7 @@ python neural_style/neural_style.py eval --content-image Loading datasets') train_set = get_training_set(opt.upscale_factor) diff --git a/super_resolution/super_resolve.py b/super_resolution/super_resolve.py index 750d635312..2db3d5297d 100644 --- a/super_resolution/super_resolve.py +++ b/super_resolution/super_resolve.py @@ -12,6 +12,7 @@ parser.add_argument('--model', type=str, required=True, help='model file to use') parser.add_argument('--output_filename', type=str, help='where to save the output image') parser.add_argument('--cuda', action='store_true', help='use cuda') +parser.add_argument('--device', type=str, default='cpu', help='backend device') opt = parser.parse_args() print(opt) @@ -25,6 +26,9 @@ if opt.cuda: model = model.cuda() input = input.cuda() +elif opt.device: + model = model.to(opt.device) + input = input.to(opt.device) out = model(input) out = out.cpu() diff --git a/vae/README.md b/vae/README.md index cda6a33672..393776f219 100644 --- a/vae/README.md +++ b/vae/README.md @@ -12,10 +12,11 @@ The main.py script accepts the following arguments: ```bash optional arguments: - --batch-size input batch size for training (default: 128) - --epochs number of epochs to train (default: 10) - --no-cuda enables CUDA training - --mps enables GPU on macOS - --seed random seed (default: 1) - --log-interval how many batches to wait before logging training status -``` \ No newline at end of file + --batch-size N input batch size for training (default: 128) + --epochs EPOCHS number of epochs to train (default: 10) + --no-cuda disables CUDA training + --no-mps disables macOS GPU training + --device DEVICE backend name + --seed SEED random seed (default: 1) + --log-interval N how many batches to wait before logging training status +``` diff --git a/vae/main.py b/vae/main.py index d69833fbe0..a49efe4fdd 100644 --- a/vae/main.py +++ b/vae/main.py @@ -17,6 +17,8 @@ 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('--seed', type=int, default=1, metavar='S', help='random seed (default: 1)') parser.add_argument('--log-interval', type=int, default=10, metavar='N', @@ -32,7 +34,7 @@ elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(args.device) kwargs = {'num_workers': 1, 'pin_memory': True} if args.cuda else {} train_loader = torch.utils.data.DataLoader( diff --git a/word_language_model/README.md b/word_language_model/README.md index 254b726585..ca217399c8 100644 --- a/word_language_model/README.md +++ b/word_language_model/README.md @@ -37,6 +37,7 @@ optional arguments: --seed SEED random seed --cuda use CUDA --mps enable GPU on macOS + --device DEVICE backend device --log-interval N report interval --save SAVE path to save the final model --onnx-export ONNX_EXPORT @@ -54,3 +55,9 @@ python main.py --cuda --emsize 650 --nhid 650 --dropout 0.5 --epochs 40 --tied python main.py --cuda --emsize 1500 --nhid 1500 --dropout 0.65 --epochs 40 python main.py --cuda --emsize 1500 --nhid 1500 --dropout 0.65 --epochs 40 --tied ``` + +You can also use non-cuda devices like this: + +```bash +python main.py --device npu --emsize 650 --nhid 650 --dropout 0.5 --epochs 40 +``` diff --git a/word_language_model/generate.py b/word_language_model/generate.py index 13bd8abfcd..c201e3ff21 100644 --- a/word_language_model/generate.py +++ b/word_language_model/generate.py @@ -23,6 +23,8 @@ help='random seed') parser.add_argument('--cuda', action='store_true', help='use CUDA') +parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--mps', action='store_true', default=False, help='enables macOS GPU training') parser.add_argument('--temperature', type=float, default=1.0, @@ -46,7 +48,7 @@ elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(args.device) if args.temperature < 1e-3: parser.error("--temperature has to be greater or equal 1e-3.") diff --git a/word_language_model/main.py b/word_language_model/main.py index 23bda03e73..71c4446003 100644 --- a/word_language_model/main.py +++ b/word_language_model/main.py @@ -40,7 +40,9 @@ parser.add_argument('--cuda', action='store_true', default=False, help='use CUDA') parser.add_argument('--mps', action='store_true', default=False, - help='enables macOS GPU training') + help='enables macOS GPU training') +parser.add_argument('--device', type=str, default='cpu', + help='backend device') parser.add_argument('--log-interval', type=int, default=200, metavar='N', help='report interval') parser.add_argument('--save', type=str, default='model.pt', @@ -68,7 +70,7 @@ elif use_mps: device = torch.device("mps") else: - device = torch.device("cpu") + device = torch.device(args.device) ############################################################################### # Load data