cyrilvallez HF Staff commited on
Commit
cd66a74
·
verified ·
1 Parent(s): 2ffb799

Fix for new versions

Browse files
Files changed (1) hide show
  1. custom_generate/generate.py +3 -1
custom_generate/generate.py CHANGED
@@ -181,7 +181,9 @@ def _contrastive_search(
181
  # keep track of which sequences are already finished
182
  batch_size, cur_len = input_ids.shape[:2]
183
  unfinished_sequences = torch.ones(batch_size, dtype=torch.long, device=input_ids.device)
184
- model_kwargs = model._get_initial_cache_position(cur_len, input_ids.device, model_kwargs)
 
 
185
 
186
  # Create cosine_matrix_mask based on the attention_mask
187
  cosine_matrix_mask = torch.ones_like(input_ids, dtype=torch.long)
 
181
  # keep track of which sequences are already finished
182
  batch_size, cur_len = input_ids.shape[:2]
183
  unfinished_sequences = torch.ones(batch_size, dtype=torch.long, device=input_ids.device)
184
+ # Does not exist anymore in recent versions!
185
+ if hasattr(model, "_get_initial_cache_position"):
186
+ model_kwargs = model._get_initial_cache_position(cur_length, input_ids.device, model_kwargs)
187
 
188
  # Create cosine_matrix_mask based on the attention_mask
189
  cosine_matrix_mask = torch.ones_like(input_ids, dtype=torch.long)