Skip to content

Fix regression on Processor.save_pretrained caused by #31691#32921

Merged
ArthurZucker merged 1 commit into
huggingface:mainfrom
leloykun:fc--fix-save-pretrained
Aug 22, 2024
Merged

Fix regression on Processor.save_pretrained caused by #31691#32921
ArthurZucker merged 1 commit into
huggingface:mainfrom
leloykun:fc--fix-save-pretrained

Conversation

@leloykun

@leloykun leloykun commented Aug 21, 2024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fix regression on Processor.save_pretrained caused by #31691

tl;dr: a month ago, we made a change that removed "chat_template" from processor_dict when saving a processor. This caused processor_config.json to not get saved at all. See:

processor_dict = self.to_dict()
chat_template = processor_dict.pop("chat_template", None)
if chat_template is not None:
    chat_template_json_string = json.dumps({"chat_template": chat_template}, indent=2, sort_keys=True) + "\n"
    with open(output_chat_template_file, "w", encoding="utf-8") as writer:
        writer.write(chat_template_json_string)
    logger.info(f"chat template saved in {output_chat_template_file}")

# For now, let's not save to `processor_config.json` if the processor doesn't have extra attributes and
# `auto_map` is not specified.
if set(processor_dict.keys()) != {"processor_class"}:
    self.to_json_file(output_processor_file)
    logger.info(f"processor saved in {output_processor_file}")

but we kept these lines as is:

if set(self.to_dict().keys()) == {"processor_class"}:
    return []
return [output_processor_file]

So, for a month now, we've not been saving processor_config.json but still returning [processor_config.json] as the saved files. This has caused a test in my other PR (#32906) to fail

Who can review?

@amyeroberts @zucchini-nlp

@leloykun leloykun marked this pull request as ready for review August 21, 2024 14:40

@zucchini-nlp zucchini-nlp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, thanks for fixing!

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tho we need a small test to make sure we don't break that again 😓

@zucchini-nlp

Copy link
Copy Markdown
Member

I guess that had a tests, but it wasn't triggered when the prev PR was merged. I ran only VLMs when merging the prev PR...

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Okay, merging and patching!

@ArthurZucker ArthurZucker merged commit 273c0af into huggingface:main Aug 22, 2024
ArthurZucker pushed a commit that referenced this pull request Aug 22, 2024
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants