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

Replace hardcoded default values in argparse help strings #1290

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
8 changes: 4 additions & 4 deletions distributed/FSDP/T5_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ def fsdp_main(args):
# Training settings
parser = argparse.ArgumentParser(description='PyTorch T5 FSDP Example')
parser.add_argument('--batch-size', type=int, default=4, metavar='N',
help='input batch size for training (default: 64)')
help='input batch size for training (default: %(default)s)')
parser.add_argument('--test-batch-size', type=int, default=4, metavar='N',
help='input batch size for testing (default: 1000)')
help='input batch size for testing (default: %(default)s)')
parser.add_argument('--epochs', type=int, default=2, metavar='N',
help='number of epochs to train (default: 3)')
help='number of epochs to train (default: %(default)s)')
parser.add_argument('--seed', type=int, default=1, metavar='S',
help='random seed (default: 1)')
help='random seed (default: %(default)s)')
parser.add_argument('--track_memory', action='store_false', default=True,
help='track the gpu memory')
parser.add_argument('--run_validation', action='store_false', default=True,
Expand Down
3 changes: 2 additions & 1 deletion distributed/ddp-tutorial-series/multigpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def main(rank: int, world_size: int, save_every: int, total_epochs: int, batch_s
parser = argparse.ArgumentParser(description='simple distributed training job')
parser.add_argument('total_epochs', type=int, help='Total epochs to train the model')
parser.add_argument('save_every', type=int, help='How often to save a snapshot')
parser.add_argument('--batch_size', default=32, type=int, help='Input batch size on each device (default: 32)')
parser.add_argument('--batch_size', default=32, type=int,
help='Input batch size on each device (default: %(default)s)')
args = parser.parse_args()

world_size = torch.cuda.device_count()
Expand Down
3 changes: 2 additions & 1 deletion distributed/ddp-tutorial-series/multigpu_torchrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def main(save_every: int, total_epochs: int, batch_size: int, snapshot_path: str
parser = argparse.ArgumentParser(description='simple distributed training job')
parser.add_argument('total_epochs', type=int, help='Total epochs to train the model')
parser.add_argument('save_every', type=int, help='How often to save a snapshot')
parser.add_argument('--batch_size', default=32, type=int, help='Input batch size on each device (default: 32)')
parser.add_argument('--batch_size', default=32, type=int,
help='Input batch size on each device (default: %(default)s)')
args = parser.parse_args()

main(args.save_every, args.total_epochs, args.batch_size)
3 changes: 2 additions & 1 deletion distributed/ddp-tutorial-series/multinode.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def main(save_every: int, total_epochs: int, batch_size: int, snapshot_path: str
parser = argparse.ArgumentParser(description='simple distributed training job')
parser.add_argument('total_epochs', type=int, help='Total epochs to train the model')
parser.add_argument('save_every', type=int, help='How often to save a snapshot')
parser.add_argument('--batch_size', default=32, type=int, help='Input batch size on each device (default: 32)')
parser.add_argument('--batch_size', default=32, type=int,
help='Input batch size on each device (default: %(default)s)')
args = parser.parse_args()

main(args.save_every, args.total_epochs, args.batch_size)
7 changes: 4 additions & 3 deletions distributed/ddp-tutorial-series/single_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(
train_data: DataLoader,
optimizer: torch.optim.Optimizer,
gpu_id: int,
save_every: int,
save_every: int,
) -> None:
self.gpu_id = gpu_id
self.model = model.to(gpu_id)
Expand Down Expand Up @@ -75,8 +75,9 @@ def main(device, total_epochs, save_every, batch_size):
parser = argparse.ArgumentParser(description='simple distributed training job')
parser.add_argument('total_epochs', type=int, help='Total epochs to train the model')
parser.add_argument('save_every', type=int, help='How often to save a snapshot')
parser.add_argument('--batch_size', default=32, type=int, help='Input batch size on each device (default: 32)')
parser.add_argument('--batch_size', default=32, type=int,
help='Input batch size on each device (default: %(default)s)')
args = parser.parse_args()

device = 0 # shorthand for cuda:0
main(device, args.total_epochs, args.save_every, args.batch_size)
6 changes: 3 additions & 3 deletions distributed/rpc/batch/reinforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

parser = argparse.ArgumentParser(description='PyTorch RPC Batch RL example')
parser.add_argument('--gamma', type=float, default=1.0, metavar='G',
help='discount factor (default: 1.0)')
help='discount factor (default: %(default)s)')
parser.add_argument('--seed', type=int, default=543, metavar='N',
help='random seed (default: 543)')
help='random seed (default: %(default)s)')
parser.add_argument('--num-episode', type=int, default=10, metavar='E',
help='number of episodes (default: 10)')
help='number of episodes (default: %(default)s)')
args = parser.parse_args()

torch.manual_seed(args.seed)
Expand Down
6 changes: 3 additions & 3 deletions distributed/rpc/rl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
parser.add_argument('--world-size', type=int, default=2, metavar='W',
help='world size for RPC, rank 0 is the agent, others are observers')
parser.add_argument('--gamma', type=float, default=0.99, metavar='G',
help='discount factor (default: 0.99)')
help='discount factor (default: %(default)s)')
parser.add_argument('--seed', type=int, default=543, metavar='N',
help='random seed (default: 543)')
help='random seed (default: %(default)s)')
parser.add_argument('--log-interval', type=int, default=10, metavar='N',
help='interval between training status logs (default: 10)')
help='interval between training status logs (default: %(default)s)')
args = parser.parse_args()

