text stringlengths 1 93.6k |
|---|
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 '
|
'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)',
|
dest='weight_decay')
|
parser.add_argument('-p', '--print-freq', default=10, type=int,
|
metavar='N', help='print frequency (default: 10)')
|
parser.add_argument('--resume', default='', type=str, metavar='PATH',
|
help='path to latest checkpoint (default: none)')
|
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',
|
help='use pre-trained model')
|
parser.add_argument('--world-size', default=-1, type=int,
|
help='number of nodes for distributed training')
|
parser.add_argument('--rank', default=-1, type=int,
|
help='node rank for distributed training')
|
parser.add_argument('--dist-url', default='tcp://224.66.41.62:23456', type=str,
|
help='url used to set up distributed training')
|
parser.add_argument('--dist-backend', default='nccl', type=str,
|
help='distributed backend')
|
parser.add_argument('--seed', default=None, type=int,
|
help='seed for initializing training. ')
|
parser.add_argument('--gpu', default=None, type=int,
|
help='GPU id to use.')
|
parser.add_argument('--multiprocessing-distributed', action='store_true',
|
help='Use multi-processing distributed training to launch '
|
'N processes per node, which has N GPUs. This is the '
|
'fastest way to use PyTorch for either single node or '
|
'multi node data parallel training')
|
best_acc1 = 0
|
def main():
|
args = parser.parse_args()
|
if args.seed is not None:
|
random.seed(args.seed)
|
torch.manual_seed(args.seed)
|
cudnn.deterministic = True
|
warnings.warn('You have chosen to seed training. '
|
'This will turn on the CUDNN deterministic setting, '
|
'which can slow down your training considerably! '
|
'You may see unexpected behavior when restarting '
|
'from checkpoints.')
|
if args.gpu is not None:
|
warnings.warn('You have chosen a specific GPU. This will completely '
|
'disable data parallelism.')
|
if args.dist_url == "env://" and args.world_size == -1:
|
args.world_size = int(os.environ["WORLD_SIZE"])
|
args.distributed = args.world_size > 1 or args.multiprocessing_distributed
|
ngpus_per_node = torch.cuda.device_count()
|
if args.multiprocessing_distributed:
|
# Since we have ngpus_per_node processes per node, the total world_size
|
# needs to be adjusted accordingly
|
args.world_size = ngpus_per_node * args.world_size
|
# Use torch.multiprocessing.spawn to launch distributed processes: the
|
# main_worker process function
|
mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args))
|
else:
|
# Simply call main_worker function
|
main_worker(args.gpu, ngpus_per_node, args)
|
def main_worker(gpu, ngpus_per_node, args):
|
global best_acc1
|
args.gpu = gpu
|
if args.gpu is not None:
|
print("Use GPU: {} for training".format(args.gpu))
|
if args.distributed:
|
if args.dist_url == "env://" and args.rank == -1:
|
args.rank = int(os.environ["RANK"])
|
if args.multiprocessing_distributed:
|
# For multiprocessing distributed training, rank needs to be the
|
# global rank among all the processes
|
args.rank = args.rank * ngpus_per_node + gpu
|
dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url,
|
world_size=args.world_size, rank=args.rank)
|
# create model
|
if args.pretrained:
|
print("=> using pre-trained model '{}'".format(args.arch))
|
model = models.__dict__[args.arch](pretrained=True)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.