mir-group / nequip

NequIP is a code for building E(3)-equivariant interatomic potentials
https://www.nature.com/articles/s41467-022-29939-5
MIT License
565 stars 124 forks source link

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

Open feifzhou opened 11 months ago

feifzhou commented 11 months ago

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

ThePauliPrinciple commented 8 months ago

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.