class_docstr: Tests PyTorch and Tensorflow model imports
docstr: Verifies gradient updates and loss decreases during training
docstr_tok: ["Verifies","gradient","updates","and","loss","decreases","during","training"]
code: def _check_training(
      self,
      model,
      x_train,
      y_train,
      loss_name,
      num_epochs=2,
      learning_rate=0.001,
  ):
      """Verifies gradient updates and loss decreases during training"""
      # create loss function
      loss = getattr(crypten.nn, loss_name)()
  
      for i in range(num_epochs):
          output = model(x_train)
          loss_value = loss(output, y_train)
  
          # set gradients to "zero"
          model.zero_grad()
          for param in model.parameters():
              self.assertIsNone(
                  param.grad, "zero_grad did not reset gradients"
              )
  
          # perform backward pass
          loss_value.backward()
          for param in model.parameters():
              if param.requires_grad:
                  self.assertIsNotNone(
                      param.grad,
                      "required parameter gradient not created",
                  )
  
          # update parameters
          orig_parameters, upd_parameters = {}, {}
          orig_parameters = self._compute_reference_parameters(
              "", orig_parameters, model, 0
          )
          model.update_parameters(learning_rate)
          upd_parameters = self._compute_reference_parameters(
              "", upd_parameters, model, learning_rate
          )
  
          # check parameter update
          parameter_changed = False
          for name, value in orig_parameters.items():
              if param.requires_grad and param.grad is not None:
                  unchanged = torch.allclose(
                      upd_parameters[name], value
                  )
                  if unchanged is False:
                      parameter_changed = True
                  self.assertTrue(
                      parameter_changed,
                      "no parameter changed in training step",
                  )
  
          # record initial and current loss
          if i == 0:
              orig_loss = loss_value.get_plain_text()
          curr_loss = loss_value.get_plain_text()
  
      # check that the loss has decreased after training
      self.assertTrue(
          curr_loss.item() < orig_loss.item(),
          f"{loss_name} has not decreased after training",
      )
  
imports: import collections
  import io
  import logging
  import os
  import unittest
  import crypten
  import torch
  from crypten.common.tensor_types import is_float_tensor
  from crypten.config import cfg
  from crypten.nn import onnx_converter
  from test.multiprocess_test_case import get_random_test_tensor, MultiProcessTestCase, onehot
label_desc: Use image node_id 7 for calling the TestOnnxConverter obj's underlying member method code with example usage: obj._check_training(model, x_train, y_train, loss_name, num_epochs, learning_rate) without return types