class_docstr: This class tests all member functions of crypten package
class_docstr_tok: ["This","class","tests","all","member","functions","of","crypten","package"]
docstr: Test that crypten.save and crypten.load properly save and load
  shares of cryptensors
code: def test_save_load(self):
      """Test that crypten.save and crypten.load properly save and load
      shares of cryptensors"""
      import io
      import pickle
  
      def custom_load_function(f):
          obj = pickle.load(f)
          return obj
  
      def custom_save_function(obj, f):
          pickle.dump(obj, f)
  
      all_save_fns = [torch.save, custom_save_function]
      all_load_fns = [torch.load, custom_load_function]
  
      tensor = get_random_test_tensor()
      cryptensor1 = crypten.cryptensor(tensor)
  
      for i, save_closure in enumerate(all_save_fns):
          load_closure = all_load_fns[i]
          f = [
              io.BytesIO()
              for i in range(
                  crypten.communicator.get().get_world_size()
              )
          ]
          crypten.save(
              cryptensor1, f[self.rank], save_closure=save_closure
          )
          f[self.rank].seek(0)
          cryptensor2 = crypten.load(
              f[self.rank], load_closure=load_closure
          )
          # test whether share matches
          self.assertTrue(cryptensor1.share.allclose(cryptensor2.share))
          # test whether tensor matches
          self.assertTrue(
              cryptensor1.get_plain_text().allclose(
                  cryptensor2.get_plain_text()
              )
          )
          attributes = [
              a
              for a in dir(cryptensor1)
              if not a.startswith("__")
              and not callable(getattr(cryptensor1, a))
              and a not in ["share", "_tensor", "ctx"]
          ]
          for a in attributes:
              attr1, attr2 = getattr(cryptensor1, a), getattr(
                  cryptensor2, a
              )
              if a == "encoder":
                  self.assertTrue(attr1._scale == attr2._scale)
                  self.assertTrue(
                      attr1._precision_bits == attr2._precision_bits
                  )
              elif torch.is_tensor(attr1):
                  self.assertTrue(attr1.eq(attr2).all())
              else:
                  self.assertTrue(attr1 == attr2)
  
imports: import itertools
  import logging
  import math
  import random
  import unittest
  from collections import defaultdict
  import crypten
  import crypten.communicator
  import torch
  import torch.nn.functional
  from crypten.common import serial
  from crypten.common.tensor_types import is_float_tensor
  from crypten.config import cfg
  from test.multiprocess_test_case import get_random_test_tensor, MultiProcessTestCase
  from torch import nn
label_desc: Use image node_id 12 for calling the TestCrypten obj's underlying member method code with example usage: obj.test_save_load() and returns: obj