About the Gradient Calculation of TraceELBO

I’m reading the source codes for TraceELBO class. However, I do not fully understand its calculation for gradients for non-reparametrical cases.

The codes inside the blue frame are to compute the surrogate loss particle for guide trace. And the codes inside the red frame are the modifications in each iteration. However, I notice that in the REINFORCE estimator, there is another term in the surrogate loss, shown in the red frame in the second figure. (I mean, is there a need to to add an extra term score_function_term in the red frame in first figure?)
image

How does TraceELBO take account to this term? Thanks!

well for example in the case of the elbo “f” contains terms like log q(z), which is taken care of in the entropy_term