Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for modular with fast image processors #35379

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yonigozlan
Copy link
Member

What does this PR do?

Add support for using modular with fast image processors

Also add a fix for using modular on files other than modeling, which seem to have been broken by a recent change

Who can review?

@Cyrilvallez

Comment on lines +127 to +143
def post_process_segmentation():
raise NotImplementedError("Segmentation post-processing is not implemented for Deformable DETR yet.")

def post_process_instance():
raise NotImplementedError("Instance post-processing is not implemented for Deformable DETR yet.")

def post_process_panoptic():
raise NotImplementedError("Panoptic post-processing is not implemented for Deformable DETR yet.")

def post_process_instance_segmentation():
raise NotImplementedError("Segmentation post-processing is not implemented for Deformable DETR yet.")

def post_process_semantic_segmentation():
raise NotImplementedError("Semantic segmentation post-processing is not implemented for Deformable DETR yet.")

def post_process_panoptic_segmentation():
raise NotImplementedError("Panoptic segmentation post-processing is not implemented for Deformable DETR yet.")
Copy link
Member Author

@yonigozlan yonigozlan Dec 21, 2024

Choose a reason for hiding this comment

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

Here I wanted to remove these inherited functions. Somehow this works, but I'm not sure if there is a better way to do this?

Using modular the other way (with DetrImageProcessorFast inheriting from DeformableDetrImageProcessorFast) would solve the problem, but this wouldn't make sense chronologically.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the only way to "properly" do it!

Comment on lines +553 to +575
def from_dict():
raise NotImplementedError("No need to override this method for RT-DETR yet.")

def post_process():
raise NotImplementedError("Post-processing is not implemented for RT-DETR yet.")

def post_process_segmentation():
raise NotImplementedError("Segmentation post-processing is not implemented for RT-DETR yet.")

def post_process_instance():
raise NotImplementedError("Instance post-processing is not implemented for RT-DETR yet.")

def post_process_panoptic():
raise NotImplementedError("Panoptic post-processing is not implemented for RT-DETR yet.")

def post_process_instance_segmentation():
raise NotImplementedError("Segmentation post-processing is not implemented for RT-DETR yet.")

def post_process_semantic_segmentation():
raise NotImplementedError("Semantic segmentation post-processing is not implemented for RT-DETR yet.")

def post_process_panoptic_segmentation():
raise NotImplementedError("Panoptic segmentation post-processing is not implemented for RT-DETR yet.")
Copy link
Member Author

Choose a reason for hiding this comment

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

same here

Comment on lines +13 to +15
if dep_name == node_name:
# Skip self dependencies for topological sort as they create cycles
continue
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the case in ijepa for example, where we import IJepaConfig in modular

Copy link
Collaborator

Choose a reason for hiding this comment

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

that's quite an edge case!

@@ -54,7 +59,7 @@ def extract_classes_and_imports(file_path):
for node in ast.walk(tree):
if isinstance(node, (ast.Import, ast.ImportFrom)):
module = node.module if isinstance(node, ast.ImportFrom) else None
if module and (".modeling_" in module):
if module and (".modeling_" in module or "transformers.models" in module):
Copy link
Member Author

@yonigozlan yonigozlan Dec 21, 2024

Choose a reason for hiding this comment

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

@ArthurZucker @Cyrilvallez This was changed in a recent PR, but seems to have broken modular for generating files other than modeling

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, let's be more restrictive I think I was trying to avoid imports that are not from a modeling code directly, like models.auto etc. Can you make sure the order is still correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

The order was off for instruct_blib_video, because llava_next was listed twice as a dep. I added a check right after this line to avoid this and now the order is the same as it was

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

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 +127 to +143
def post_process_segmentation():
raise NotImplementedError("Segmentation post-processing is not implemented for Deformable DETR yet.")

def post_process_instance():
raise NotImplementedError("Instance post-processing is not implemented for Deformable DETR yet.")

def post_process_panoptic():
raise NotImplementedError("Panoptic post-processing is not implemented for Deformable DETR yet.")

def post_process_instance_segmentation():
raise NotImplementedError("Segmentation post-processing is not implemented for Deformable DETR yet.")

def post_process_semantic_segmentation():
raise NotImplementedError("Semantic segmentation post-processing is not implemented for Deformable DETR yet.")

def post_process_panoptic_segmentation():
raise NotImplementedError("Panoptic segmentation post-processing is not implemented for Deformable DETR yet.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the only way to "properly" do it!

]
return encoded_inputs

# Copied from transformers.models.rt_detr.image_processing_rt_detr.RTDetrImageProcessor.post_process_object_detection
Copy link
Collaborator

Choose a reason for hiding this comment

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

modular == no need for copied from -> you are missing an iinheritance here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes ideally I would want to inherit this function from the slow rtdetr image processor, but that would mean I'd have to inherit from two different models and this doesn't seem to be supported.
I just removed the copied from for now.

Comment on lines +13 to +15
if dep_name == node_name:
# Skip self dependencies for topological sort as they create cycles
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's quite an edge case!

@@ -54,7 +59,7 @@ def extract_classes_and_imports(file_path):
for node in ast.walk(tree):
if isinstance(node, (ast.Import, ast.ImportFrom)):
module = node.module if isinstance(node, ast.ImportFrom) else None
if module and (".modeling_" in module):
if module and (".modeling_" in module or "transformers.models" in module):
Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, let's be more restrictive I think I was trying to avoid imports that are not from a modeling code directly, like models.auto etc. Can you make sure the order is still correct?

Comment on lines +1662 to +1666
file_name_prefix = file_type.split("*")[0]
file_name_suffix = file_type.split("*")[-1] if "*" in file_type else ""
new_file_name = modular_file.replace("modular_", f"{file_name_prefix}_").replace(
".py", f"{file_name_suffix}.py"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is enabled by this? 🤗

Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike other modeling files, fast image processing files have a suffix (_fast), so this is a way to account for that when writing or reading those files. It's also why I defined the file type for fast image processors as image_processing*_fast here



class DeformableDetrImageProcessorFast(DetrImageProcessorFast):
# Copied from transformers.models.deformable_detr.image_processing_deformable_detr.DeformableDetrImageProcessor.post_process
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should not have copied from in modular!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sorry about that, same reason as for RT-DETR. I have removed them from now

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.

3 participants