torch.manual_seed(args.seed)
Expand Down
20 changes: 10 additions & 10 deletions gat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,29 +292,29 @@ def test(model, criterion, input, target, mask):

parser = argparse.ArgumentParser(description='PyTorch Graph Attention Network')
parser.add_argument('--epochs', type=int, default=300,
help='number of epochs to train (default: 300)')
help='number of epochs to train (default: %(default)s)')
parser.add_argument('--lr', type=float, default=0.005,
help='learning rate (default: 0.005)')
help='learning rate (default: %(default)s)')
parser.add_argument('--l2', type=float, default=5e-4,
help='weight decay (default: 6e-4)')
help='weight decay (default: %(default)s)')
parser.add_argument('--dropout-p', type=float, default=0.6,
help='dropout probability (default: 0.6)')
help='dropout probability (default: %(default)s)')
parser.add_argument('--hidden-dim', type=int, default=64,
help='dimension of the hidden representation (default: 64)')
help='dimension of the hidden representation (default: %(default)s)')
parser.add_argument('--num-heads', type=int, default=8,
help='number of the attention heads (default: 4)')
help='number of the attention heads (default: %(default)s)')
parser.add_argument('--concat-heads', action='store_true', default=False,
help='wether to concatinate attention heads, or average over them (default: False)')
help='wether to concatinate attention heads, or average over them (default: %(default)s)')
parser.add_argument('--val-every', type=int, default=20,
help='epochs to wait for print training and validation evaluation (default: 20)')
help='epochs to wait for print training and validation evaluation (default: %(default)s)')
parser.add_argument('--no-cuda', action='store_true', default=False,
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,
help='quickly check a single pass')
parser.add_argument('--seed', type=int, default=13, metavar='S',
help='random seed (default: 13)')
help='random seed (default: %(default)s)')
args = parser.parse_args()

torch.manual_seed(args.seed)
Expand Down Expand Up @@ -372,4 +372,4 @@ def test(model, criterion, input, target, mask):
if args.dry_run:
break
loss_test, acc_test = test(gat_net, criterion, (features, adj_mat), labels, idx_test)
print(f'Test set results: loss {loss_test:.4f} accuracy {acc_test:.4f}')
print(f'Test set results: loss {loss_test:.4f} accuracy {acc_test:.4f}')
18 changes: 9 additions & 9 deletions gcn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,27 @@ def test(model, criterion, input, target, mask):

