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

Error reporting that leaky ReLU is not yet implemented for PyTorch conversion #736

Closed
jbmaxwell opened this issue Jun 24, 2020 · 11 comments
Closed
Assignees
Labels
bug Unexpected behaviour that should be corrected (type) PyTorch (traced) question Response providing clarification needed. Will not be assigned to a release. (type)

Comments

@jbmaxwell
Copy link

I was trying to convert a ClusterGAN from PyTorch to CoreML yesterday and got an error about leaky_relu not being implemented yet. Is there a projected timeline for this? It seems to me leaky ReLU is a very popular activation function.
As a workaround, is there a reasonably simple way to write my own for the converter to use?

Any thoughts appreciated.

@jbmaxwell jbmaxwell added the question Response providing clarification needed. Will not be assigned to a release. (type) label Jun 24, 2020
@aseemw aseemw added the bug Unexpected behaviour that should be corrected (type) label Jun 24, 2020
@aseemw
Copy link
Collaborator

aseemw commented Jun 24, 2020

Hi @jbmaxwell thanks for reporting the issue!
Yes it does seem the leaky relu mapping function is not implemented yet. I see the one for relu but not for leaky relu.

It should be added in the upcoming beta releases of coremltools.

As for the timeline, generally coremltools is aligned with the Core ML framework which is aligned with the rest of the Apple OS software.

@jbmaxwell
Copy link
Author

Okay, fingers crossed that we'll see it in the next beta—and that it will drop relatively soon! :)

I have the model running using LibTorch for now, but I'm curious about performance and have a feeling that the CoreML version will be better optimized for the hardware (correct me if I'm wrong).

@srikris
Copy link
Contributor

srikris commented Jun 25, 2020

@jbmaxwell To clarify, this implementation is a good reference right? (https://github.com/zhampel/clusterGAN)

@jbmaxwell
Copy link
Author

Yes, that's the one.

@leovinus2001
Copy link
Contributor

Hitting the same issue
RuntimeError: PyTorch convert function for op leaky_relu_ not implemented
with a non GAN model.
Hence +1 for please add it in the next beta

@leovinus2001
Copy link
Contributor

leovinus2001 commented Jun 25, 2020

Here a small test case for your convenience. @aseemw @srikris
Change bool 'showBug' for testing on/off.
testLeakyRelu.jun25.txt

@dlawrences
Copy link

Running in the same issue when converting YOLO Object Detection models to CoreML.

I am using ReLU as a work-around for now, could we also supply custom activation functions instead of LeakyReLU?

Thanks

@HanClinto
Copy link

@dlawrences Were you able to switch ReLU out for LeakyReLU after training, or did you need to re-train the model from scratch after you did that? If so, how did you change this?

@dlawrences
Copy link

@dlawrences Were you able to switch ReLU out for LeakyReLU after training, or did you need to re-train the model from scratch after you did that? If so, how did you change this?

I have changed the model architecture to use nn.ReLU (https://pytorch.org/docs/master/generated/torch.nn.ReLU.html) instead of nn.LeakyReLU (https://pytorch.org/docs/master/generated/torch.nn.LeakyReLU.html). I don't think the weights trained for the LeakyReLU activation function would have worked that well on plain ReLU tbh - I would expect some gradients would go to zero really fast for the latter one.

@DawerG
Copy link
Collaborator

DawerG commented Jul 7, 2020

This PR #758 adds leaky_relu and upsample_nearest2d layers. Can you please try converting this model using the change in this PR?

@leovinus2001
Copy link
Contributor

Pulled coremltools, rebuilt coremltools from TOT, reran the testcase I provided above, and that passes now. Seems like LeakyRelu works. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour that should be corrected (type) PyTorch (traced) question Response providing clarification needed. Will not be assigned to a release. (type)
Projects
None yet
Development

No branches or pull requests

8 participants