class_docstr: Base class for actor critic trainers. Suitable for multi-step and multi-agent training.
  
  :param algorithm_config: Algorithm parameters.
  :param rollout_generator: The rollout generator to use. This object encapsulates the env.
  :param evaluator: The evaluator to use.
  :param model: Structured torch actor critic model.
  :param model_selection: Optional model selection class, receives model evaluation results.
docstr: Perform gradient step based on given losses.
  
  :param policy_losses: List of policy losses.
  :param entropies: List of policy entropies.
  :param value_losses: The value loss.
docstr_tok: ["Perform","gradient","step","based","on","given","losses",".",":","param","policy_losses",":","List","of","policy","losses",".",":","param","entropies",":","List","of","policy","entropies",".",":","param","value_losses",":","The","value","loss","."]
code: def _gradient_step(
      self,
      policy_losses: List[torch.Tensor],
      entropies: List[torch.Tensor],
      value_losses: List[torch.Tensor],
  ) -> None:
      """Perform gradient step based on given losses.
  
      :param policy_losses: List of policy losses.
      :param entropies: List of policy entropies.
      :param value_losses: The value loss.
      """
  
      # accumulate step losses
      policy_loss = sum(policy_losses)
  
      # compute entropy loss
      entropy_loss = sum(entropies)
  
      # compute value loss
      value_loss = sum(value_losses)
  
      # perform update
      loss = (
          self.algorithm_config.value_loss_coef * value_loss
          + self.algorithm_config.policy_loss_coef * policy_loss
      )
      if self.algorithm_config.entropy_coef > 0.0:
          loss -= self.algorithm_config.entropy_coef * entropy_loss
  
      # compute backward pass
      self.optimizer.zero_grad()
      loss.backward(retain_graph=False)
  
      # limit to maximum allowed gradient norm
      if self.algorithm_config.max_grad_norm > 0.0:
          nn.utils.clip_grad_norm_(
              self.model.parameters(),
              self.algorithm_config.max_grad_norm,
          )
  
      # perform optimizer step
      self.optimizer.step()
  
imports: import sys
  import time
  from abc import ABC, abstractmethod
  from typing import List, Union, Dict, Optional
  import numpy
  import torch
  import torch.nn
  from maze.core.agent.torch_actor_critic import TorchActorCritic
  from maze.core.annotations import override
  from maze.core.env.base_env_events import BaseEnvEvents
  from maze.core.env.structured_env import ActorID
  from maze.core.log_stats.log_stats import increment_log_step, LogStatsLevel
  from maze.core.rollout.rollout_generator import RolloutGenerator
  from maze.core.trajectory_recording.records.structured_spaces_record import StructuredSpacesRecord
  from maze.train.parallelization.distributed_actors.distributed_actors import DistributedActors
  from maze.train.trainers.a2c.a2c_algorithm_config import A2CAlgorithmConfig
  from maze.train.trainers.common.actor_critic.actor_critic_events import ActorCriticEvents
  from maze.train.trainers.common.evaluators.rollout_evaluator import RolloutEvaluator
  from maze.train.trainers.common.model_selection.best_model_selection import BestModelSelection
  from maze.train.trainers.common.trainer import Trainer
  from maze.train.trainers.impala.impala_algorithm_config import ImpalaAlgorithmConfig
  from maze.train.trainers.ppo.ppo_algorithm_config import PPOAlgorithmConfig
  from maze.train.utils.train_utils import compute_gradient_norm
  from maze.utils.bcolors import BColors
  from tqdm import tqdm
  from typing.io import BinaryIO
label_desc: Use image node_id 8 for calling the ActorCritic obj's underlying member method code with example usage: obj._gradient_step(policy_losses, entropies, value_losses) without return types