parser = argparse.ArgumentParser(description='PyTorch Graph Convolutional Network')
parser.add_argument('--epochs', type=int, default=200,
help='number of epochs to train (default: 200)')
help='number of epochs to train (default: %(default)s)')
parser.add_argument('--lr', type=float, default=0.01,
help='learning rate (default: 0.01)')
help='learning rate (default: %(default)s)')
parser.add_argument('--l2', type=float, default=5e-4,
help='weight decay (default: 5e-4)')
help='weight decay (default: %(default)s)')
parser.add_argument('--dropout-p', type=float, default=0.5,
help='dropout probability (default: 0.5)')
help='dropout probability (default: %(default)s)')
parser.add_argument('--hidden-dim', type=int, default=16,
help='dimension of the hidden representation (default: 16)')
help='dimension of the hidden representation (default: %(default)s)')
parser.add_argument('--val-every', type=int, default=20,
help='epochs to wait for print training and validation evaluation (default: 20)')
help='epochs to wait for print training and validation evaluation (default: %(default)s)')
parser.add_argument('--include-bias', action='store_true', default=False,
help='use bias term in convolutions (default: False)')
help='use bias term in convolutions (default: %(default)s)')
parser.add_argument('--no-cuda', action='store_true', default=False,
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,
help='quickly check a single pass')
parser.add_argument('--seed', type=int, default=42, metavar='S',
help='random seed (default: 42)')
help='random seed (default: %(default)s)')
args = parser.parse_args()

use_cuda = not args.no_cuda and torch.cuda.is_available()
Expand Down Expand Up @@ -260,4 +260,4 @@ def test(model, criterion, input, target, mask):
break

loss_test, acc_test = test(gcn, criterion, (features, adj_mat), labels, idx_test)
print(f'Test set results: loss {loss_test:.4f} accuracy {acc_test:.4f}')
print(f'Test set results: loss {loss_test:.4f} accuracy {acc_test:.4f}')
14 changes: 7 additions & 7 deletions imagenet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@

