MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / from_pretrained

Method from_pretrained

eval_code/recons/models/moge/model/v2.py:67–97  ·  view source on GitHub ↗

Load a model from a checkpoint file. ### Parameters: - `pretrained_model_name_or_path`: path to the checkpoint file or repo id. - `compiled` - `model_kwargs`: additional keyword arguments to override the parameters in the checkpoint. - `hf_kwargs`: a

(cls, pretrained_model_name_or_path: Union[str, Path, IO[bytes]], model_kwargs: Optional[Dict[str, Any]] = None, **hf_kwargs)

Source from the content-addressed store, hash-verified

65
66 @classmethod
67 def from_pretrained(cls, pretrained_model_name_or_path: Union[str, Path, IO[bytes]], model_kwargs: Optional[Dict[str, Any]] = None, **hf_kwargs) -> 'MoGeModel':
68 """
69 Load a model from a checkpoint file.
70
71 ### Parameters:
72 - `pretrained_model_name_or_path`: path to the checkpoint file or repo id.
73 - `compiled`
74 - `model_kwargs`: additional keyword arguments to override the parameters in the checkpoint.
75 - `hf_kwargs`: additional keyword arguments to pass to the `hf_hub_download` function. Ignored if `pretrained_model_name_or_path` is a local path.
76
77 ### Returns:
78 - A new instance of `MoGe` with the parameters loaded from the checkpoint.
79 """
80 if Path(pretrained_model_name_or_path).exists():
81 checkpoint_path = pretrained_model_name_or_path
82 else:
83 checkpoint_path = hf_hub_download(
84 repo_id=pretrained_model_name_or_path,
85 repo_type="model",
86 filename="model.pt",
87 **hf_kwargs
88 )
89 checkpoint = torch.load(checkpoint_path, map_location='cpu', weights_only=True)
90
91 model_config = checkpoint['model_config']
92 if model_kwargs is not None:
93 model_config.update(model_kwargs)
94 model = cls(**model_config)
95 model.load_state_dict(checkpoint['model'], strict=False)
96
97 return model
98
99 def init_weights(self):
100 self.encoder.init_weights()

Callers 8

load_model_and_tokenizerFunction · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected