Optimal Stochastic Trace Estimation in Generative Modeling