Repository: huggingface/huggingface_hub
Pull request #152 (2021-07-01 10:09:46)

Add config to list_models
Here is an example from `list_models` for `adapter-transformers`.

FYI @calpt

```
ModelInfo: {
	modelId: AdapterHub/roberta-base-pf-sick
	sha: b4cbe28cab4c4ac47d1cb431c73ac7917e38c0d0
	lastModified: 2021-06-16T16:11:08.000Z
	tags: ['roberta', 'en', 'dataset:sick', 'adapter-transformers']
	pipeline_tag: None
	siblings: [ModelFile(rfilename='.gitattributes'), ModelFile(rfilename='README.md'), ModelFile(rfilename='adapter_config.json'), ModelFile(rfilename='head_config.json'), ModelFile(rfilename='pytorch_adapter.bin'), ModelFile(rfilename='pytorch_model_head.bin')]
	config: {'model_type': 'roberta', 'adapter_transformers': {'model_name': 'roberta-base', 'model_class': 'RobertaModelWithHeads'}}
	private: False
	library_name: adapter-transformers
}
ModelInfo: {
	modelId: calpt/adapter-bert-base-squad1
	sha: 9d63a706848c70bbd52ab7124dba3256e659d12a
	lastModified: 2021-06-08T10:13:48.000Z
	tags: ['bert', 'adapter-transformers', 'adapterhub:qa/squad1']
	pipeline_tag: None
	siblings: [ModelFile(rfilename='.gitattributes'), ModelFile(rfilename='README.md'), ModelFile(rfilename='adapter_config.json'), ModelFile(rfilename='head_config.json'), ModelFile(rfilename='pytorch_adapter.bin'), ModelFile(rfilename='pytorch_model_head.bin')]
	config: {'model_type': 'bert', 'adapter_transformers': {'model_name': 'bert-base-uncased', 'model_class': 'BertModelWithHeads'}}
	private: False
	library_name: adapter-transformers
}
ModelInfo: {
	modelId: calpt/adapter_test
	sha: 000caa859c43bc5bc6825db4bd8c003211f95d7a
	lastModified: 2021-06-28T12:01:43.000Z
	tags: ['bert', 'dataset:imdb', 'adapter-transformers', 'adapterhub:sentiment/imdb']
	pipeline_tag: None
	siblings: [ModelFile(rfilename='README.md'), ModelFile(rfilename='adapter_config.json'), ModelFile(rfilename='head_config.json'), ModelFile(rfilename='pytorch_adapter.bin'), ModelFile(rfilename='pytorch_model_head.bin')]
	config: {'model_type': 'bert', 'adapter_transformers': {'model_name': 'bert-base-uncased', 'model_class': 'BertModelWithHeads'}}
	private: False
	library_name: adapter-transformers
}
```



Patch:
diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py
index 72c5aeb8..42dd2122 100644
--- a/src/huggingface_hub/hf_api.py
+++ b/src/huggingface_hub/hf_api.py
@@ -201,6 +201,7 @@ class HfApi:
         direction: Optional[Literal[-1]] = None,
         limit: Optional[int] = None,
         full: Optional[bool] = None,
+        fetch_config: Optional[bool] = None,
     ) -> List[ModelInfo]:
         """
         Get the public list of all the models on huggingface.co
@@ -238,6 +239,8 @@ class HfApi:
             full (:obj:`bool`, `optional`):
                 Whether to fetch all model data, including the `lastModified`, the `sha`, the files and the `tags`.
                 This is set to `True` by default when using a filter.
+            fetch_config (:obj:`bool`, `optional`):
+                Whether to fetch the model configs as well. This is not included in `full` due to its size.
 
         """
         path = "{}/api/models".format(self.endpoint)
@@ -256,6 +259,8 @@ class HfApi:
                 params.update({"full": True})
             elif "full" in params:
                 del params["full"]
+        if fetch_config is not None:
+            params.update({"config": fetch_config})
         r = requests.get(path, params=params)
         r.raise_for_status()
         d = r.json()


Test patch:
diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml
index 65db1ccb..7b84647d 100644
--- a/.github/workflows/python-tests.yml
+++ b/.github/workflows/python-tests.yml
@@ -3,7 +3,7 @@ name: Python tests
 on:
   push:
     branches:
-      - *
+      - main
     paths-ignore:
       - "interfaces/**"
       - "widgets/**"
diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py
index 6274e2b5..6a4e9775 100644
--- a/tests/test_hf_api.py
+++ b/tests/test_hf_api.py
@@ -341,6 +341,18 @@ class HfApiPublicTest(unittest.TestCase):
         self.assertIsInstance(model, ModelInfo)
         self.assertTrue(all(tag in model.tags for tag in ["bert", "jax"]))
 
+    @with_production_testing
+    def test_list_models_with_config(self):
+        _api = HfApi()
+        models = _api.list_models(
+            filter="adapter-transformers", fetch_config=True, limit=20
+        )
+        found_configs = 0
+        for model in models:
+            if model.config:
+                found_configs = found_configs + 1
+        self.assertGreater(found_configs, 0)
+
     @with_production_testing
     def test_model_info(self):
         _api = HfApi()