Skip to content

Conversation

@Cyrilvallez
Copy link
Member

@Cyrilvallez Cyrilvallez commented Apr 28, 2025

What does this PR do?

As per the title. See #36895 (comment) for details. It's mostly an issue for all the detr models, as they share the suffix in the base name.

cc @qubvel for viz!

@github-actions github-actions bot marked this pull request as draft April 28, 2025 10:58
@github-actions
Copy link
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@Cyrilvallez Cyrilvallez marked this pull request as ready for review April 28, 2025 10:59
@HuggingFaceDocBuilderDev

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.

Comment on lines -32 to -48
# Check that adding the second base class correctly set the parent, even though in clip it does not have the "Vision" part
class Multimodal2VisionSdpaAttention(CLIPSdpaAttention, Multimodal2VisionAttention):
pass


# Check that adding the second base class correctly set the parent, even though in clip it does not have the "Vision" part
class Multimodal2VisionFlashAttention2(CLIPFlashAttention2, Multimodal2VisionAttention):
pass


MULTIMODAL2_VISION_ATTENTION_CLASSES = {
"eager": Multimodal2VisionAttention,
"sdpa": Multimodal2VisionSdpaAttention,
"flash_attention_2": Multimodal2VisionFlashAttention2,
}


Copy link
Member Author

Choose a reason for hiding this comment

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

They no longer exist

Comment on lines +1768 to +1778
else:
for i, model_name in enumerate(args.files_to_parse):
if os.sep not in model_name:
full_path = os.path.join("src", "transformers", "models", model_name, f"modular_{model_name}.py")
# If it does not exist, try in the examples section
if not os.path.isfile(full_path):
full_path = os.path.join("examples", "modular-transformers", f"modular_{model_name}.py")
# We did not find it anywhere
if not os.path.isfile(full_path):
raise ValueError(f"Cannot find a modular file for {model_name}. Please provide the full path.")
args.files_to_parse[i] = full_path
Copy link
Member Author

Choose a reason for hiding this comment

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

Because I'm too lazy to write the full path each time. It allows to do e.g.
python utils/modular_model_converter.py --files_to_parse aria instead of python utils/modular_model_converter.py --files_to_parse src/transformers/models/aria/modular_aria.py

Copy link
Collaborator

Choose a reason for hiding this comment

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

big win haha

Copy link
Contributor

Choose a reason for hiding this comment

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

love it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yessss 🙏

@Cyrilvallez Cyrilvallez mentioned this pull request Apr 28, 2025
5 tasks
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

thanks!

Comment on lines +1768 to +1778
else:
for i, model_name in enumerate(args.files_to_parse):
if os.sep not in model_name:
full_path = os.path.join("src", "transformers", "models", model_name, f"modular_{model_name}.py")
# If it does not exist, try in the examples section
if not os.path.isfile(full_path):
full_path = os.path.join("examples", "modular-transformers", f"modular_{model_name}.py")
# We did not find it anywhere
if not os.path.isfile(full_path):
raise ValueError(f"Cannot find a modular file for {model_name}. Please provide the full path.")
args.files_to_parse[i] = full_path
Copy link
Collaborator

Choose a reason for hiding this comment

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

big win haha

@Cyrilvallez Cyrilvallez merged commit 4602059 into main Apr 29, 2025
11 checks passed
@Cyrilvallez Cyrilvallez deleted the modular-prefix branch April 29, 2025 08:43
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
…e a common name suffix (huggingface#37829)

* first try

* Fix and set examples

* style

* fix

* Update modular_test_detr.py

* Update image_processing_new_imgproc_model.py

* Update modular_model_converter.py
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.

6 participants