-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
base: main
Are you sure you want to change the base?
Add support for modular with fast image processors #35379
Conversation
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.") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
if dep_name == node_name: | ||
# Skip self dependencies for topological sort as they create cycles | ||
continue |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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.") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
if dep_name == node_name: | ||
# Skip self dependencies for topological sort as they create cycles | ||
continue |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
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" | ||
) |
There was a problem hiding this comment.
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? 🤗
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
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