ALJIACHI commited on
Commit
2f77769
·
verified ·
1 Parent(s): 9544d48

Upload modeling.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. modeling.py +5 -8
modeling.py CHANGED
@@ -372,18 +372,15 @@ class NewEmbeddings(nn.Module):
372
  embeddings = inputs_embeds
373
 
374
  # Set and unpad position_ids
375
- # Always regenerate internally for robustness — avoids corrupt position_ids
376
- # from external callers (e.g. sentence-transformers on some environments)
377
- if seq_length > self.position_ids.size(0):
378
- self.register_buffer(
379
- "position_ids", torch.arange(seq_length, device=embeddings.device), persistent=False
380
- )
381
  if unpad_inputs:
382
  # [1, cumsum_seq_len]
383
- position_ids = torch.cat([self.position_ids[:l] for l in length]).unsqueeze(0)
384
  else:
385
  # [bs, seq_len]
386
- position_ids = self.position_ids[:seq_length].expand(batch_size, -1)
387
 
388
  # Compute rotary embedding
389
  if self.position_embedding_type == 'rope':
 
372
  embeddings = inputs_embeds
373
 
374
  # Set and unpad position_ids
375
+ # Create fresh position_ids each call for robustness — the persistent buffer
376
+ # can become corrupted on certain environments (Python 3.13 / HF Spaces)
377
+ _pos = torch.arange(seq_length, dtype=torch.long, device=embeddings.device)
 
 
 
378
  if unpad_inputs:
379
  # [1, cumsum_seq_len]
380
+ position_ids = torch.cat([_pos[:l] for l in length]).unsqueeze(0)
381
  else:
382
  # [bs, seq_len]
383
+ position_ids = _pos.unsqueeze(0).expand(batch_size, -1)
384
 
385
  # Compute rotary embedding
386
  if self.position_embedding_type == 'rope':