class_docstr: This class tests the crypten.nn package.
class_docstr_tok: ["This","class","tests","the","crypten.nn","package","."]
docstr: Tests the crypten.nn.Parameter module.
code: def test_parameter_module(self):
      """
      Tests the crypten.nn.Parameter module.
      """
      for trainable in [False, True]:
          for ttype in [
              torch.tensor,
              torch.nn.parameter.Parameter,
              crypten.cryptensor,
          ]:
              # check creation of Parameter:
              num_rows, num_cols = 5, 4
              size = (num_rows, num_cols)
              reference = get_random_test_tensor(
                  size=size, is_float=True
              )
              param = crypten.nn.Parameter(
                  ttype(reference), trainable=trainable
              )
              self.assertTrue(hasattr(param, "data"))
              self.assertTrue(hasattr(param, "requires_grad"))
              self.assertTrue(hasattr(param, "encrypted"))
              self.assertEqual(
                  param.requires_grad,
                  trainable,
                  msg=f"requires_grad incorrect for type {ttype}",
              )
  
              # check that parameter is registered:
              self.assertEqual(
                  len(list(param.parameters())), 1 if trainable else 0
              )
              self.assertEqual(
                  len(list(param.buffers())), 0 if trainable else 1
              )
  
              # check value of parameter:
              for value in [param.data, param(None)]:
                  if ttype == crypten.cryptensor:
                      self.assertEqual(value.size(), reference.size())
                      equal_elem = (
                          (value == reference).sum().get_plain_text()
                      )
                      self.assertEqual(
                          equal_elem.item(), num_rows * num_cols
                      )
                      self.assertTrue(param.encrypted)
                  else:
                      self.assertEqual(value.size(), reference.size())
                      self.assertTrue((value == reference).all().item())
                      self.assertFalse(param.encrypted)
  
              # check that we can encrypt parameter:
              if ttype != crypten.cryptensor:
                  param = param.encrypt()
                  self.assertTrue(param.encrypted)
                  self._check(
                      param.data,
                      reference,
                      f"encryption of parameter failed for {ttype} with trainable = {trainable}",
                  )
                  for value in [param.data, param(None)]:
                      self.assertTrue(
                          crypten.is_encrypted_tensor(value)
                      )
  
              # check that we can decrypt parameter:
              param = param.decrypt()
              self.assertFalse(param.encrypted)
              for value in [param.data, param(None)]:
                  self.assertTrue(torch.is_tensor(value))
  
      # check that we cannot initialize with other types:
      with self.assertRaises(AssertionError):
          param = crypten.nn.Parameter(list(range(5)))
  
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 12 for calling the TestNN obj's underlying member method code with example usage: obj.test_parameter_module() without return types