klemenk commited on
Commit
5963fe7
·
verified ·
1 Parent(s): c55fb2a

Update modeling.py

Browse files
Files changed (1) hide show
  1. modeling.py +0 -47
modeling.py CHANGED
@@ -268,53 +268,6 @@ class GSLMForCausalLM(GSLMPreTrainedModel):
268
  # Initialize weights
269
  self.post_init()
270
 
271
- @classmethod
272
- def from_pretrained(cls, pretrained_model_name_or_path, *model_args,
273
- **kwargs):
274
- """
275
- Load **either** a HF‑native checkpoint **or** a fairseq‑style
276
- checkpoint transparently.
277
- """
278
- trust_remote_code = kwargs.pop("trust_remote_code", True)
279
-
280
- # try:
281
- # # First try the normal Hugging‑Face path
282
- # return super().from_pretrained(
283
- # pretrained_model_name_or_path,
284
- # *model_args,
285
- # trust_remote_code=trust_remote_code,
286
- # **kwargs,
287
- # )
288
-
289
- # except (RuntimeError, KeyError) as err:
290
-
291
- # 1. Load *raw* tensors (no strict shape checks yet)
292
- import torch
293
- state_dict = torch.load(
294
- pretrained_model_name_or_path,
295
- map_location="cpu",
296
- weights_only=False,
297
- )["model"]
298
-
299
- # 2. Convert key names
300
- converted = _fairseq_to_hf(state_dict)
301
-
302
- # 3. Build an *uninitialised* model then load weights
303
- config = kwargs.pop("config", None) # a config object or None
304
- with no_init_weights():
305
- model = cls(config) if config is not None else cls.from_config(
306
- pretrained_model_name_or_path
307
- )
308
-
309
- missing, unexpected = model.load_state_dict(converted, strict=False)
310
- if missing or unexpected:
311
- print(
312
- f"Checkpoint conversion finished with "
313
- f"{len(missing)} missing and {len(unexpected)} "
314
- "unexpected keys."
315
- )
316
- return model
317
-
318
  def get_input_embeddings(self):
319
  return self.transformer.wte
320
 
 
268
  # Initialize weights
269
  self.post_init()
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  def get_input_embeddings(self):
272
  return self.transformer.wte
273