You’re right, I did debugging step by step and the following line is the culprit, I am directly treating loss term as scalar while calculating average loss over the epoch.
avg_loss_g = (avg_loss_g+loss_G)/(i+1)