# Sort models by parameter count

**URL:** <https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305>\
**Category:** Site Feedback\
**Created:** [August 28, 2024, 4:55am UTC](https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305 "2024-08-28T04:55:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![idkthrowaway123123](https://avatars.discourse-cdn.com/v4/letter/i/0ea827/32.png) [@idkthrowaway123123](https://discuss.huggingface.co/u/idkthrowaway123123)\
**Post date:** [August 28, 2024, 4:55am UTC](https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305/1 "2024-08-28T04:55:38Z")

</div>

I’m trying to find out what my poor 4070 TI can handle in terms of fine-tuning power for LLMs. I’ve currently narrowed it down to the fact GPT2-Medium (345m) is fine but GPT2-Large (774m) is too much 😁. I’m still looking to fine tune it, therefore it would be very helpful if you could sort models by parameter size on the website, so I can filter quickly. At this moment I had to look very long to discover Bloom has a 560m variant!

That is all, thank you!

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/52583_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [August 28, 2024, 8:03am UTC](https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305/2 "2024-08-28T08:03:43Z")

</div>

hi @idkthrowaway123123  
I hope api can help you a bit about it:

[https://huggingface.co/api/models?filter=safetensors](https://huggingface.co/api/models?filter=safetensors) returns all models with safetensors tag. And the following returns number of safetensors parameters:  
[https://huggingface.co/api/models/model\_id\_x](https://huggingface.co/api/models/model_id_x)

example:  
[https://huggingface.co/api/models/google-bert/bert-base-german-cased](https://huggingface.co/api/models/google-bert/bert-base-german-cased)

You can add more tags and other parameters to filter better:  
[https://huggingface.co/api/models?pipeline\_tag=fill-mask&filter=safetensors](https://huggingface.co/api/models?pipeline_tag=fill-mask&filter=safetensors)

> **[Hub API Endpoints](https://huggingface.co/docs/hub/en/api)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

I know it’s not exactly what you want 🙂

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/52583_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [August 28, 2024, 8:40am UTC](https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305/3 "2024-08-28T08:40:03Z")

</div>

Better solution with Hub Python Library:

Filtering models:

> **[HfApi Client](https://huggingface.co/docs/huggingface_hub/v0.24.6/en/package_reference/hf_api)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

List repo files:

> **[HfApi Client](https://huggingface.co/docs/huggingface_hub/v0.24.6/en/package_reference/hf_api#huggingface_hub.HfApi.list_repo_files)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

Get file url:

> **[Downloading files](https://huggingface.co/docs/huggingface_hub/v0.24.6/en/package_reference/file_download#huggingface_hub.hf_hub_url)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

And get file metadata (which contains size):

> **[Downloading files](https://huggingface.co/docs/huggingface_hub/v0.24.6/en/package_reference/file_download#huggingface_hub.get_hf_file_metadata)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![idkthrowaway123123](https://avatars.discourse-cdn.com/v4/letter/i/0ea827/32.png) [@idkthrowaway123123](https://discuss.huggingface.co/u/idkthrowaway123123)\
**Post date:** [August 29, 2024, 12:40am UTC](https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305/4 "2024-08-29T00:40:18Z")

</div>

Nice! I’m new to this place so didn’t know this yet, but i will check that out. Thanks a bunch!

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/52583_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [August 29, 2024, 5:33pm UTC](https://discuss.huggingface.co/t/sort-models-by-parameter-count/104305/5 "2024-08-29T17:33:55Z")

</div>

You can add filter option for `list_models` and change/add condition for file size.

```auto
from huggingface_hub import list_models, list_repo_files, hf_hub_url, get_hf_file_metadata

models = list_models()

for model in models:
  files = list_repo_files(model.id)
  for file in files:
    if file[-4:]==".bin":
      file_size = get_hf_file_metadata(hf_hub_url(model.id,file)).size
      if file_size // 1000000 > 1000: # if file bigger than 1gb
        print(model)
        print(f"{file_size // 1000000} mb")
        print("https://huggingface.co/"+model.id)

```

You can filter by #download/likes etc…

`ModelInfo(id='google-bert/bert-large-uncased', author=None, sha=None, created_at=datetime.datetime(2022, 3, 2, 23, 29, 4, tzinfo=datetime.timezone.utc), last_modified=None, private=False, gated=None, disabled=None, downloads=2524614, downloads_all_time=None, likes=108, library_name='transformers', tags=['transformers', 'pytorch', 'tf', 'jax', 'rust', 'safetensors', 'bert', 'fill-mask', 'en', 'dataset:bookcorpus', 'dataset:wikipedia', 'arxiv:1810.04805', 'license:apache-2.0', 'autotrain_compatible', 'endpoints_compatible', 'region:us'], pipeline_tag='fill-mask', mask_token=None, card_data=None, widget_data=None, model_index=None, config=None, transformers_info=None, siblings=None, spaces=None, safetensors=None)`
