Oh, I see what you mean sorry. No, the idea was more that the calculations were resulting in a non-finite gradient for one (or more) of the variables, so by moving them to generated quantities you no longer need to worry about the gradients.
In Stan, any variables/computations in the transformed parameters block will require the gradients also be computed, whereas the generated quantities block will only compute the value.
I would still try running the model with the calculations in generated quantities first, just to check that the calculations are consistent with what you expect. It might be that there is a syntax/indexing error that’s tripping you up, and it won’t be apparent until you run the model.
If the syntax is correct, that gets a bit harder to debug. I’d start by iteratively commenting out or simplifying different calculations in the transformed parameters block, so you can narrow down which specific line is causing the issue.
Unfortunately, there’s no simple way to print the gradients at each iteration in a Stan model (print will print the value, but not the gradient). This forum post outlines how to print the gradients to a separate file, but I’m not sure how informative that output is (I’ve never used it).
If all else fails, feel free to PM me your model and I can take a closer look.
Good luck!