From 6ed2b10942becf0d67e52c07ac852c6f83db27f0 Mon Sep 17 00:00:00 2001 From: Rishiraj Acharya <44090649+rishiraj@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:09:19 +0530 Subject: [PATCH] Bug Fix: Update hub.py to fix NoneType error (#33315) * Bug Fix: Update hub.py Bug: TypeError: argument of type 'NoneType' is not iterable Analysis: The error `TypeError: argument of type 'NoneType' is not iterable` suggests that `model_card.data.tags` is `None`, and the code is trying to iterate through it using `not in`. Fix: 1. **Check if `model_card.data.tags` is `None` before the loop**: Since you're checking the variable `tags` before the loop, you should also ensure that `model_card.data.tags` is not `None`. You can do this by initializing `model_card.data.tags` to an empty list if it's `None`. 2. **Updated code**: Add a check and initialize the `tags` if it is `None` before proceeding with the iteration. This way, if `model_card.data.tags` is `None`, it gets converted to an empty list before checking the contents. This prevents the `TypeError`. * Update hub.py --- src/transformers/utils/hub.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/transformers/utils/hub.py b/src/transformers/utils/hub.py index 92be9c0b0509..540c40294474 100644 --- a/src/transformers/utils/hub.py +++ b/src/transformers/utils/hub.py @@ -1198,6 +1198,9 @@ def create_and_tag_model_card( model_card = ModelCard.from_template(card_data, model_description=model_description) if tags is not None: + # Ensure model_card.data.tags is a list and not None + if model_card.data.tags is None: + model_card.data.tags = [] for model_tag in tags: if model_tag not in model_card.data.tags: model_card.data.tags.append(model_tag)