text: import numpy as np
  import torch
  
  #import ptan
  import utils
  
  
  def unpack_batch_a2c(batch, net, last_val_gamma, device="cpu"):
      """
      Convert batch into training tensors
      :param batch:
      :param net:
      :return: states variable, actions tensor, reference values variable
      """
      states = []
      actions = []
      rewards = []
      not_done_idx = []
      last_states = []
      for idx, exp in enumerate(batch):
          states.append(exp.state)
          actions.append(exp.action)
          rewards.append(exp.reward)
          if exp.last_state is not None:
              not_done_idx.append(idx)
              last_states.append(exp.last_state)
      states_v = utils.float32_preprocessor(states).to(device)
      actions_v = torch.FloatTensor(actions).to(device)
  
      # handle rewards
      rewards_np = np.array(rewards, dtype=np.float32)
      if not_done_idx:
          last_states_v = utils.float32_preprocessor(last_states).to(device)
          last_vals_v = net(last_states_v)
          last_vals_np = last_vals_v.data.cpu().numpy()[:, 0]
          rewards_np[not_done_idx] += last_val_gamma * last_vals_np
  
      ref_vals_v = torch.FloatTensor(rewards_np).to(device)
      return states_v, actions_v, ref_vals_v
  