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 conv ops for mindspore frontend #20138

Merged
merged 12 commits into from
Aug 12, 2023
Merged

Conversation

themaigod
Copy link
Contributor

Using the implemented code in: ivy/functional/frontends/torch/nn/functional/convolution_functions.py
I also try to write deformable_conv2d. It seems that there is no ivy api for simple achieving that. So if we want to achieve it, we need to implement it based on the source algorithm. I am not sure it is the correct way.

@themaigod
Copy link
Contributor Author

#20120

Copy link
Contributor

@iamjameskeane iamjameskeane left a comment

Choose a reason for hiding this comment

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

Hey,

Thanks for opening this PR!

You have only referenced an issue for Conv2d and not for the other implementations in this PR. We would need to close the other issues to avoid confusion! So maybe open issues for the other functions so that we can link them to this PR

Also, as part of this task, I think you are required to write tests for each of these functions.

Thanks

@themaigod
Copy link
Contributor Author

Hey,

Thanks for opening this PR!

You have only referenced an issue for Conv2d and not for the other implementations in this PR. We would need to close the other issues to avoid confusion! So maybe open issues for the other functions so that we can link them to this PR

Also, as part of this task, I think you are required to write tests for each of these functions.

Thanks

Thanks. I will write tests soon.

@themaigod
Copy link
Contributor Author

themaigod commented Jul 27, 2023

@jkeane508 Sorry about the delay. I have written the tests.
I saw in the same file, people annotated all the code, so I did too. Are these codes going to used when the whole mindspore frontend code finish?

@themaigod themaigod requested a review from iamjameskeane July 28, 2023 05:01
@iamjameskeane
Copy link
Contributor

@jkeane508 Sorry about the delay. I have written the tests. I saw in the same file, people annotated all the code, so I did too. Are these codes going to used when the whole mindspore frontend code finish?

Yea I think so!

Can you open issues for the other functions you've done in this PR. We can merge functions that haven't been linked as issues. Thanks!

@themaigod themaigod mentioned this pull request Jul 28, 2023
@themaigod
Copy link
Contributor Author

themaigod commented Jul 28, 2023

@jkeane508 Sorry about the delay. I have written the tests. I saw in the same file, people annotated all the code, so I did too. Are these codes going to used when the whole mindspore frontend code finish?

Yea I think so!

Can you open issues for the other functions you've done in this PR. We can merge functions that haven't been linked as issues. Thanks!

I have opened it. #20945 @jkeane508

@themaigod
Copy link
Contributor Author

@jkeane508 Sorry about the delay. I have written the tests. I saw in the same file, people annotated all the code, so I did too. Are these codes going to used when the whole mindspore frontend code finish?

Yea I think so!
Can you open issues for the other functions you've done in this PR. We can merge functions that haven't been linked as issues. Thanks!

I have opened it. #20945 @jkeane508

Sorry, I misunderstanded. Here:

@themaigod
Copy link
Contributor Author

@jkeane508

This was linked to issues Jul 31, 2023
@iamjameskeane iamjameskeane removed a link to an issue Jul 31, 2023
@iamjameskeane
Copy link
Contributor

Using the implemented code in: ivy/functional/frontends/torch/nn/functional/convolution_functions.py I also try to write deformable_conv2d. It seems that there is no ivy api for simple achieving that. So if we want to achieve it, we need to implement it based on the source algorithm. I am not sure it is the correct way.

Just reading about deformable conv2d. Is there a way to implement it using the source algorithm with functions that already exist in the Ivy functional API?

@themaigod
Copy link
Contributor Author

themaigod commented Jul 31, 2023

