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 on the training set `(x, y)`.
  
  :param x: Training data.
  :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or index labels of
            shape (nb_samples,).
  :param batch_size: Size of batches.
  :param nb_epochs: Number of epochs to use for training.
  :param training_mode: `True` for model set to training mode and `'False` for model set to evaluation mode.
  :param drop_last: Set to ``True`` to drop the last incomplete batch, if the dataset size is not divisible by
                    the batch size. If ``False`` and the size of dataset is not divisible by the batch size, then
                    the last batch will be smaller. (default: ``False``)
  :param scheduler: Learning rate scheduler to run at the start of every epoch.
  :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","on","the","training","set","`","(","x",",","y",")","`",".",":","param","x",":","Training","data",".",":","param","y",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","(","nb_samples",",","nb_classes",")","or","index","labels","of","shape","(","nb_samples",",",")",".",":","param","batch_size",":","Size","of","batches",".",":","param","nb_epochs",":","Number","of","epochs","to","use","for","training",".",":","param","training_mode",":","`","True","`","for","model","set","to","training","mode","and","`","'False","`","for","model","set","to","evaluation","mode",".",":","param","drop_last",":","Set","to","``","True","``","to","drop","the","last","incomplete","batch",",","if","the","dataset","size","is","not","divisible","by","the","batch","size",".","If","``","False","``","and","the","size","of","dataset","is","not","divisible","by","the","batch","size",",","then","the","last","batch","will","be","smaller",".","(","default",":","``","False","``",")",":","param","scheduler",":","Learning","rate","scheduler","to","run","at","the","start","of","every","epoch",".",":","param","kwargs",":","Dictionary","of","framework-specific","arguments",".","This","parameter","is","not","currently","supported","for","PyTorch","and","providing","it","takes","no","effect","."]
code: def fit(  # pylint: disable=W0221
      self,
      x: np.ndarray,
      y: np.ndarray,
      batch_size: int = 128,
      nb_epochs: int = 10,
      training_mode: bool = True,
      drop_last: bool = False,
      scheduler: Optional[
          "torch.optim.lr_scheduler._LRScheduler"
      ] = None,
      **kwargs,
  ) -> None:
      """
      Fit the regressor on the training set `(x, y)`.
  
      :param x: Training data.
      :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or index labels of
                shape (nb_samples,).
      :param batch_size: Size of batches.
      :param nb_epochs: Number of epochs to use for training.
      :param training_mode: `True` for model set to training mode and `'False` for model set to evaluation mode.
      :param drop_last: Set to ``True`` to drop the last incomplete batch, if the dataset size is not divisible by
                        the batch size. If ``False`` and the size of dataset is not divisible by the batch size, then
                        the last batch will be smaller. (default: ``False``)
      :param scheduler: Learning rate scheduler to run at the start of every epoch.
      :param kwargs: Dictionary of framework-specific arguments. This parameter is not currently supported for PyTorch
             and providing it takes no effect.
      """
      import torch
      from torch.utils.data import TensorDataset, DataLoader
  
      # Set model mode
      self._model.train(mode=training_mode)
  
      if self._optimizer is None:  # pragma: no cover
          raise ValueError(
              "An optimizer is needed to train the model, but none for provided."
          )
  
      # Apply preprocessing
      x_preprocessed, y_preprocessed = self._apply_preprocessing(
          x, y, fit=True
      )
  
      # Create dataloader
      x_tensor = torch.from_numpy(x_preprocessed)
      y_tensor = torch.from_numpy(y_preprocessed)
      dataset = TensorDataset(x_tensor, y_tensor)
      dataloader = DataLoader(
          dataset=dataset,
          batch_size=batch_size,
          shuffle=True,
          drop_last=drop_last,
      )
  
      # Start training
      for _ in range(nb_epochs):
          # Train for one epoch
          for x_batch, y_batch in dataloader:
              # Move inputs to device
              x_batch = x_batch.to(self._device)
              y_batch = y_batch.to(self._device)
  
              # Zero the parameter gradients
              self._optimizer.zero_grad()
  
              # Perform prediction
              model_outputs = self._model(x_batch)
  
              # Form the loss function
              loss = self._loss(model_outputs[-1].reshape(-1), y_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()
  
          if scheduler is not None:
              scheduler.step()
  
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 12 for calling the PyTorchRegressor obj's underlying member method code with example usage: obj.fit(x, y, batch_size, nb_epochs, training_mode, drop_last, scheduler) without return types