Python torch.backends.cudnn.deterministic() Examples
The following are 30
code examples of torch.backends.cudnn.deterministic().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.backends.cudnn
, or try the search function
.
Example #1
Source File: cifar_train.py From LDAM-DRW with MIT License | 6 votes |
def main(): args = parser.parse_args() args.store_name = '_'.join([args.dataset, args.arch, args.loss_type, args.train_rule, args.imb_type, str(args.imb_factor), args.exp_str]) prepare_folders(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.') ngpus_per_node = torch.cuda.device_count() main_worker(args.gpu, ngpus_per_node, args)
Example #2
Source File: compress_classifier.py From dnn-quant-ocs with Apache License 2.0 | 6 votes |
def automated_deep_compression(model, criterion, loggers, args): import examples.automated_deep_compression.ADC as ADC HAVE_COACH_INSTALLED = True if not HAVE_COACH_INSTALLED: raise ValueError("ADC is currently experimental and uses non-public Coach features") if not isinstance(loggers, list): loggers = [loggers] train_loader, val_loader, test_loader, _ = apputils.load_data( args.dataset, os.path.expanduser(args.data), args.batch_size, args.workers, args.validation_size, args.deterministic) args.display_confusion = True validate_fn = partial(validate, val_loader=test_loader, criterion=criterion, loggers=loggers, args=args) if args.ADC_params is not None: ADC.summarize_experiment(args.ADC_params, args.dataset, args.arch, validate_fn) exit() save_checkpoint_fn = partial(apputils.save_checkpoint, arch=args.arch, dir=msglogger.logdir) ADC.do_adc(model, args.dataset, args.arch, val_loader, validate_fn, save_checkpoint_fn)
Example #3
Source File: compress_classifier.py From dnn-quant-ocs with Apache License 2.0 | 6 votes |
def automated_deep_compression(model, criterion, loggers, args): import examples.automated_deep_compression.ADC as ADC HAVE_COACH_INSTALLED = True if not HAVE_COACH_INSTALLED: raise ValueError("ADC is currently experimental and uses non-public Coach features") if not isinstance(loggers, list): loggers = [loggers] train_loader, val_loader, test_loader, _ = apputils.load_data( args.dataset, os.path.expanduser(args.data), args.batch_size, args.workers, args.validation_size, args.deterministic) args.display_confusion = True validate_fn = partial(validate, val_loader=test_loader, criterion=criterion, loggers=loggers, args=args) if args.ADC_params is not None: ADC.summarize_experiment(args.ADC_params, args.dataset, args.arch, validate_fn) exit() save_checkpoint_fn = partial(apputils.save_checkpoint, arch=args.arch, dir=msglogger.logdir) ADC.do_adc(model, args.dataset, args.arch, val_loader, validate_fn, save_checkpoint_fn)
Example #4
Source File: train.py From PointWeb with MIT License | 6 votes |
def init(): global args, logger, writer args = get_parser() logger = get_logger() writer = SummaryWriter(args.save_path) os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(str(x) for x in args.train_gpu) if args.manual_seed is not None: cudnn.benchmark = False cudnn.deterministic = True torch.manual_seed(args.manual_seed) np.random.seed(args.manual_seed) torch.manual_seed(args.manual_seed) torch.cuda.manual_seed_all(args.manual_seed) if len(args.train_gpu) == 1: args.sync_bn = False logger.info(args)
Example #5
Source File: trainer.py From mrqa with Apache License 2.0 | 6 votes |
def set_random_seed(random_seed): if random_seed is not None: print("Set random seed as {}".format(random_seed)) os.environ['PYTHONHASHSEED'] = str(random_seed) random.seed(random_seed) np.random.seed(random_seed) torch.manual_seed(random_seed) torch.cuda.manual_seed_all(random_seed) torch.set_num_threads(1) cudnn.benchmark = False 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.')
Example #6
Source File: imagenet.py From pytorch-lightning with Apache License 2.0 | 6 votes |
def main(args: Namespace) -> None: model = ImageNetLightningModel(**vars(args)) if args.seed is not None: random.seed(args.seed) torch.manual_seed(args.seed) cudnn.deterministic = True trainer = pl.Trainer( default_root_dir=args.save_path, gpus=args.gpus, max_epochs=args.epochs, distributed_backend=args.distributed_backend, precision=16 if args.use_16bit else 32, ) if args.evaluate: trainer.run_evaluation() else: trainer.fit(model)
Example #7
Source File: ptb_main.py From online-normalization with BSD 3-Clause "New" or "Revised" License | 6 votes |
def main(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.') device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') print('=> load data...') corpus = data.Corpus(args.data) eval_batch_size = 10 train_loader = batchify(corpus.train, args.batch_size, device) val_loader = batchify(corpus.valid, eval_batch_size, device) ntokens = len(corpus.dictionary) main_worker(train_loader, val_loader, ntokens, args, device)
Example #8
Source File: train_pt.py From imgclsmob with MIT License | 6 votes |
def init_rand(seed): """ Initialize all random generators by seed. Parameters: ---------- seed : int Seed value. Returns ------- int Generated seed value. """ if seed <= 0: seed = np.random.randint(10000) else: cudnn.deterministic = True logging.warning( "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.") random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) return seed
Example #9
Source File: torch.py From catalyst with Apache License 2.0 | 6 votes |
def prepare_cudnn(deterministic: bool = None, benchmark: bool = None) -> None: """ Prepares CuDNN benchmark and sets CuDNN to be deterministic/non-deterministic mode Args: deterministic (bool): deterministic mode if running in CuDNN backend. benchmark (bool): If ``True`` use CuDNN heuristics to figure out which algorithm will be most performant for your model architecture and input. Setting it to ``False`` may slow down your training. """ if torch.cuda.is_available(): # CuDNN reproducibility # https://pytorch.org/docs/stable/notes/randomness.html#cudnn if deterministic is None: deterministic = ( os.environ.get("CUDNN_DETERMINISTIC", "True") == "True" ) cudnn.deterministic = deterministic # https://discuss.pytorch.org/t/how-should-i-disable-using-cudnn-in-my-code/38053/4 if benchmark is None: benchmark = os.environ.get("CUDNN_BENCHMARK", "True") == "True" cudnn.benchmark = benchmark
Example #10
Source File: distributed_slurm_main.py From pytorch-distributed with MIT License | 6 votes |
def main(): args = parser.parse_args() if args.seed is not None: random.seed(args.seed) torch.manual_seed(args.seed) cudnn.deterministic = True # torch.backends.cudnn.enabled = False 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.') args.local_rank = int(os.environ["SLURM_PROCID"]) args.world_size = int(os.environ["SLURM_NPROCS"]) ngpus_per_node = torch.cuda.device_count() job_id = os.environ["SLURM_JOBID"] args.dist_url = "file://{}.{}".format(os.path.realpath(args.dist_file), job_id) mp.spawn(main_worker, nprocs=ngpus_per_node, args=(ngpus_per_node, args))
Example #11
Source File: horovod_distributed.py From pytorch-distributed with MIT License | 6 votes |
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.') hvd.init() local_rank = hvd.local_rank() torch.cuda.set_device(local_rank) main_worker(local_rank, 4, args)
Example #12
Source File: main.py From TF2 with Apache License 2.0 | 5 votes |
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)
Example #13
Source File: imagenet.py From pytorch-dp with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: main.py From PyTorch with MIT License | 5 votes |
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)
Example #15
Source File: train.py From semseg with MIT License | 5 votes |
def main(): args = get_parser() check(args) os.environ["CUDA_VISIBLE_DEVICES"] = ','.join(str(x) for x in args.train_gpu) if args.manual_seed is not None: random.seed(args.manual_seed) np.random.seed(args.manual_seed) torch.manual_seed(args.manual_seed) torch.cuda.manual_seed(args.manual_seed) torch.cuda.manual_seed_all(args.manual_seed) cudnn.benchmark = False cudnn.deterministic = True 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 args.ngpus_per_node = len(args.train_gpu) if len(args.train_gpu) == 1: args.sync_bn = False args.distributed = False args.multiprocessing_distributed = False if args.multiprocessing_distributed: port = find_free_port() args.dist_url = f"tcp://127.0.0.1:{port}" args.world_size = args.ngpus_per_node * args.world_size mp.spawn(main_worker, nprocs=args.ngpus_per_node, args=(args.ngpus_per_node, args)) else: main_worker(args.train_gpu, args.ngpus_per_node, args)
Example #16
Source File: main.py From online-normalization with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(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.') # Generate some random images input_images, target_masks = generate_random_data(args.im_size, args.im_size, count=3) print(f'=> image shape: {input_images.shape} in ' f'range: [{input_images.min()}, {input_images.max()}]') print(f'=> target shape: {target_masks.shape} in ' f'range: [{target_masks.min()}, {target_masks.max()}]') t_form = transforms.Compose([transforms.ToTensor(),]) # create generator to create images train_set = SimDataset(args.t_size, args.im_size, transform=t_form) val_set = SimDataset(args.v_size, args.im_size, transform=t_form) # create dataloaders train_loader = DataLoader(train_set, batch_size=args.batch_size, shuffle=True, num_workers=0, drop_last=True) val_loader = DataLoader(val_set, batch_size=args.batch_size, shuffle=False, num_workers=0) # train model model = main_worker(train_loader, val_loader, args=args) return model
Example #17
Source File: main.py From TF2 with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: fmnist_main.py From online-normalization with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(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.') # Data loading code print('=> creating training set...') train_transform = transforms.Compose([transforms.ToTensor()]) train_dataset = datasets.FashionMNIST(args.data, train=True, transform=train_transform, target_transform=None, download=True) print('=> create train dataloader...') train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=args.batch_size, shuffle=True, num_workers=args.workers, pin_memory=True, drop_last=True) print('=> creating validation set...') val_transform = transforms.Compose([transforms.ToTensor()]) val_dataset = datasets.FashionMNIST(args.data, train=False, transform=val_transform, target_transform=None, download=True) print('=> creating validation dataloader...') val_loader = torch.utils.data.DataLoader(val_dataset, batch_size=args.batch_size, shuffle=False, num_workers=args.workers, pin_memory=True) main_worker(train_loader, val_loader, NUM_CLASSES, args)
Example #19
Source File: main.py From online-normalization with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): 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 if args.distributed: raise NotImplementedError('multiprocessing with ON not implemented') 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)
Example #20
Source File: main.py From GroupNorm-reproduce with Apache License 2.0 | 5 votes |
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)
Example #21
Source File: utils.py From BERT4Rec-VAE-Pytorch with GNU General Public License v3.0 | 5 votes |
def fix_random_seed_as(random_seed): random.seed(random_seed) torch.manual_seed(random_seed) torch.cuda.manual_seed_all(random_seed) np.random.seed(random_seed) cudnn.deterministic = True cudnn.benchmark = False
Example #22
Source File: train_imagenet.py From NAS-Benchmark with GNU General Public License v3.0 | 5 votes |
def main(): if not torch.cuda.is_available(): logging.info('No GPU found!') sys.exit(1) np.random.seed(args.seed) torch.manual_seed(args.seed) cudnn.enabled = True cudnn.benchmark = False cudnn.deterministic = True torch.cuda.manual_seed(args.seed) logging.info("Args = %s", args) _, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir) train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_imagenet(model_state_dict, optimizer_state_dict, epoch=epoch-1) while epoch < args.epochs: scheduler.step() logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0]) train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion) logging.info('train_acc %f', train_acc) valid_acc_top1, valid_acc_top5, valid_obj = valid(valid_queue, model, eval_criterion) logging.info('valid_acc_top1 %f', valid_acc_top1) logging.info('valid_acc_top5 %f', valid_acc_top5) epoch += 1 is_best = False if valid_acc_top1 > best_acc_top1: best_acc_top1 = valid_acc_top1 is_best = True utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)
Example #23
Source File: general.py From MedicalZooPytorch with MIT License | 5 votes |
def reproducibility(args, seed): torch.manual_seed(seed) if args.cuda: torch.cuda.manual_seed(seed) np.random.seed(seed) cudnn.deterministic = True # FOR FASTER GPU TRAINING WHEN INPUT SIZE DOESN'T VARY # LET'S TEST IT cudnn.benchmark = True
Example #24
Source File: main.py From EfficientNet-PyTorch with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: pretrain_insup.py From virtex with MIT License | 5 votes |
def main(): _A = parser.parse_args() random.seed(_A.seed) torch.manual_seed(_A.seed) cudnn.deterministic = True _A.world_size = torch.cuda.device_count() # Use torch.multiprocessing.spawn to launch distributed processes: the # main_worker process function mp.spawn(main_worker, nprocs=_A.world_size, args=(_A.world_size, _A))
Example #26
Source File: distributed.py From pytorch-distributed with MIT License | 5 votes |
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.') main_worker(args.local_rank, 4, args)
Example #27
Source File: apex_distributed.py From pytorch-distributed with MIT License | 5 votes |
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.') main_worker(args.local_rank, 4, args)
Example #28
Source File: train.py From EfficientDet.Pytorch with MIT License | 5 votes |
def main(): args = parser.parse_args() if(not os.path.exists(os.path.join(args.save_folder, args.dataset, args.network))): os.makedirs(os.path.join(args.save_folder, args.dataset, args.network)) 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.') os.environ['MASTER_ADDR'] = 'localhost' os.environ['MASTER_PORT'] = '12355' os.environ['WORLD_SIZE'] = '2' 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)
Example #29
Source File: train_pt_cifar-.py From imgclsmob with MIT License | 5 votes |
def init_rand(seed): if seed <= 0: seed = np.random.randint(10000) else: 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.') random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) return seed
Example #30
Source File: test_cifar.py From NAO_pytorch with GNU General Public License v3.0 | 5 votes |
def main(): if not torch.cuda.is_available(): logging.info('No GPU found!') sys.exit(1) random.seed(args.seed) np.random.seed(args.seed) torch.manual_seed(args.seed) torch.cuda.manual_seed(args.seed) torch.cuda.manual_seed_all(args.seed) cudnn.enabled = True cudnn.benchmark = False cudnn.deterministic = True args.steps = int(np.ceil(50000 / args.batch_size)) * args.epochs logging.info("Args = %s", args) _, model_state_dict, epoch, step, optimizer_state_dict, best_acc_top1 = utils.load(args.output_dir) build_fn = get_builder(args.dataset) train_queue, valid_queue, model, train_criterion, eval_criterion, optimizer, scheduler = build_fn(model_state_dict, optimizer_state_dict, epoch=epoch-1) while epoch < args.epochs: scheduler.step() logging.info('epoch %d lr %e', epoch, scheduler.get_lr()[0]) train_acc, train_obj, step = train(train_queue, model, optimizer, step, train_criterion) logging.info('train_acc %f', train_acc) valid_acc_top1, valid_obj = valid(valid_queue, model, eval_criterion) logging.info('valid_acc %f', valid_acc_top1) epoch += 1 is_best = False if valid_acc_top1 > best_acc_top1: best_acc_top1 = valid_acc_top1 is_best = True utils.save(args.output_dir, args, model, epoch, step, optimizer, best_acc_top1, is_best)