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: Obtain samples for each task before and after the fast-adaptation.
  
  Args:
      trainer (Trainer): A trainer instance to obtain samples.
  
  Returns:
      tuple: Tuple of (all_samples, all_params).
          all_samples (list[_MAMLEpisodeBatch]): A list of size
              [meta_batch_size * (num_grad_updates + 1)]
          all_params (list[dict]): A list of named parameter
              dictionaries.
docstr_tok: ["Obtain","samples","for","each","task","before","and","after","the","fast-adaptation",".","Args",":","trainer","(","Trainer",")",":","A","trainer","instance","to","obtain","samples",".","Returns",":","tuple",":","Tuple","of","(","all_samples",",","all_params",")",".","all_samples","(","list","[","_MAMLEpisodeBatch","]",")",":","A","list","of","size","[","meta_batch_size","*","(","num_grad_updates","+","1",")","]","all_params","(","list","[","dict","]",")",":","A","list","of","named","parameter","dictionaries","."]
code: def _obtain_samples(self, trainer):
      """Obtain samples for each task before and after the fast-adaptation.
  
      Args:
          trainer (Trainer): A trainer instance to obtain samples.
  
      Returns:
          tuple: Tuple of (all_samples, all_params).
              all_samples (list[_MAMLEpisodeBatch]): A list of size
                  [meta_batch_size * (num_grad_updates + 1)]
              all_params (list[dict]): A list of named parameter
                  dictionaries.
  
      """
      tasks = self._task_sampler.sample(self._meta_batch_size)
      all_samples = [[] for _ in range(len(tasks))]
      all_params = []
      theta = dict(self._policy.named_parameters())
  
      for i, env_up in enumerate(tasks):
          for j in range(self._num_grad_updates + 1):
              episodes = trainer.obtain_episodes(
                  trainer.step_itr, env_update=env_up
              )
              batch_samples = self._process_samples(episodes)
              all_samples[i].append(batch_samples)
  
              # The last iteration does only sampling but no adapting
              if j < self._num_grad_updates:
                  # A grad need to be kept for the next grad update
                  # Except for the last grad update
                  require_grad = j < self._num_grad_updates - 1
                  self._adapt(batch_samples, set_grad=require_grad)
  
          all_params.append(dict(self._policy.named_parameters()))
          # Restore to pre-updated policy
          update_module_params(self._policy, theta)
  
      return all_samples, all_params
  
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 5 for calling the MAML obj's underlying member method code with example usage: obj._obtain_samples(trainer) and returns: all_samples,  all_params