sapthesh commited on
Commit
1fea6dc
Β·
verified Β·
1 Parent(s): d854425

Update custom_model.py

Browse files
Files changed (1) hide show
  1. custom_model.py +9 -5
custom_model.py CHANGED
@@ -13,8 +13,12 @@ class CustomModel(PreTrainedModel):
13
 
14
  @classmethod
15
  def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
16
- config = cls.config_class.from_pretrained(pretrained_model_name_or_path, *args, **kwargs)
17
- model = cls(config)
18
- # Load the weights from the pretrained model
19
- model.load_state_dict(torch.load(pretrained_model_name_or_path))
20
- return model
 
 
 
 
 
13
 
14
  @classmethod
15
  def from_pretrained(cls, pretrained_model_name_or_path, *args, **kwargs):
16
+ try:
17
+ config = cls.config_class.from_pretrained(pretrained_model_name_or_path, *args, **kwargs)
18
+ model = cls(config)
19
+ # Load the weights from the pretrained model
20
+ model.load_state_dict(torch.load(pretrained_model_name_or_path))
21
+ return model
22
+ except FileNotFoundError:
23
+ print(f"Failed to load model from {pretrained_model_name_or_path}. Please check the model name and path.")
24
+ return None