speechisalluneed commited on
Commit
cbd97cf
·
verified ·
1 Parent(s): f23ccdf

Update modeling_fastslm.py

Browse files
Files changed (1) hide show
  1. modeling_fastslm.py +6 -5
modeling_fastslm.py CHANGED
@@ -289,7 +289,6 @@ class SpeechEncoder(nn.Module):
289
  class FastSLMPreTrainedModel(PreTrainedModel):
290
  config_class = FastSLMConfig
291
  base_model_prefix = "fastslm"
292
-
293
  def _init_weights(self, module):
294
  if isinstance(module, nn.Linear):
295
  nn.init.normal_(module.weight, std=0.02)
@@ -307,8 +306,8 @@ class FastSLMForConditionalGeneration(FastSLMPreTrainedModel, GenerationMixin):
307
  config.llm_config,
308
  trust_remote_code=True
309
  )
310
- if self.llm._tied_weights_keys is not None:
311
- self._tied_weights_keys = [f"llm.{k}" for k in self.llm._tied_weights_keys]
312
 
313
  llm_lora_config = LoraConfig(
314
  r=config.lora_r,
@@ -327,6 +326,8 @@ class FastSLMForConditionalGeneration(FastSLMPreTrainedModel, GenerationMixin):
327
  special_tokens = audio_token + language_token + task_token
328
  self.tokenizer.add_special_tokens({"additional_special_tokens": special_tokens})
329
 
 
 
330
  def get_input_embeddings(self) -> nn.Module:
331
  """Returns the input embedding layer of the LLM."""
332
  return self.llm.get_input_embeddings()
@@ -358,7 +359,7 @@ class FastSLMForConditionalGeneration(FastSLMPreTrainedModel, GenerationMixin):
358
  ):
359
  speech_query, speech_attn_mask = self.encoder(audio)
360
 
361
- token_embedding = self.llm.get_input_embeddings()
362
 
363
  # Create speech labels (-100 to ignore in loss calculation)
364
  speech_label_len = int(speech_query.shape[1])
@@ -397,7 +398,7 @@ class FastSLMForConditionalGeneration(FastSLMPreTrainedModel, GenerationMixin):
397
  return outputs
398
 
399
  def generate(self, input_ids, audio: List[torch.Tensor] = None, **kwargs):
400
- token_embedding = self.llm.get_input_embeddings()
401
  if audio is not None:
402
  speech_query, speech_attn_mask = self.encoder(audio)
403
  audio_token_id = self.tokenizer.convert_tokens_to_ids("<|AUDIO|>")
 
289
  class FastSLMPreTrainedModel(PreTrainedModel):
290
  config_class = FastSLMConfig
291
  base_model_prefix = "fastslm"
 
292
  def _init_weights(self, module):
293
  if isinstance(module, nn.Linear):
294
  nn.init.normal_(module.weight, std=0.02)
 
306
  config.llm_config,
307
  trust_remote_code=True
308
  )
309
+ # if self.llm._tied_weights_keys is not None:
310
+ # self._tied_weights_keys = [f"llm.{k}" for k in self.llm._tied_weights_keys]
311
 
312
  llm_lora_config = LoraConfig(
313
  r=config.lora_r,
 
326
  special_tokens = audio_token + language_token + task_token
327
  self.tokenizer.add_special_tokens({"additional_special_tokens": special_tokens})
328
 
329
+ self.post_init()
330
+
331
  def get_input_embeddings(self) -> nn.Module:
332
  """Returns the input embedding layer of the LLM."""
333
  return self.llm.get_input_embeddings()
 
359
  ):
360
  speech_query, speech_attn_mask = self.encoder(audio)
361
 
362
+ token_embedding = self.get_input_embeddings()
363
 
364
  # Create speech labels (-100 to ignore in loss calculation)
365
  speech_label_len = int(speech_query.shape[1])
 
398
  return outputs
399
 
400
  def generate(self, input_ids, audio: List[torch.Tensor] = None, **kwargs):
401
+ token_embedding = self.get_input_embeddings()
402
  if audio is not None:
403
  speech_query, speech_attn_mask = self.encoder(audio)
404
  audio_token_id = self.tokenizer.convert_tokens_to_ids("<|AUDIO|>")