Skip to content

No more forcing separators#2279

Merged
echarlaix merged 20 commits into
mainfrom
stop-forcing-separators
Jun 17, 2025
Merged

No more forcing separators#2279
echarlaix merged 20 commits into
mainfrom
stop-forcing-separators

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented May 25, 2025

Copy link
Copy Markdown
Member

What does this PR do?

There's a lot of separators shenanigans we have to do every time we deal with model_types (or is it model-types 😅).
This PR removes that by using the names models were given in transformers.
Motivation for this PR is that in #2278 I was able to add the officially named "qwen3_moe" and hardest part was figuring out where it should be "qwen3-moe" and where "qwen3_moe" should be used.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@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.

@IlyasMoutawwakil
IlyasMoutawwakil marked this pull request as ready for review May 25, 2025 19:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the forced conversion of model type names by no longer replacing underscores with dashes, instead using the official model names from transformers. Key changes include updating test cases, exporter configurations, and documentation comments across multiple files to reflect the new naming convention without separator modifications.

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/onnxruntime/testing_utils.py Updated model name keys to use official naming (e.g., "blenderbot-small").
tests/onnxruntime/test_optimization.py and test_modeling.py Removed use of the replace() function when checking supported tasks.
tests/exporters/utils.py, tflite, onnx, etc. Modified model type keys to align with official naming conventions.
optimum/utils/normalized_config.py and related exporter files Eliminated forced underscore-to-dash conversion in model type handling.
optimum/exporters/tasks.py Updated task mappings and removed deprecated string manipulation.
Other files across tests and exporter modules Consistently applied new naming rules in both code and comments.
Comments suppressed due to low confidence (2)

optimum/utils/normalized_config.py:306

  • With the removal of forced separator conversion, please update the documentation to clearly specify the expected model_type format and ensure that users are aware of the new naming convention.
model_type = model_type.replace("_", "-")

optimum/exporters/tasks.py:1447

  • Since the transformation of model_type values has been removed, confirm that the documentation and internal guidelines are updated accordingly to reflect the new behavior.
model_type = model_type.lower().replace("_", "-")

@echarlaix echarlaix 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, thanks @IlyasMoutawwakil

Comment thread optimum/exporters/tasks.py
@@ -459,7 +459,7 @@ class TasksManager:
"question-answering",
onnx="BigBirdOnnxConfig",
),

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.

would you mind also checking that this doesn't break anything for others optimum-xxx like optimum-intel or optimum-neuron

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done for optimum-intel in huggingface/optimum-intel#1329
for optimum-neuron I see that they are still pinning optimum 1.23 🤔
I could give it a shot but only if they wanna also update @JingyaHuang

@IlyasMoutawwakil

Copy link
Copy Markdown
Member Author

here's the script for reference, it should always be ran with latest transformers

from transformers.models.auto.configuration_auto import CONFIG_MAPPING_NAMES

def replace_in_directory(directory, old_str, new_str):
    import os

    for root, dirs, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)

            # skip this file
            if file == "script.py":
                continue

            # skip non .py .txt and .json files
            if not (file.endswith(".py") or file.endswith(".txt") or file.endswith(".json")):
                continue

            try:
                with open(file_path, "r", encoding="utf-8") as f:
                    content = f.read()
                if old_str in content:
                    content = content.replace(old_str, new_str)
                    with open(file_path, "w", encoding="utf-8") as f:
                        f.write(content)

            except (UnicodeDecodeError, FileNotFoundError):
                # Skip files that cannot be read or do not exist
                continue


def correct_model_types():
    for model_type in CONFIG_MAPPING_NAMES.keys():
        if "-" in model_type:
            wrong_model_type = model_type.replace("-", "_")
        elif "_" in model_type:
            wrong_model_type = model_type.replace("_", "-")
        else:
            continue

        new_str = f'"{model_type}"'
        old_str = f'"{wrong_model_type}"'
        # replace all occurrences in current directory
        replace_in_directory(".", old_str, new_str)


def remove_separators_shenanigans():
    old_str = '.replace("_", "-")'
    new_str = ""
    replace_in_directory(".", old_str, new_str)
    old_str = '.replace("-", "_")'
    new_str = ""
    replace_in_directory(".", old_str, new_str)


if __name__ == "__main__":
    correct_model_types()
    remove_separators_shenanigans()
    print("Model types corrected.")

@echarlaix
echarlaix requested a review from JingyaHuang June 4, 2025 14:26
@echarlaix

Copy link
Copy Markdown
Collaborator

thanks a lot @IlyasMoutawwakil !! if that works for you we can merge after the next release to have some time to make sure this doesn't introduce any issue for other repos (optimum-neuron / optimum-executorch and others)

@echarlaix

Copy link
Copy Markdown
Collaborator

cc @JingyaHuang let us know if that works for you (might have an impact on optimum-neuron)

@echarlaix
echarlaix merged commit 5246fc8 into main Jun 17, 2025
35 of 37 checks passed
@echarlaix
echarlaix deleted the stop-forcing-separators branch June 17, 2025 14:05
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