Solved by ptrblck in post #2 
              
              
                I think the error is raised, because scripting assumes tensors as the input, if no annotations are used as described here. 
I don’t know, if it’s possible to script the complete optimization, but you should be able to script the model at least.