I do this as follow
   optimizer.zero_grad() 
    model_w.eval()
    feat2 = model_w(G_result.detach())  
    model_w.train()
    feat = model_w(x2_w)
    loss, p_inds, n_inds, dist_ap, dist_an, dist_mat = global_loss(tri_loss, feat, y_w, normalize_feature= False) 
    loss.backward()
    optimizer.step()

the result is still wrong.Is there any other problem?