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

❓ [QUESTION] Custom layer with control structure not supported? #356

Open
feifzhou opened this issue Jul 28, 2023 · 1 comment
Open

❓ [QUESTION] Custom layer with control structure not supported? #356

feifzhou opened this issue Jul 28, 2023 · 1 comment
Labels
question Further information is requested

Comments

@feifzhou
Copy link

I implemented a customized layer which does different things depending on the data

...
forward(self, data):
if data.some_criterion:
do this
else:
do that
..

However, the autograd computation of forces fails on the first step:

return Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
RuntimeError: One of the differentiated Tensors appears to not have been used in the graph. Set allow_unused=True if this is the desired behavior.

Is it because of JIT? Is there a way to make control structure work in a customized operator?

thank you

@feifzhou feifzhou added the question Further information is requested label Jul 28, 2023
@ThePauliPrinciple
Copy link

A practical solution is to calculate both cases for all elements, multiply them with a mask corresponding to the condition and add the two results together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants