Hi.
I try to convert valueDICE code(tf2) to pytorch.

  
      github.com
  
  
    google-research/google-research/blob/master/value_dice/value_dice.py 1
# coding=utf-8
# Copyright 2021 The Google Research Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Implementation of DualDICE https://openreview.net/pdf?id=SygrvzwniE ."""

import numpy as np
import tensorflow.compat.v2 as tf
from value_dice import keras_utils


  This file has been truncated. show original

  
  
    
    
  
  


but I got stuck in backward.
valueDICE uses the same loss function twice pi and nu.
So I tried similarly but I’m not sure how to do it properly in pytorch.
I tried like
# assume : a = pi, b = nu
self.a_optimizer(self.a.parameters())
self.b_optimizer(self.b.parameters())

# ~~~

loss = 1234 # maybe valueDICE loss
a_loss = -loss # + pi regularization
b_loss = loss # + nu penelty

tm.a_optimizer.zero_grad()  
a_loss.backward(retain_graph=True)
tm.b_optimizer.zero_grad()
b_loss.backward()
    
tm.a_optimizer.step()  
tm.b_optimizer.step()  
    

In this case, a does not change.
I’ve tried other methods as well, but I’m not sure how to suit it.
Could you give me a keyword on how pytorch handles these cases properly?