code: def _add_log_prob_and_value_to_episodes(
      episodes,
      model,
      phi,
      batch_states,
      obs_normalizer,
      device,
  ):
      dataset = list(itertools.chain.from_iterable(episodes))
  
      # Compute v_pred and next_v_pred
      states = batch_states([b["state"] for b in dataset], device, phi)
      next_states = batch_states(
          [b["next_state"] for b in dataset], device, phi
      )
  
      if obs_normalizer:
          states = obs_normalizer(states, update=False)
          next_states = obs_normalizer(next_states, update=False)
  
      with torch.no_grad(), pfrl.utils.evaluating(model):
          distribs, vs_pred = model(states)
          _, next_vs_pred = model(next_states)
  
          actions = torch.tensor(
              [b["action"] for b in dataset], device=device
          )
          log_probs = distribs.log_prob(actions).cpu().numpy()
          vs_pred = vs_pred.cpu().numpy().ravel()
          next_vs_pred = next_vs_pred.cpu().numpy().ravel()
  
      for transition, log_prob, v_pred, next_v_pred in zip(
          dataset, log_probs, vs_pred, next_vs_pred
      ):
          transition["log_prob"] = log_prob
          transition["v_pred"] = v_pred
          transition["next_v_pred"] = next_v_pred
  
imports: import collections
  import itertools
  import random
  import numpy
  import torch
  import torch.nn.functional
  import pfrl
  from pfrl import agent
  from pfrl.utils.batch_states import batch_states
  from pfrl.utils.mode_of_distribution import mode_of_distribution
  from pfrl.utils.recurrent import concatenate_recurrent_states, flatten_sequences_time_first, get_recurrent_state_at, mask_recurrent_state_at, one_step_forward, pack_and_forward
label_desc: Use image node_id 6 for calling a global function with example usage: _add_log_prob_and_value_to_episodes(episodes, model, phi, batch_states, obs_normalizer, device) without return types