def save_inference(self, args, logits, metas, json_metas):
    cache_dir = (args.data.output.path.parent / 'caches')
    cache_dir.mkdir(parents=True, exist_ok=True)
    pid = args.parent_pid
    local_rank = du.get_rank()
    output_name = Path(args.data.output.path).stem
    name = '{}_contrastive_inferred_cache_{}_{}.csv'.format(output_name, pid, local_rank)
    scores = logits.numpy().tolist()
    rows = [{'score': score, **v} for (score, v) in zip(scores, metas)]
    lines = format_rows(rows, json_metas, sharded_meta=True, headers=['score', 'shard_name', 'filename', 'id', 'segment'])
    print('saving cache to {}'.format((cache_dir / name)))
    with open((cache_dir / name), 'a+') as f:
        writer = csv.writer(f)
        for line in lines:
            writer.writerow(line)
def save_inference(self, args, logits, metas, json_metas):
    cache_dir = (args.data.output.path.parent / 'caches')
    cache_dir.mkdir(parents=True, exist_ok=True)
    pid = args.parent_pid
    local_rank = du.get_rank()
    output_name = Path(args.data.output.path).stem
    name = '{}_contrastive_inferred_cache_{}_{}.csv'.format(output_name, pid, local_rank)
    scores = logits.numpy().tolist()
    rows = [{'score': score, **v} for (score, v) in zip(scores, metas)]
    lines = format_rows(rows, json_metas, sharded_meta=True, headers=['score', 'shard_name', 'filename', 'id', 'segment'])
    print('saving cache to {}'.format((cache_dir / name)))
    with open((cache_dir / name), 'a+') as f:
        writer = csv.writer(f)
        for line in lines:
            writer.writerow(line)