This issue is a result of a Codex global repository scan.
Summary
The Hugging Face model constructors resolve weight and dictionary paths and always pass them into the UniMol backend. If resolve_weight_path or resolve_dict_path returns a missing default path or stale repo-relative path, the backend does not enter its auto-download path because pretrained_model_path is not None. _has_transformers_weights also only checks local directories, so Hub model ids or saved HF checkpoints can skip super().from_pretrained() and ignore Transformers weights.
Code references
|
def _has_transformers_weights(pretrained_model_name_or_path): |
|
if not isinstance(pretrained_model_name_or_path, (str, os.PathLike)): |
|
return False |
|
path = os.fspath(pretrained_model_name_or_path) |
|
if not os.path.isdir(path): |
|
return False |
|
filenames = { |
|
WEIGHTS_NAME, |
|
SAFE_WEIGHTS_NAME, |
|
"pytorch_model.bin.index.json", |
|
"model.safetensors.index.json", |
|
} |
|
return any(os.path.isfile(os.path.join(path, name)) for name in filenames) |
|
@classmethod |
|
def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs): |
|
config = kwargs.pop("config", None) |
|
if config is None: |
|
config, kwargs = cls.config_class.from_pretrained( |
|
pretrained_model_name_or_path, |
|
return_unused_kwargs=True, |
|
**kwargs, |
|
) |
|
config.pretrained_model_path = config.resolve_weight_path(pretrained_model_name_or_path) |
|
config.pretrained_dict_path = config.resolve_dict_path(pretrained_model_name_or_path) |
|
if _has_transformers_weights(pretrained_model_name_or_path): |
|
return super().from_pretrained( |
|
pretrained_model_name_or_path, |
|
*model_args, |
|
config=config, |
|
**kwargs, |
|
) |
|
return cls(config, *model_args) |
|
|
|
|
|
class UnimolModel(UnimolPreTrainedModel): |
|
def __init__(self, config: UnimolConfig): |
|
super().__init__(config) |
|
weight_path = config.resolve_weight_path() |
|
dict_path = config.resolve_dict_path() |
|
self.unimol = UniMolBackend( |
|
output_dim=config.num_labels, |
|
data_type=config.data_type, |
|
remove_hs=config.remove_hs, |
|
pretrained_model_path=weight_path, |
|
pretrained_dict_path=dict_path, |
|
) |
|
weight_path = config.resolve_weight_path() |
|
dict_path = config.resolve_dict_path() |
|
self.unimol = UniMolBackend( |
|
output_dim=config.num_labels, |
|
data_type=config.data_type, |
|
remove_hs=config.remove_hs, |
|
pretrained_model_path=weight_path, |
|
pretrained_dict_path=dict_path, |
|
weight_path = config.resolve_weight_path() |
|
dict_path = config.resolve_dict_path() |
|
self.unimol = UniMolBackend( |
|
output_dim=config.num_labels, |
|
data_type=config.data_type, |
|
remove_hs=config.remove_hs, |
|
pretrained_model_path=weight_path, |
|
pretrained_dict_path=dict_path, |
|
) |
|
def resolve_weight_path(self, pretrained_model_name_or_path=None): |
|
if self.pretrained_model_path: |
|
return self._resolve_path(self.pretrained_model_path, pretrained_model_name_or_path) |
|
base = pretrained_model_name_or_path or get_weight_dir() |
|
if os.path.isfile(os.path.join(base, self.weight_name)): |
|
return os.path.join(base, self.weight_name) |
|
return os.path.join(get_weight_dir(), self.weight_name) |
|
|
|
def resolve_dict_path(self, pretrained_model_name_or_path=None): |
|
if self.pretrained_dict_path: |
|
return self._resolve_path(self.pretrained_dict_path, pretrained_model_name_or_path) |
|
base = pretrained_model_name_or_path or get_weight_dir() |
|
if os.path.isfile(os.path.join(base, self.dict_name)): |
|
return os.path.join(base, self.dict_name) |
|
return os.path.join(get_weight_dir(), self.dict_name) |
|
"pretrained_dict_path": "unimol_tools/unimol_tools/weights/mol.dict.txt", |
|
"pretrained_model_path": "unimol_tools/unimol_tools/weights/mol_pre_all_h_220816.pt", |
|
"pretrained_dict_path": "unimol_tools/unimol_tools/weights/mol.dict.txt", |
|
"pretrained_model_path": "unimol_tools/unimol_tools/weights/mol_pre_no_h_220816.pt", |
Impact
Packaged HF entries and saved Transformers checkpoints can fail to load on clean installs or silently ignore saved HF weights, depending on whether the stale paths exist locally.
Suggested fix
Use Transformers helpers such as cached_file or has_file to detect local and remote HF weights, delegate to super().from_pretrained() for real HF checkpoints, and avoid passing missing paths into the backend. Remove stale pretrained_*_path entries from bundled configs or resolve them to local packaged files.
This issue is a result of a Codex global repository scan.
Summary
The Hugging Face model constructors resolve weight and dictionary paths and always pass them into the UniMol backend. If resolve_weight_path or resolve_dict_path returns a missing default path or stale repo-relative path, the backend does not enter its auto-download path because pretrained_model_path is not None. _has_transformers_weights also only checks local directories, so Hub model ids or saved HF checkpoints can skip super().from_pretrained() and ignore Transformers weights.
Code references
unimol_tools/unimol_hf/modeling_unimol.py
Lines 33 to 45 in 4596596
unimol_tools/unimol_hf/modeling_unimol.py
Lines 130 to 162 in 4596596
unimol_tools/unimol_hf/modeling_unimol.py
Lines 235 to 242 in 4596596
unimol_tools/unimol_hf/modeling_unimol.py
Lines 304 to 312 in 4596596
unimol_tools/unimol_hf/configuration_unimol.py
Lines 88 to 102 in 4596596
unimol_tools/unimol_hf/pretrained/unimol-v1-allh/config.json
Lines 39 to 40 in 4596596
unimol_tools/unimol_hf/pretrained/unimol-v1-noh/config.json
Lines 39 to 40 in 4596596
Impact
Packaged HF entries and saved Transformers checkpoints can fail to load on clean installs or silently ignore saved HF weights, depending on whether the stale paths exist locally.
Suggested fix
Use Transformers helpers such as cached_file or has_file to detect local and remote HF weights, delegate to super().from_pretrained() for real HF checkpoints, and avoid passing missing paths into the backend. Remove stale pretrained_*_path entries from bundled configs or resolve them to local packaged files.