Spaces:
Runtime error
Runtime error
File size: 1,654 Bytes
d41829b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import random
import torch
import numpy as np
import os
def set_all_seeds(seed=42):
print("set all seeds", flush=True)
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
def fix_state_dict(state_dict):
new_state_dict = {}
for k, v in state_dict.items():
name = k[7:] if k.startswith('module.') else k
new_state_dict[name] = v
return new_state_dict
#######################################################
def load_hint_texts_from_file(file_path):
hint_texts = []
with open(file_path, 'r') as file:
for line in file:
hint_texts.append([line.strip()])
return hint_texts
def load_mask_from_file(file_path):
mask = []
with open(file_path, 'r') as file:
for line in file:
mask.append([line.strip()])
return mask
def load_file_names(file_path):
with open(file_path, 'r') as file:
file_names = [line.strip() for line in file]
return file_names
def gen_prog_ind(num_cases=16, sublist_length=4):
total_range = 0.9
step = total_range / sublist_length
ranges = [(i * step, i * step + step / 5) for i in range(sublist_length)]
prog_ind_all = []
for _ in range(num_cases):
while True:
case = [random.uniform(r[0], r[1]) for r in ranges]
if all(step*0.8 <= case[i+1] - case[i] <= step*1.6 for i in range(len(case) - 1)):
prog_ind_all.append([case])
break
return prog_ind_all |