Different results of two APIs of the hub

Hello,
I am wondering what’s the difference between these both usages of the API’s,
both usages produce model cards but have different outcomes:
One of them results None and the other one produces an output:

from huggingface_hub import HfApi

hf_api = HfApi()

model_id = 'typeform/distilbert-base-uncased-mnli'
model_info = hf_api.model_info(model_id)
print(model_info.last_modified) # prints: datetime.datetime(2023, 3, 22, 8, 49, tzinfo=datetime.timezone.utc)
from huggingface_hub import list_models

# Fetch all models
models = list_models()

# Filter for the desired model
desired_model = "typeform/distilbert-base-uncased-mnli"
matching_model = next((model for model in models if model.modelId == desired_model), None)
print(matching_model.last_modified) # prints None

Thanks!

1 Like

I think this is to reduce the load on the Hub, but anyway, by default, heavy data is not fetched, so you need to add full=True (for last_modified, etc.) or cardData=True (for cardData).

from huggingface_hub import HfApi

hf_api = HfApi()

model_id = 'typeform/distilbert-base-uncased-mnli'
model_info = hf_api.model_info(model_id)
print(model_info.last_modified) # prints: datetime.datetime(2023, 3, 22, 8, 49, tzinfo=datetime.timezone.utc)

from huggingface_hub import list_models

# Fetch all models
# models = list_models()
models = list_models(full=True)

# Filter for the desired model
desired_model = "typeform/distilbert-base-uncased-mnli"
matching_model = next((model for model in models if model.modelId == desired_model), None)
print(matching_model.last_modified) # prints None

"""
2023-03-22 08:49:00+00:00
2023-03-22 08:49:00+00:00
"""

Makes sense, thanks!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.