I guess there shouldn’t be a difference, but since your codes are incomplete I would recommend to run a quick test using a constant input and check the output as well as the gradients for an iteration.
I’m not familiar with your use case, but would it be possible to pass the complete input directly to the model instead of using a loop?