Thanks for the code sample. This is indeed a very small model !
Can you try replacing torch::NoGradGuard guard; by at::AutoNonVariableTypeMode non_var_type_mode(true);? This is not supposed to be public api but might help for now.