Thanks for your responses. I probably wasn’t clear, that this isn’t the actual program I’m running (this simplified version works for me also), but rather I was using it to illustrate that there’s a difference between whether the scripted function is defined in the global scope versus local scope. Adding on to this, it doesn’t work either if the function is defined inside def __init__() and then set with self.func = func, and then later called in forward … the only case that works is when the scripted function is defined within forward.
One other detail I noticed is that the global case works if it only performs a single operation (e.g., x + x), rather than 2+ operations (e.g., x + x + x), which leads me to believe this might be a bug in the fuser.
Also, I’m not sure, but this topic seems possibly related: Second forward call of torchscripted module breaks on cuda
thanks again!