I find it a little confusing as well. It seems that many deep learning backend frameworks support deformable convolution directly, such as MindSpore, PyTorch, and PaddlePaddle, making it efficient to implement. You can see some examples in the GitHub issue comment I provided (#20945 (comment)). TensorFlow doesn't have native support for it, despite several pull requests attempting to add it. So it is not our duty.

For instance, PaddlePaddle provides documentation on how to use deformable convolution (https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/fluid/layers/deformable_conv_cn.html#paddle.fluid.layers.deformable_conv).

While personal implementations are available for other frameworks like PyTorch (https://github.com/oeway/pytorch-deform-conv) and TensorFlow (https://github.com/kastnerkyle/deform-conv/), they can be complex and might encounter efficiency issues, especially when implemented in Python (I guess) due to the number of reshape-related operations involved.

Given the complexity and lack of equivalent functions in Ivy, I suggest following the rule stated in the documentation: "In case a frontend function is complex and there is no equivalent Ivy function to use, it is strongly advised to add that function to our Experimental API."

I have another concern about deformable convolution being currently required only for the MindSpore frontend, while other frameworks like PyTorch (torchvision) and PaddlePaddle have this API but haven't implemented it in the frontend. So, do we really need this?

If you want, I can try to follow the implementation in this GitHub repository (https://github.com/kastnerkyle/deform-conv/), but I think that it might not make much sense. I hope this helps clarify the situation. Let me know if you have any further comment! @jkeane508

@iamjameskeane
Copy link
Contributor

I find it a little confusing as well. It seems that many deep learning backend frameworks support deformable convolution directly, such as MindSpore, PyTorch, and PaddlePaddle, making it efficient to implement. You can see some examples in the GitHub issue comment I provided (#20945 (comment)). TensorFlow doesn't have native support for it, despite several pull requests attempting to add it. So it is not our duty.

For instance, PaddlePaddle provides documentation on how to use deformable convolution (https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/fluid/layers/deformable_conv_cn.html#paddle.fluid.layers.deformable_conv).

While personal implementations are available for other frameworks like PyTorch (https://github.com/oeway/pytorch-deform-conv) and TensorFlow (https://github.com/kastnerkyle/deform-conv/), they can be complex and might encounter efficiency issues, especially when implemented in Python (I guess) due to the number of reshape-related operations involved.

Given the complexity and lack of equivalent functions in Ivy, I suggest following the rule stated in the documentation: "In case a frontend function is complex and there is no equivalent Ivy function to use, it is strongly advised to add that function to our Experimental API."

I have another concern about deformable convolution being currently required only for the MindSpore frontend, while other frameworks like PyTorch (torchvision) and PaddlePaddle have this API but haven't implemented it in the frontend. So, do we really need this?

If you want, I can try to follow the implementation in this GitHub repository (https://github.com/kastnerkyle/deform-conv/), but I think that it might not make much sense. I hope this helps clarify the situation. Let me know if you have any further comment! @jkeane508

Yep, having looked at all the options. I think what makes the most sense is adding this to the Ivy Experimental API. Would you be keen to do this or shall I open an issue?

@themaigod themaigod mentioned this pull request Aug 2, 2023
@themaigod
Copy link
Contributor Author

themaigod commented Aug 2, 2023

I open one - [ivy.deform_conv2d] #21187 by Feature request. I can continue on it and it will take some time as it will be the first time for me to work on ivy functional api and backend api.

Could you help me to link conv1d and conv3d to mindspore frontend to-do list (because they are not in the list)? And then we can merge this PR and close these three issues (conv1d, conv2d, conv3d).

Thanks. @jkeane508

@themaigod
Copy link
Contributor Author

I open one - [ivy.deform_conv2d] #21187 by Feature request. I can continue on it and it will take some time as it will be the first time for me to work on ivy functional api and backend api.

Could you help me to link conv1d and conv3d to mindspore frontend to-do list (because they are not in the list)? And then we can merge this PR and close these three issues (conv1d, conv2d, conv3d).

Thanks. @jkeane508

I am not sure this issue (#21187 ) is opened with correct labels, and I guess that it need to be reviewed. Many thanks if you can help me check it.

@iamjameskeane
Copy link
Contributor

I open one - [ivy.deform_conv2d] #21187 by Feature request. I can continue on it and it will take some time as it will be the first time for me to work on ivy functional api and backend api.
Could you help me to link conv1d and conv3d to mindspore frontend to-do list (because they are not in the list)? And then we can merge this PR and close these three issues (conv1d, conv2d, conv3d).
Thanks. @jkeane508

I am not sure this issue (#21187 ) is opened with correct labels, and I guess that it need to be reviewed. Many thanks if you can help me check it.

Yea this looks good!

@iamjameskeane iamjameskeane requested a review from xoiga123 August 4, 2023 09:34
@iamjameskeane
Copy link
Contributor

Hey @xoiga123,

Just wanted to request a review from you before merging if that's ok :)

@themaigod
Copy link
Contributor Author

@xoiga123 pls review. Thanks.

Copy link
Contributor

@xoiga123 xoiga123 left a comment

Choose a reason for hiding this comment

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

Hey @themaigod, sorry for the super late reply 😅

The implementation and the reasoning all sound good, I only have some nitpicks about the tests.

Also, wouldn't it be more correct to place the tests into

test_mindspore/test_ops/test_function/test_mindspore_nn_func.py

instead of the current

test_mindspore/test_ops/test_mindspore_nn_func.py

I'm not sure why the file got created in the first place, as nn_func only exists in mindspore.ops.function.nn_func and not mindspore.ops.nn_func

#
# # conv1d
# @handle_frontend_test(
# fn_tree="mindspore.ops.Conv1d",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a class, the correct functional path would be mindspore.ops.function.nn_func.conv1d

# fn_tree="mindspore.ops.Conv1d",
# dtype_vals=x_and_filters(dim=1),
# )
# def test_torch_conv1d(
Copy link
Contributor

Choose a reason for hiding this comment

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

test_mindspore_conv1d

#
#
# @handle_frontend_test(
# fn_tree="mindspore.ops.Conv2d",
Copy link
Contributor

Choose a reason for hiding this comment

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

mindspore.ops.function.nn_func.conv2d

# fn_tree="mindspore.ops.Conv2d",
# dtype_vals=x_and_filters(dim=2),
# )
# def test_torch_conv2d(
Copy link
Contributor

Choose a reason for hiding this comment

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

test_mindspore_conv2d

#
#
# @handle_frontend_test(
# fn_tree="mindspore.ops.Conv3d",
Copy link
Contributor

Choose a reason for hiding this comment

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

mindspore.ops.function.nn_func.conv3d

# fn_tree="mindspore.ops.Conv3d",
# dtype_vals=x_and_filters(dim=3),
# )
# def test_torch_conv3d(
Copy link
Contributor

Choose a reason for hiding this comment

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

test_mindspore_conv3d

@themaigod themaigod requested a review from xoiga123 August 11, 2023 12:31
@themaigod
Copy link
Contributor Author

@xoiga123 Sorry for the mistakes in tests. I have fixed the name and the position issues.

Copy link
Contributor

@iamjameskeane iamjameskeane left a comment

Choose a reason for hiding this comment

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

LGTM! :)

@iamjameskeane iamjameskeane merged commit 9f193db into ivy-llc:master Aug 12, 2023
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.

conv3d conv1d conv2d
3 participants