Arushhh commited on
Commit
ce4de2e
·
verified ·
1 Parent(s): 90fbb55

variant support: WISE_ALPHA, EMB_DIR/OUT_PREFIX

Browse files
Files changed (1) hide show
  1. code/hf_jobs/encode_e5_ft.py +11 -0
code/hf_jobs/encode_e5_ft.py CHANGED
@@ -115,6 +115,17 @@ def main():
115
  local_dir=f'{WORK}/model')
116
  log('model files', sorted(os.listdir(mpath)))
117
  model = SentenceTransformer(mpath, device='cuda', model_kwargs={'torch_dtype': torch.float16})
 
 
 
 
 
 
 
 
 
 
 
118
  model.eval()
119
  pdt = next(model.parameters()).dtype
120
  if pdt != torch.float16:
 
115
  local_dir=f'{WORK}/model')
116
  log('model files', sorted(os.listdir(mpath)))
117
  model = SentenceTransformer(mpath, device='cuda', model_kwargs={'torch_dtype': torch.float16})
118
+ wa = float(os.environ.get('WISE_ALPHA', '0') or 0)
119
+ if wa > 0: # WiSE-FT: weights = (1 - a) * stock e5-large + a * this model (fine-tuned), then fp16
120
+ base = SentenceTransformer('intfloat/multilingual-e5-large', device='cuda', model_kwargs={'torch_dtype': torch.float32})
121
+ ft32 = SentenceTransformer(mpath, device='cuda', model_kwargs={'torch_dtype': torch.float32})
122
+ sd_b, sd_f = base.state_dict(), ft32.state_dict()
123
+ with torch.no_grad():
124
+ for k, v in base.state_dict().items():
125
+ if v.is_floating_point():
126
+ v.copy_((1 - wa) * sd_b[k] + wa * sd_f[k])
127
+ model = base.half(); del ft32
128
+ log(f'WiSE-FT weight average: alpha={wa} (0 = stock e5-large, 1 = {MODEL}@{MODEL_REVISION})')
129
  model.eval()
130
  pdt = next(model.parameters()).dtype
131
  if pdt != torch.float16: