code
stringlengths
3
6.57k
re.compile(r'reference\.md')
re.compile(r'_episodes/.*\.md')
re.compile(r'.*\.md')
main()
CustomDataset(torch.utils.data.Dataset)
__init__(self, input_ids, token_type_ids, attention_masks)
__len__(self)
len(self.input_ids)
__getitem__(self, index)
weights_init(tensor: torch.Tensor)
isinstance(tensor, nn.Linear)
switch_init(tensor.weight.data)
torch.nn.init.zeros_(tensor.bias.data)
isinstance(tensor, nn.LayerNorm)
torch.nn.init.zeros_(tensor.weight.data)
torch.nn.init.zeros_(tensor.bias.data)
switch_init(tensor: torch.Tensor, s: float = 0.1, mean: float=0)
torch.nn.init._calculate_fan_in_and_fan_out(tensor)
math.sqrt(s/fan_in)
torch.nn.init.trunc_normal_(tensor=tensor, mean=mean, std=std)
LaBSE_Switch(nn.Module)
__init__(self, config, word_embeddings_module)
super()
__init__()
MultiHeadAttention(config['heads'], config['d_model'], config['dropout'])
FeedForward(config['d_model'], config['d_ff'], config['dropout_ffn'])
int(768)
self.switch_model.apply(weights_init)
self.weight_init_from_teacher(teacher_model=teacher_model, int_matches=int_matches)
weight_init_from_teacher(self, teacher_model, int_matches)
load_teacher(device=torch.device('cuda')
forward(self, input_ids, token_type_ids=None, attention_mask=None)
self.word_embeddings(input_ids)
print(_n_hid)
self.switch_model(torch.reshape(input_embeddings, (_seq_len, _batch, _n_hid)
load_student(name, student_config, device, teacher_model, int_matches, N_LAYERS)
BertConfig.from_pretrained(name)
BertModel.from_pretrained(name, config=student_config)
student_model.set_input_embeddings(teacher_model.get_input_embeddings()
student_model.float()
student_model.to(device=device)
deepcopy(teacher_model.get_input_embeddings()
word_embedding_compression(word_embeddings, student_config['d_model'])
LaBSE_Switch(config=student_config, word_embeddings_module=compressed_word_embeddings)
student_model.switch_model.apply(weights_init)
student_model.weight_init_from_teacher(teacher_model=teacher_model, int_matches=int_matches)
student_model.float()
student_model.to(device=device)
load_teacher(device)
AutoConfig.from_pretrained('sentence-transformers/LaBSE')
AutoModel.from_pretrained('sentence-transformers/LaBSE', config=teacher_config)
teacher_model.float()
teacher_model.to(device=device)
simple_adaptor(batch, model_outputs)
values.append(i[1])
torch.stack(values)
attentions.append(inv_softmax(j)
torch.stack(attentions)
inv_softmax(x,C=-50)
torch.log(x)
torch.where(result <= float('-inf')
torch.full_like(result,C)
teacher_adaptor(batch, model_outputs)
values.append(i[1])
torch.stack(values)
attentions.append(inv_softmax(j)
torch.stack(attentions)
print(model_outputs['pooler_output'].requires_grad)
switch_student_adaptor(batch, model_outputs)
reshape(layers, batch_size, heads, len, len)
reshape(batch_size, len, d_model)
print(model_outputs['pooler_output'].requires_grad)
reshape(layers, batch_size, heads, len, embedding_per_head)
predict(model, teacher_model, eval_dataset, step, device, STUDENT, BATCH_SIZE, eval_metric='cosine_similarity', feedback=True)
model.eval()
DataLoader(eval_dataset,batch_size=BATCH_SIZE)
print('Running callback function on {} dev set samples...'.format(len(eval_dataset)
to(device)
to(device)
torch.no_grad()
model(input_ids=input_ids, attention_mask=attention_mask)
teacher_model(input_ids=input_ids, attention_mask=attention_mask)
logits_S.detach()
cpu()
logits_T.detach()
cpu()
detach()
cpu()
detach()
cpu()
range(len(cpu_logits_S)
student_logits.append(cpu_logits_S[i].numpy()
teacher_logits.append(cpu_logits_T[i].numpy()
range(len(counts)
batch_counts.append(counts[i].numpy()
batch_n_dropped.append(n_dropped[i])
batch_route_prob.append(route_prob[i].numpy()
model.train()
np.array(student_logits)
np.array(teacher_logits)