class_docstr: This class tests the crypten.nn package.
class_docstr_tok: ["This","class","tests","the","crypten.nn","package","."]
docstr: Tests crypten.nn.Sequential module.
code: def test_sequential(self):
      """
      Tests crypten.nn.Sequential module.
      """
  
      # try networks of different depth:
      for num_layers in range(1, 6):
          for compute_gradients in [True, False]:
              # construct sequential container:
              input_size = (3, 10)
              output_size = (input_size[0], input_size[1] - num_layers)
              layer_idx = range(input_size[1], output_size[1], -1)
  
              # Construct module list
              torch_module_list = [
                  torch.nn.Linear(num_feat, num_feat - 1)
                  for num_feat in layer_idx
              ]
              crypten_module_list = [
                  crypten.nn.Linear(num_feat, num_feat - 1)
                  for num_feat in layer_idx
              ]
  
              # Coordinate parameter values:
              for i in range(len(torch_module_list)):
                  torch_module_list[i].weight = torch.nn.Parameter(
                      get_random_test_tensor(
                          size=torch_module_list[i].weight.size(),
                          is_float=True,
                      )
                  )
                  torch_module_list[i].bias = torch.nn.Parameter(
                      get_random_test_tensor(
                          size=torch_module_list[i].bias.size(),
                          is_float=True,
                      )
                  )
                  crypten_module_list[i].weight = torch_module_list[
                      i
                  ].weight
                  crypten_module_list[i].bias = torch_module_list[
                      i
                  ].bias
  
              # Construct sequential modules
              torch_sequential = torch.nn.Sequential(*torch_module_list)
              crypten_sequential = crypten.nn.Sequential(
                  *crypten_module_list
              )
              crypten_sequential.encrypt()
  
              # check container:
              self.assertTrue(
                  crypten_sequential.encrypted,
                  "nn.Sequential not encrypted",
              )
              for module in crypten_sequential.modules():
                  self.assertTrue(
                      module.encrypted, "module not encrypted"
                  )
              assert len(list(crypten_sequential.modules())) == len(
                  list(torch_sequential.modules())
              ), "nn.Sequential contains incorrect number of modules"
  
              # construct test input and run through sequential container:
              input = get_random_test_tensor(
                  size=input_size, is_float=True
              )
              encr_input = crypten.cryptensor(input)
              encr_input.requires_grad = compute_gradients
              encr_output = crypten_sequential(encr_input)
  
              # compute reference output:
              reference = torch_sequential(input)
  
              # compare output to reference:
              self._check(
                  encr_output, reference, "nn.Sequential forward failed"
              )
  
imports: import copy
  import itertools
  import logging
  import unittest
  import crypten
  import crypten.communicator
  import torch
  import torch.nn.functional
  from crypten.common.rng import generate_random_ring_element
  from crypten.common.tensor_types import is_float_tensor
  from crypten.config import cfg
  from crypten.encoder import FixedPointEncoder
  from test.multiprocess_test_case import get_random_linear, get_random_test_tensor, MultiProcessTestCase, onehot
label_desc: Use image node_id 14 for calling the TestNN obj's underlying member method code with example usage: obj.test_sequential() without return types