in src/util.py [0:0]
def save_distributed_dataset(data, opt):
dir_path = Path(opt.checkpoint_dir) / opt.name
write_path = dir_path / 'tmp_dir'
write_path.mkdir(exist_ok=True)
tmp_path = write_path / f'{opt.global_rank}.json'
with open(tmp_path, 'w') as fw:
json.dump(data, fw)
if opt.is_distributed:
torch.distributed.barrier()
if opt.is_main:
final_path = dir_path / 'dataset_wscores.json'
logger.info(f'Writing dataset with scores at {final_path}')
glob_path = write_path / '*'
results_path = write_path.glob('*.json')
alldata = []
for path in results_path:
with open(path, 'r') as f:
data = json.load(f)
alldata.extend(data)
path.unlink()
with open(final_path, 'w') as fout:
json.dump(alldata, fout, indent=4)
write_path.rmdir()