Atom0124 commited on
Commit
48f6ed5
·
verified ·
1 Parent(s): 4f3c577

Sync modeling/config to silx-ai @ main (batch3)

Browse files
Files changed (2) hide show
  1. configuration_quasar.py +2 -2
  2. modeling_quasar.py +11 -1
configuration_quasar.py CHANGED
@@ -2,10 +2,10 @@
2
 
3
  """
4
 
5
- from transformers.configuration_utils import PreTrainedConfig
6
 
7
 
8
- class QuasarConfig(PreTrainedConfig):
9
  model_type = "quasar"
10
  keys_to_ignore_at_inference = ["past_key_values"]
11
 
 
2
 
3
  """
4
 
5
+ from transformers.configuration_utils import PretrainedConfig
6
 
7
 
8
+ class QuasarConfig(PretrainedConfig):
9
  model_type = "quasar"
10
  keys_to_ignore_at_inference = ["past_key_values"]
11
 
modeling_quasar.py CHANGED
@@ -3,6 +3,7 @@
3
  """
4
 
5
  import math
 
6
  from dataclasses import dataclass
7
 
8
  import torch
@@ -908,6 +909,15 @@ class QuasarForCausalLM(QuasarPreTrainedModel, FLAGenerationMixin):
908
  self.model = QuasarModel(config)
909
  self.vocab_size = config.vocab_size
910
  self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
 
 
 
 
 
 
 
 
 
911
  self.post_init()
912
 
913
  def get_input_embeddings(self):
@@ -967,7 +977,7 @@ class QuasarForCausalLM(QuasarPreTrainedModel, FLAGenerationMixin):
967
  if mask.any():
968
  active_hidden = flat_hidden[mask]
969
  active_labels = flat_labels[mask]
970
- chunk_size = 256
971
  total_loss = 0.0
972
  total_tokens = active_labels.numel()
973
  for i in range(0, total_tokens, chunk_size):
 
3
  """
4
 
5
  import math
6
+ import os
7
  from dataclasses import dataclass
8
 
9
  import torch
 
909
  self.model = QuasarModel(config)
910
  self.vocab_size = config.vocab_size
911
  self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
912
+ self.model.lm_head = self.lm_head
913
+
914
+ def _remap_lm_head_state_dict(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs):
915
+ checkpoint_key = prefix + "model.lm_head.weight"
916
+ module_key = prefix + "lm_head.weight"
917
+ if checkpoint_key in state_dict and module_key not in state_dict:
918
+ state_dict[module_key] = state_dict[checkpoint_key]
919
+
920
+ self.register_load_state_dict_pre_hook(_remap_lm_head_state_dict)
921
  self.post_init()
922
 
923
  def get_input_embeddings(self):
 
977
  if mask.any():
978
  active_hidden = flat_hidden[mask]
979
  active_labels = flat_labels[mask]
980
+ chunk_size = int(os.environ.get("QUASAR_LM_HEAD_CHUNK_SIZE", "2048"))
981
  total_loss = 0.0
982
  total_tokens = active_labels.numel()
983
  for i in range(0, total_tokens, chunk_size):