code: def finish_episode(policy, optimizer, gamma):
      R = 0
      policy_loss = []
      returns = deque()
      for r in policy.rewards[::-1]:
          R = r + gamma * R
          returns.appendleft(R)
      returns = torch.tensor(returns)
      returns = (returns - returns.mean()) / (returns.std() + eps)
      for log_prob, R in zip(policy.saved_log_probs, returns):
          policy_loss.append(-log_prob * R)
      optimizer.zero_grad()
      policy_loss = torch.cat(policy_loss).sum()
      policy_loss.backward()
      optimizer.step()
      del policy.rewards[:]
      del policy.saved_log_probs[:]
  
file_path: ignite/examples/reinforcement_learning/reinforce.py
imports: import argparse
  from collections import deque
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torch.distributions import Categorical
  from ignite.engine import Engine, Events
label_desc: Use image node_id 2 for calling a global function with example usage: finish_episode(policy, optimizer, gamma) without return types