class_docstr: ## Trainer
class_docstr_tok: ["#","#","Trainer"]
code: def __init__(
      self,
      *,
      updates: int,
      epochs: int,
      n_workers: int,
      worker_steps: int,
      mini_batch_size: int,
      update_target_model: int,
      learning_rate: FloatDynamicHyperParam,
  ):
      # number of workers
      self.n_workers = n_workers
      # steps sampled on each update
      self.worker_steps = worker_steps
      # number of training iterations
      self.train_epochs = epochs
  
      # number of updates
      self.updates = updates
      # size of mini batch for training
      self.mini_batch_size = mini_batch_size
  
      # update target network every 250 update
      self.update_target_model = update_target_model
  
      # learning rate
      self.learning_rate = learning_rate
  
      # exploration as a function of updates
      self.exploration_coefficient = Piecewise(
          [(0, 1.0), (25_000, 0.1), (self.updates / 2, 0.01)],
          outside_value=0.01,
      )
  
      # $\beta$ for replay buffer as a function of updates
      self.prioritized_replay_beta = Piecewise(
          [(0, 0.4), (self.updates, 1)], outside_value=1
      )
  
      # Replay buffer with $\alpha = 0.6$. Capacity of the replay buffer must be a power of 2.
      self.replay_buffer = ReplayBuffer(2**14, 0.6)
  
      # Model for sampling and training
      self.model = Model().to(device)
      # target model to get $\textcolor{orange}Q(s';\textcolor{orange}{\theta_i^{-}})$
      self.target_model = Model().to(device)
  
      # create workers
      self.workers = [Worker(47 + i) for i in range(self.n_workers)]
  
      # initialize tensors for observations
      self.obs = np.zeros((self.n_workers, 4, 84, 84), dtype=np.uint8)
  
      # reset the workers
      for worker in self.workers:
          worker.child.send(("reset", None))
  
      # get the initial observations
      for i, worker in enumerate(self.workers):
          self.obs[i] = worker.child.recv()
  
      # loss function
      self.loss_func = QFuncLoss(0.99)
      # optimizer
      self.optimizer = torch.optim.Adam(
          self.model.parameters(), lr=2.5e-4
      )
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/rl/dqn/experiment.py
imports: import numpy
  import torch
  from labml import tracker, experiment, logger, monit
  from labml.internal.configs.dynamic_hyperparam import FloatDynamicHyperParam
  from labml_helpers.schedule import Piecewise
  from labml_nn.rl.dqn import QFuncLoss
  from labml_nn.rl.dqn.model import Model
  from labml_nn.rl.dqn.replay_buffer import ReplayBuffer
  from labml_nn.rl.game import Worker
label_desc: Use image node_id 1 to create a new Trainer object  with example: obj = Trainer()