@@ -542,17 +542,17 @@ def _get_safe_alternatives(filename: str) -> Iterable[str]:
542542 yield filename [:- 4 ] + ".safetensors"
543543
544544
545- def _get_license_from_hf_hub (hf_hub_id : str | None ) -> str | None :
545+ def _get_license_from_hf_hub (model_id : str | None , hf_hub_id : str | None ) -> str | None :
546546 """Retrieve license information for a model from Hugging Face Hub.
547547
548548 Fetches the license field from the model card metadata on Hugging Face Hub
549- for the specified model. This function is called lazily when the license
550- attribute is accessed on PretrainedCfg objects that don't have an explicit
551- license set.
549+ for the specified model. Returns None if the model is not found, if
550+ huggingface_hub is not installed, or if the model is marked as "untrained".
552551
553552 Args:
554- hf_hub_id: The Hugging Face Hub model ID (e.g., 'organization/model').
555- If None or empty, returns None as license cannot be determined.
553+ model_id: The model identifier/name. In the case of None we assume an untrained model.
554+ hf_hub_id: The Hugging Face Hub organization/user ID. If it is None,
555+ we will return None as we cannot infer the license terms.
556556
557557 Returns:
558558 The license string in lowercase if found, None otherwise.
@@ -566,17 +566,17 @@ def _get_license_from_hf_hub(hf_hub_id: str | None) -> str | None:
566566 _logger .warning (msg = msg )
567567 return None
568568
569- if hf_hub_id is None or hf_hub_id == "timm/" :
569+ if not ( model_id and hf_hub_id ) :
570570 return None
571571
572+ repo_id : str = hf_hub_id + model_id
573+
572574 try :
573- info = model_info (repo_id = hf_hub_id )
575+ info = model_info (repo_id = repo_id )
574576
575577 except RepositoryNotFoundError :
576578 # TODO: any wish what happens here? @rwightman
577- return None
578-
579- except Exception as _ :
579+ print (repo_id )
580580 return None
581581
582582 license = info .card_data .get ("license" ).lower () if info .card_data else None
0 commit comments