class_docstr: This class tests all autograd-related functionality.
docstr: Tests autograd graph construction and backprop.
docstr_tok: ["Tests","autograd","graph","construction","and","backprop","."]
code: def test_autograd(self) -> None:
      """Tests autograd graph construction and backprop."""
  
      # define test cases:
      tests = [
          (1, ["relu", "neg", "relu", "sum"]),
          (2, ["t", "neg", "add", "sum"]),
          (2, ["relu", "mul", "t", "sum"]),
      ]
      binary_functions = ["add", "sub", "mul", "dot", "matmul"]
  
      # PyTorch test case:
      for test in tests:
          # get test case:
          number_of_inputs, ops = test
          inputs = [
              get_random_test_tensor(size=(12, 5), is_float=True)
              for _ in range(number_of_inputs)
          ]
          encr_inputs = [crypten.cryptensor(input) for input in inputs]
  
          # get autograd variables:
          for input in inputs:
              input.requires_grad = True
          for encr_input in encr_inputs:
              encr_input.requires_grad = True
  
          # perform forward pass, logging all intermediate outputs:
          outputs, encr_outputs = [inputs], [encr_inputs]
          for op in ops:
              # get inputs for current operation:
              input, output = outputs[-1], []
              encr_input, encr_output = encr_outputs[-1], []
  
              # apply current operation:
              if (
                  op in binary_functions
              ):  # combine outputs via operation
                  output.append(getattr(input[0], op)(input[1]))
                  encr_output.append(
                      getattr(encr_input[0], op)(encr_input[1])
                  )
              else:
                  for idx in range(len(input)):
                      output.append(getattr(input[idx], op)())
                      encr_output.append(getattr(encr_input[idx], op)())
  
              # keep references to outputs of operation:
              outputs.append(output)
              encr_outputs.append(encr_output)
  
          # check output of forward pass:
          output, encr_output = outputs[-1][0], encr_outputs[-1][0]
          self._check(encr_output._tensor, output, "forward failed")
          self.assertTrue(
              encr_output.requires_grad, "requires_grad incorrect"
          )
  
          # perform backward pass:
          output.backward()
          encr_output.backward()
  
          # test result of running backward function:
          for idx in range(number_of_inputs):
              self._check(
                  encr_inputs[idx].grad,
                  inputs[idx].grad,
                  "backward failed",
              )
  
imports: import logging
  import random
  import unittest
  import crypten
  import crypten.gradients
  import torch
  from crypten.common.tensor_types import is_float_tensor
  from crypten.config import cfg
  from crypten.gradients import AutogradContext, AutogradFunction
  from test.multiprocess_test_case import get_random_test_tensor, MultiProcessTestCase
label_desc: Use image node_id 10 for calling the TestAutograd obj's underlying member method code with example usage: obj.test_autograd() without return types