MCPcopy Index your code
hub / github.com/TorchSSL/TorchSSL / main_worker

Function main_worker

softmatch.py:66–252  ·  view source on GitHub ↗

main_worker is conducted on each GPU.

(gpu, ngpus_per_node, args)

Source from the content-addressed store, hash-verified

64
65
66def main_worker(gpu, ngpus_per_node, args):
67 '''
68 main_worker is conducted on each GPU.
69 '''
70
71 global best_acc1
72 args.gpu = gpu
73
74 # random seed has to be set for the syncronization of labeled data sampling in each process.
75 assert args.seed is not None
76 random.seed(args.seed)
77 torch.manual_seed(args.seed)
78 np.random.seed(args.seed)
79 cudnn.deterministic = True
80
81 # SET UP FOR DISTRIBUTED TRAINING
82 if args.distributed:
83 if args.dist_url == "env://" and args.rank == -1:
84 args.rank = int(os.environ["RANK"])
85 if args.multiprocessing_distributed:
86 args.rank = args.rank * ngpus_per_node + gpu # compute global rank
87
88 # set distributed group:
89 dist.init_process_group(backend=args.dist_backend, init_method=args.dist_url,
90 world_size=args.world_size, rank=args.rank)
91
92 # SET save_path and logger
93 save_path = os.path.join(args.save_dir, args.save_name)
94 logger_level = "WARNING"
95 tb_log = None
96 if args.rank % ngpus_per_node == 0:
97 tb_log = TBLog(save_path, 'tensorboard', use_tensorboard=args.use_tensorboard)
98 logger_level = "INFO"
99
100 logger = get_logger(args.save_name, save_path, logger_level)
101 logger.warning(f"USE GPU: {args.gpu} for training")
102
103 # SET FreeMatch: class FreeMatch in models.freematch
104 args.bn_momentum = 1.0 - 0.999
105 if 'imagenet' in args.dataset.lower():
106 _net_builder = net_builder('ResNet50', False, None, is_remix=False)
107 args.lr = 0.1
108 else:
109 _net_builder = net_builder(args.net,
110 args.net_from_name,
111 {'first_stride': 2 if 'stl' in args.dataset else 1,
112 'depth': args.depth,
113 'widen_factor': args.widen_factor,
114 'leaky_slope': args.leaky_slope,
115 'bn_momentum': args.bn_momentum,
116 'dropRate': args.dropout,
117 'use_embed': False,
118 'is_remix': False},
119 )
120
121 model = SoftMatch(_net_builder,
122 args.num_classes,
123 args.ema_m,

Callers 1

mainFunction · 0.70

Calls 15

get_ssl_dsetMethod · 0.95
get_dsetMethod · 0.95
get_lb_train_dataMethod · 0.95
get_ulb_train_dataMethod · 0.95
get_lb_test_dataMethod · 0.95
TBLogClass · 0.90
get_loggerFunction · 0.90
net_builderFunction · 0.90
SoftMatchClass · 0.90
count_parametersFunction · 0.90
get_optimizerFunction · 0.90

Tested by

no test coverage detected