manjunath2n7 commited on
Commit
e5782e3
·
verified ·
1 Parent(s): ad472d6

Update modeling_spin.py

Browse files
Files changed (1) hide show
  1. modeling_spin.py +4 -2
modeling_spin.py CHANGED
@@ -108,8 +108,8 @@ class TransformerBlock(nn.Module):
108
 
109
  class SpinForCausalLM(PreTrainedModel, GenerationMixin):
110
  config_class = SpinConfig
111
- # Fix: Use dict mapping for tied weights
112
  _tied_weights_keys = {"lm_head.weight": "tok_embeddings.weight"}
 
113
 
114
  def __init__(self, config: SpinConfig):
115
  super().__init__(config)
@@ -144,6 +144,7 @@ class SpinForCausalLM(PreTrainedModel, GenerationMixin):
144
  def forward(
145
  self,
146
  input_ids: torch.Tensor = None,
 
147
  labels: torch.Tensor = None,
148
  past_key_values: list = None,
149
  use_cache: bool = False,
@@ -182,12 +183,13 @@ class SpinForCausalLM(PreTrainedModel, GenerationMixin):
182
  past_key_values=new_kv_caches if use_cache else None,
183
  )
184
 
185
- def prepare_inputs_for_generation(self, input_ids, past_key_values=None, **kwargs):
186
  if past_key_values is not None and len(past_key_values) > 0 and past_key_values[0] is not None:
187
  input_ids = input_ids[:, -1:]
188
  return {
189
  "input_ids": input_ids,
190
  "past_key_values": past_key_values,
 
191
  "use_cache": True,
192
  }
193
 
 
108
 
109
  class SpinForCausalLM(PreTrainedModel, GenerationMixin):
110
  config_class = SpinConfig
 
111
  _tied_weights_keys = {"lm_head.weight": "tok_embeddings.weight"}
112
+ _supports_cache_class = False
113
 
114
  def __init__(self, config: SpinConfig):
115
  super().__init__(config)
 
144
  def forward(
145
  self,
146
  input_ids: torch.Tensor = None,
147
+ attention_mask: torch.Tensor = None,
148
  labels: torch.Tensor = None,
149
  past_key_values: list = None,
150
  use_cache: bool = False,
 
183
  past_key_values=new_kv_caches if use_cache else None,
184
  )
185
 
186
+ def prepare_inputs_for_generation(self, input_ids, past_key_values=None, attention_mask=None, **kwargs):
187
  if past_key_values is not None and len(past_key_values) > 0 and past_key_values[0] is not None:
188
  input_ids = input_ids[:, -1:]
189
  return {
190
  "input_ids": input_ids,
191
  "past_key_values": past_key_values,
192
+ "attention_mask": attention_mask,
193
  "use_cache": True,
194
  }
195