docstr: Test that impala_policy_rlm loss matches the impala learner loss.
  
  Correctness of V-Trance is tested in test_vtrace_v2.py.
docstr_tok: ["Test","that","impala_policy_rlm","loss","matches","the","impala","learner","loss",".","Correctness","of","V-Trance","is","tested","in","test_vtrace_v2.py","."]
code: def test_impala_loss(self):
      """Test that impala_policy_rlm loss matches the impala learner loss.
  
      Correctness of V-Trance is tested in test_vtrace_v2.py.
      """
      config = (
          ImpalaConfig()
          .experimental(_enable_new_api_stack=True)
          .environment("CartPole-v1")
          .rollouts(
              num_rollout_workers=0,
              rollout_fragment_length=frag_length,
          )
          .resources(num_gpus=0)
          .training(
              gamma=0.99,
              model=dict(
                  fcnet_hiddens=[10, 10],
                  fcnet_activation="linear",
                  vf_share_layers=False,
              ),
          )
      )
      # TODO (Artur): See if setting Impala's default to {} pose any issues.
      #  Deprecate the current default and set it to {}.
      config.exploration_config = {}
  
      for fw in framework_iterator(config, frameworks=["torch", "tf2"]):
          algo = config.build()
  
          if fw == "torch":
              train_batch = convert_to_torch_tensor(
                  SampleBatch(FAKE_BATCH)
              )
          else:
              train_batch = SampleBatch(
                  tree.map_structure(
                      lambda x: tf.convert_to_tensor(x), FAKE_BATCH
                  )
              )
  
          algo_config = config.copy(copy_frozen=False)
          algo_config.num_learner_workers = 0
          learner_group = algo_config.build_learner_group(
              env=algo.workers.local_worker().env
          )
          learner_group.set_weights(algo.get_weights())
          learner_group.update_from_batch(
              batch=train_batch.as_multi_agent()
          )
  
          algo.stop()
  
file_path: ray/python/ray/rllib/algorithms/impala/tests/test_impala_learner.py
imports: import unittest
  import numpy
  import tree
  import ray
  from ray.rllib.algorithms.impala import ImpalaConfig
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.framework import try_import_torch, try_import_tf
  from ray.rllib.utils.test_utils import framework_iterator
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor
label_desc: Use image node_id 3 for calling the TestImpalaLearner obj's underlying member method code with example usage: obj.test_impala_loss() without return types