dir_file = net_plotter.name_direction_file(args) # name the direction file if rank == 0: net_plotter.setup_direction(args, dir_file, net) surf_file = name_surface_file(args, dir_file) if rank == 0: setup_surface_file(args, surf_file, dir_file) # wait until master has setup the direction file and surface file mpi.barrier(comm) # load directions d = net_plotter.load_directions(dir_file) # calculate the consine similarity of the two directions if len(d) == 2 and rank == 0: similarity = proj.cal_angle(proj.nplist_to_tensor(d[0]), proj.nplist_to_tensor(d[1])) print('cosine similarity between x-axis and y-axis: %f' % similarity) #-------------------------------------------------------------------------- # Setup dataloader #-------------------------------------------------------------------------- # download CIFAR10 if it does not exit if rank == 0 and args.dataset == 'cifar10': torchvision.datasets.CIFAR10(root=args.dataset + '/data', train=True, download=True) mpi.barrier(comm) trainloader, testloader = dataloader.load_dataset( args.dataset, args.datapath, args.batch_size, args.threads,
surf_file += '.h5' f = h5py.File(surf_file, 'a') f['dir_file'] = args.dir_file # Create the coordinates(resolutions) at which the function is evaluated xcoordinates = np.linspace(args.xmin, args.xmax, num=args.xnum) f['xcoordinates'] = xcoordinates ycoordinates = np.linspace(args.ymin, args.ymax, num=args.ynum) f['ycoordinates'] = ycoordinates f.close() directions = [xdirection, ydirection] similarity = proj.cal_angle(proj.nplist_to_tensor(directions[0]), proj.nplist_to_tensor(directions[1])) print('cosine similarity between x-axis and y-axis: %f' % similarity) f = h5py.File(surf_file, 'r+') xcoordinates = f['xcoordinates'][:] ycoordinates = f['ycoordinates'][:] losses = -np.ones(shape=(len(xcoordinates), len(ycoordinates))) accuracies = -np.ones(shape=(len(xcoordinates), len(ycoordinates))) f['train_loss'] = losses f['train_acc'] = accuracies inds, coords, inds_nums = scheduler.get_job_indices( losses, xcoordinates, ycoordinates, None)
dir_file = net_plotter.name_direction_file(args) # name the direction file if rank == 0: net_plotter.setup_direction(args, dir_file, net) surf_file = name_surface_file(args, dir_file) if rank == 0: setup_surface_file(args, surf_file, dir_file) # wait until master has setup the direction file and surface file mpi4pytorch.barrier(comm) # load directions d = net_plotter.load_directions(dir_file) # calculate the consine similarity of the two directions if len(d) == 2 and rank == 0: similarity = proj.cal_angle(proj.nplist_to_tensor(d[0]), proj.nplist_to_tensor(d[1])) print('cosine similarity between x-axis and y-axis: %f' % similarity) #-------------------------------------------------------------------------- # Setup dataloader #-------------------------------------------------------------------------- # download CIFAR10 if it does not exit if rank == 0 and args.dataset == 'cifar10': torchvision.datasets.CIFAR10(root=args.dataset + '/data', train=True, download=True) mpi4pytorch.barrier(comm) trainloader, testloader = dataloader.load_dataset(args.dataset, args.datapath, args.batch_size, args.threads, args.raw_data, args.data_split, args.split_idx, args.trainloader, args.testloader)
dir_file = net_plotter.name_direction_file(args) # name the direction file if rank == 0: net_plotter.setup_direction(args, dir_file, net) surf_file = name_surface_file(args, dir_file) if rank == 0: setup_surface_file(args, surf_file, dir_file) # wait until master has setup the direction file and surface file mpi4pytorch.barrier(comm) # load directions d = net_plotter.load_directions(dir_file) # calculate the consine similarity of the two directions if len(d) == 2 and rank == 0: similarity = proj.cal_angle(proj.list_to_vec(d[0]), proj.list_to_vec(d[1])) print('cosine similarity between x-axis and y-axis: ' + str(similarity)) #-------------------------------------------------------------------------- # Setup dataloader #-------------------------------------------------------------------------- # download CIFAR10 if it does not exit if rank == 0 and args.dataset == 'cifar10': torchvision.datasets.CIFAR10(root=args.dataset + '/data', train=True, download=True) mpi4pytorch.barrier(comm) trainloader, testloader = dataloader.load_dataset(