orionweller commited on
Commit
a2fb673
·
1 Parent(s): b8415ff
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -136,13 +136,13 @@ class RepLlamaModel:
136
  batch_dict = create_batch_dict(self.tokenizer, batch_texts, always_add_eos="last")
137
  batch_dict = {key: value.cuda() for key, value in batch_dict.items()}
138
 
139
- # with torch.cuda.amp.autocast():
140
- with torch.no_grad():
141
- outputs = self.model(**batch_dict)
142
- embeddings = pool(outputs.last_hidden_state, batch_dict['attention_mask'], 'last')
143
- embeddings = F.normalize(embeddings, p=2, dim=-1)
144
- logger.info(f"Encoded shape: {embeddings.shape}, Norm of first embedding: {torch.norm(embeddings[0]).item()}")
145
- all_embeddings.append(embeddings.cpu().numpy())
146
 
147
  self.model = self.model.cpu()
148
  return np.concatenate(all_embeddings, axis=0)
 
136
  batch_dict = create_batch_dict(self.tokenizer, batch_texts, always_add_eos="last")
137
  batch_dict = {key: value.cuda() for key, value in batch_dict.items()}
138
 
139
+ with torch.cuda.amp.autocast():
140
+ with torch.no_grad():
141
+ outputs = self.model(**batch_dict)
142
+ embeddings = pool(outputs.last_hidden_state, batch_dict['attention_mask'], 'last')
143
+ embeddings = F.normalize(embeddings, p=2, dim=-1)
144
+ logger.info(f"Encoded shape: {embeddings.shape}, Norm of first embedding: {torch.norm(embeddings[0]).item()}")
145
+ all_embeddings.append(embeddings.cpu().numpy())
146
 
147
  self.model = self.model.cpu()
148
  return np.concatenate(all_embeddings, axis=0)