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