parser = argparse.ArgumentParser(description='PyTorch ImageNet Training')
parser.add_argument('data', metavar='DIR', nargs='?', default='imagenet',
help='path to dataset (default: imagenet)')
help='path to dataset (default: %(default)s)')
parser.add_argument('-a', '--arch', metavar='ARCH', default='resnet18',
choices=model_names,
help='model architecture: ' +
' | '.join(model_names) +
' (default: resnet18)')
' (default: %(default)s)')
parser.add_argument('-j', '--workers', default=4, type=int, metavar='N',
help='number of data loading workers (default: 4)')
help='number of data loading workers (default: %(default)s)')
parser.add_argument('--epochs', default=90, type=int, metavar='N',
help='number of total epochs to run')
parser.add_argument('--start-epoch', default=0, type=int, metavar='N',
help='manual epoch number (useful on restarts)')
parser.add_argument('-b', '--batch-size', default=256, type=int,
metavar='N',
help='mini-batch size (default: 256), this is the total '
help='mini-batch size (default: %(default)s), this is the total '
'batch size of all GPUs on the current node when '
'using Data Parallel or Distributed Data Parallel')
parser.add_argument('--lr', '--learning-rate', default=0.1, type=float,
metavar='LR', help='initial learning rate', dest='lr')
parser.add_argument('--momentum', default=0.9, type=float, metavar='M',
help='momentum')
parser.add_argument('--wd', '--weight-decay', default=1e-4, type=float,
metavar='W', help='weight decay (default: 1e-4)',
metavar='W', help='weight decay (default: %(default)s)',
dest='weight_decay')
parser.add_argument('-p', '--print-freq', default=10, type=int,
metavar='N', help='print frequency (default: 10)')
metavar='N', help='print frequency (default: %(default)s)')
parser.add_argument('--resume', default='', type=str, metavar='PATH',
help='path to latest checkpoint (default: none)')
help='path to latest checkpoint (default: %(default)s)')
parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true',
help='evaluate model on validation set')
parser.add_argument('--pretrained', dest='pretrained', action='store_true',
Expand Down
8 changes: 4 additions & 4 deletions legacy/snli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def get_args():
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,
help='batch size. (default: 128)')
help='batch size. (default: %(default)s)')
parser.add_argument('--d_embed', type=int, default=100,
help='the size of each embedding vector.')
parser.add_argument('--d_proj', type=int, default=300,
help='the size of each projection layer.')
parser.add_argument('--d_hidden', type=int, default=300,
help='the number of features in the hidden state.')
parser.add_argument('--n_layers', type=int, default=1,
help='the number of recurrent layers. (default: 50)')
help='the number of recurrent layers. (default: %(default)s)')
parser.add_argument('--log_every', type=int, default=50,
help='iteration period to output log.')
parser.add_argument('--lr',type=float, default=.001,
parser.add_argument('--lr', type=float, default=.001,
help='initial learning rate.')
parser.add_argument('--dev_every', type=int, default=1000,
help='log period of validation results.')
Expand All @@ -51,7 +51,7 @@ def get_args():
parser.add_argument('--train_embed', action='store_false', dest='fix_emb',
help='enable embedding word training.')
parser.add_argument('--gpu', type=int, default=0,
help='gpu id to use. (default: 0)')
help='gpu id to use. (default: %(default)s)')
parser.add_argument('--save_path', type=str, default='results',
help='save path of results.')
parser.add_argument('--vector_cache', type=str, default=os.path.join(os.getcwd(), '.vector_cache/input_vectors.pt'),
Expand Down
12 changes: 6 additions & 6 deletions mnist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ def main():
# Training settings
parser = argparse.ArgumentParser(description='PyTorch MNIST Example')
parser.add_argument('--batch-size', type=int, default=64, metavar='N',
help='input batch size for training (default: 64)')
help='input batch size for training (default: %(default)s)')
parser.add_argument('--test-batch-size', type=int, default=1000, metavar='N',
help='input batch size for testing (default: 1000)')
help='input batch size for testing (default: %(default)s)')
parser.add_argument('--epochs', type=int, default=14, metavar='N',
help='number of epochs to train (default: 14)')
help='number of epochs to train (default: %(default)s)')
parser.add_argument('--lr', type=float, default=1.0, metavar='LR',
help='learning rate (default: 1.0)')
help='learning rate (default: %(default)s)')
parser.add_argument('--gamma', type=float, default=0.7, metavar='M',
help='Learning rate step gamma (default: 0.7)')
help='Learning rate step gamma (default: %(default)s)')
parser.add_argument('--no-cuda', action='store_true', default=False,
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,
help='quickly check a single pass')
parser.add_argument('--seed', type=int, default=1, metavar='S',
help='random seed (default: 1)')
help='random seed (default: %(default)s)')
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,
Expand Down
6 changes: 3 additions & 3 deletions mnist_forward_forward/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ def train(self, x_pos, x_neg):
type=int,
default=1000,
metavar="N",
help="number of epochs to train (default: 1000)",
help="number of epochs to train (default: %(default)s)",
)
parser.add_argument(
"--lr",
type=float,
default=0.03,
metavar="LR",
help="learning rate (default: 0.03)",
help="learning rate (default: %(default)s)",
)
parser.add_argument(
"--no_cuda", action="store_true", default=False, help="disables CUDA training"
Expand All @@ -108,7 +108,7 @@ def train(self, x_pos, x_neg):
"--no_mps", action="store_true", default=False, help="disables MPS training"
)
parser.add_argument(
"--seed", type=int, default=1, metavar="S", help="random seed (default: 1)"
"--seed", type=int, default=1, metavar="S", help="random seed (default: %(default)s)"
)
parser.add_argument(
"--save_model",
Expand Down
Loading