class_docstr: Model-Agnostic Meta-Learning (MAML).
  
  Args:
      inner_algo (garage.torch.algos.VPG): The inner algorithm used for
          computing loss.
      env (Environment): An environment.
      policy (garage.torch.policies.Policy): Policy.
      sampler (garage.sampler.Sampler): Sampler.
      task_sampler (garage.experiment.TaskSampler): Task sampler.
      meta_optimizer (Union[torch.optim.Optimizer, tuple]):
          Type of optimizer.
          This can be an optimizer type such as `torch.optim.Adam` or a tuple
          of type and dictionary, where dictionary contains arguments to
          initialize the optimizer e.g. `(torch.optim.Adam, {'lr' : 1e-3})`.
      meta_batch_size (int): Number of tasks sampled per batch.
      inner_lr (float): Adaptation learning rate.
      outer_lr (float): Meta policy learning rate.
      num_grad_updates (int): Number of adaptation gradient steps.
      meta_evaluator (MetaEvaluator): A meta evaluator for meta-testing. If
          None, don't do meta-testing.
      evaluate_every_n_epochs (int): Do meta-testing every this epochs.
class_docstr_tok: ["Model-Agnostic","Meta-Learning","(","MAML",")",".","Args",":","inner_algo","(","garage.torch.algos.VPG",")",":","The","inner","algorithm","used","for","computing","loss",".","env","(","Environment",")",":","An","environment",".","policy","(","garage.torch.policies.Policy",")",":","Policy",".","sampler","(","garage.sampler.Sampler",")",":","Sampler",".","task_sampler","(","garage.experiment.TaskSampler",")",":","Task","sampler",".","meta_optimizer","(","Union","[","torch.optim.Optimizer",",","tuple","]",")",":","Type","of","optimizer",".","This","can","be","an","optimizer","type","such","as","`","torch.optim.Adam","`","or","a","tuple","of","type","and","dictionary",",","where","dictionary","contains","arguments","to","initialize","the","optimizer","e.g",".","`","(","torch.optim.Adam",",","{","'lr","'",":","1e-3","}",")","`",".","meta_batch_size","(","int",")",":","Number","of","tasks","sampled","per","batch",".","inner_lr","(","float",")",":","Adaptation","learning","rate",".","outer_lr","(","float",")",":","Meta","policy","learning","rate",".","num_grad_updates","(","int",")",":","Number","of","adaptation","gradient","steps",".","meta_evaluator","(","MetaEvaluator",")",":","A","meta","evaluator","for","meta-testing",".","If","None",",","do","n't","do","meta-testing",".","evaluate_every_n_epochs","(","int",")",":","Do","meta-testing","every","this","epochs","."]
docstr: Train the algorithm once.
  
  Args:
      trainer (Trainer): The experiment runner.
      all_samples (list[list[_MAMLEpisodeBatch]]): A two
          dimensional list of _MAMLEpisodeBatch of size
          [meta_batch_size * (num_grad_updates + 1)]
      all_params (list[dict]): A list of named parameter dictionaries.
          Each dictionary contains key value pair of names (str) and
          parameters (torch.Tensor).
  
  Returns:
      float: Average return.
docstr_tok: ["Train","the","algorithm","once",".","Args",":","trainer","(","Trainer",")",":","The","experiment","runner",".","all_samples","(","list","[","list","[","_MAMLEpisodeBatch","]","]",")",":","A","two","dimensional","list","of","_MAMLEpisodeBatch","of","size","[","meta_batch_size","*","(","num_grad_updates","+","1",")","]","all_params","(","list","[","dict","]",")",":","A","list","of","named","parameter","dictionaries",".","Each","dictionary","contains","key","value","pair","of","names","(","str",")","and","parameters","(","torch.Tensor",")",".","Returns",":","float",":","Average","return","."]
code: def _train_once(self, trainer, all_samples, all_params):
      """Train the algorithm once.
  
      Args:
          trainer (Trainer): The experiment runner.
          all_samples (list[list[_MAMLEpisodeBatch]]): A two
              dimensional list of _MAMLEpisodeBatch of size
              [meta_batch_size * (num_grad_updates + 1)]
          all_params (list[dict]): A list of named parameter dictionaries.
              Each dictionary contains key value pair of names (str) and
              parameters (torch.Tensor).
  
      Returns:
          float: Average return.
  
      """
      itr = trainer.step_itr
      old_theta = dict(self._policy.named_parameters())
  
      kl_before = self._compute_kl_constraint(
          all_samples, all_params, set_grad=False
      )
  
      meta_objective = self._compute_meta_loss(all_samples, all_params)
  
      zero_optim_grads(self._meta_optimizer)
      meta_objective.backward()
  
      self._meta_optimize(all_samples, all_params)
  
      # Log
      loss_after = self._compute_meta_loss(
          all_samples, all_params, set_grad=False
      )
      kl_after = self._compute_kl_constraint(
          all_samples, all_params, set_grad=False
      )
  
      with torch.no_grad():
          policy_entropy = self._compute_policy_entropy(
              [task_samples[0] for task_samples in all_samples]
          )
          average_return = self._log_performance(
              itr,
              all_samples,
              meta_objective.item(),
              loss_after.item(),
              kl_before.item(),
              kl_after.item(),
              policy_entropy.mean().item(),
          )
  
      if (
          self._meta_evaluator
          and itr % self._evaluate_every_n_epochs == 0
      ):
          self._meta_evaluator.evaluate(self)
  
      update_module_params(self._old_policy, old_theta)
  
      return average_return
  
imports: import collections
  import copy
  from dowel import tabular
  import numpy
  import torch
  from garage import _Default, EpisodeBatch, log_multitask_performance, make_optimizer
  from garage.np import discount_cumsum
  from garage.torch import update_module_params
  from garage.torch._functions import np_to_torch, zero_optim_grads
  from garage.torch.optimizers import ConjugateGradientOptimizer, DifferentiableSGD
label_desc: Use image node_id 3 for calling the MAML obj's underlying member method code with example usage: obj._train_once(trainer, all_samples, all_params) and returns: average_return