class_docstr: This class implements a regressor with the PyTorch framework.
class_docstr_tok: ["This","class","implements","a","regressor","with","the","PyTorch","framework","."]
docstr: Fit the regressor using the generator that yields batches as specified.
  
  :param generator: Batch generator providing `(x, y)` for each epoch.
  :param nb_epochs: Number of epochs to use for training.
  :param kwargs: Dictionary of framework-specific arguments. This parameter is not currently supported for PyTorch
         and providing it takes no effect.
docstr_tok: ["Fit","the","regressor","using","the","generator","that","yields","batches","as","specified",".",":","param","generator",":","Batch","generator","providing","`","(","x",",","y",")","`","for","each","epoch",".",":","param","nb_epochs",":","Number","of","epochs","to","use","for","training",".",":","param","kwargs",":","Dictionary","of","framework-specific","arguments",".","This","parameter","is","not","currently","supported","for","PyTorch","and","providing","it","takes","no","effect","."]
code: def fit_generator(
      self, generator: "DataGenerator", nb_epochs: int = 20, **kwargs
  ) -> None:
      """
      Fit the regressor using the generator that yields batches as specified.
  
      :param generator: Batch generator providing `(x, y)` for each epoch.
      :param nb_epochs: Number of epochs to use for training.
      :param kwargs: Dictionary of framework-specific arguments. This parameter is not currently supported for PyTorch
             and providing it takes no effect.
      """
      import torch
      from art.data_generators import PyTorchDataGenerator
  
      # Put the model in the training mode
      self._model.train()
  
      if self._optimizer is None:  # pragma: no cover
          raise ValueError(
              "An optimizer is needed to train the model, but none for provided."
          )
  
      # Train directly in PyTorch
      from art.preprocessing.standardisation_mean_std.pytorch import (
          StandardisationMeanStdPyTorch,
      )
  
      if isinstance(generator, PyTorchDataGenerator) and (
          self.preprocessing is None
          or (
              isinstance(
                  self.preprocessing, StandardisationMeanStdPyTorch
              )
              and (
                  self.preprocessing.mean,
                  self.preprocessing.std,
              )
              == (0, 1)
          )
      ):
          for _ in range(nb_epochs):
              for i_batch, o_batch in generator.iterator:
                  if isinstance(i_batch, np.ndarray):
                      i_batch = torch.from_numpy(i_batch).to(
                          self._device
                      )
                  else:
                      i_batch = i_batch.to(self._device)
  
                  if isinstance(o_batch, np.ndarray):
                      o_batch = torch.argmax(
                          torch.from_numpy(o_batch).to(self._device),
                          dim=1,
                      )
                  else:
                      o_batch = torch.argmax(
                          o_batch.to(self._device), dim=1
                      )
  
                  # Zero the parameter gradients
                  self._optimizer.zero_grad()
  
                  # Perform prediction
                  model_outputs = self._model(i_batch)
  
                  # Form the loss function
                  loss = self._loss(
                      model_outputs[-1].reshape(
                          -1,
                      ),
                      o_batch,
                  )
  
                  # Do training
                  if self._use_amp:  # pragma: no cover
                      from apex import amp  # pylint: disable=E0611
  
                      with amp.scale_loss(
                          loss, self._optimizer
                      ) as scaled_loss:
                          scaled_loss.backward()
  
                  else:
                      loss.backward()
  
                  self._optimizer.step()
  
      else:
          # Fit a generic data generator through the API
          super().fit_generator(generator, nb_epochs=nb_epochs)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import copy
  import logging
  import os
  import time
  from typing import Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  import six
  from art import config
  from art.estimators.regression.regressor import RegressorMixin
  from art.estimators.pytorch import PyTorchEstimator
label_desc: Use image node_id 13 for calling the PyTorchRegressor obj's underlying member method code with example usage: obj.fit_generator(generator, nb_epochs) without return types