class_docstr: Base test class and used for CPU case.
docstr: Testing using external flatten params tensors as module's params' backing data.
docstr_tok: ["Testing","using","external","flatten","params","tensors","as","module","'s","params","'","backing","data","."]
code: def test_unflatten_params(self):
      """Testing using external flatten params tensors as module's params' backing data."""
      for module_init_fn in self._get_module_init_fns():
          orig_module = module_init_fn()
          module = FlattenParamsWrapper(
              orig_module,
              param_list=orig_module.param_list,
              flat_param_names=orig_module.flat_param_names,
          )
  
          # keep a list of buffer's key to be used for verification below.
          buffers = {
              k.replace("_fpw_module.", "")
              for k, _ in module.named_buffers()
          }
  
          def clone_state_dict():
              """Return a copy of the module's current state via state_dict() API."""
              return OrderedDict(
                  (k, v.clone()) for k, v in module.state_dict().items()
              )
  
          ref_flat_params = [fp.clone() for fp in module.flat_params]
          # Get the current state as a reference.
          with module.unflatten_params():
              ref_state_dict = clone_state_dict()
          for ref_fp in ref_flat_params:
              assert not torch.all(
                  ref_fp == 0.0
              )  # Should not all be 0s.
  
          # get new_state_dict with supplied new_flat_params.
          new_flat_params = [
              torch.full_like(fp, fill_value=42.0)
              for fp in module.flat_params
          ]
          with module.unflatten_params(flat_params=new_flat_params):
              new_state_dict = clone_state_dict()
  
          # confirm that unflatten_params reflects values from new_flat_param
          assert new_state_dict.keys() == ref_state_dict.keys()
          for k, v in new_state_dict.items():
              if k in buffers:  # buffers are not changed
                  torch.testing.assert_allclose(v, ref_state_dict[k])
              else:  # params reflect new_flat_param value
                  torch.testing.assert_allclose(
                      v, torch.ones_like(v) * 42.0
                  )
  
          # after context manager exits, we go back to previous (reference) state
          assert len(module.flat_params) == len(ref_flat_params)
          for i in range(len(module.flat_params)):
              torch.testing.assert_allclose(
                  module.flat_params[i], ref_flat_params[i]
              )
  
          # get another copy of state from the module (without external backing data)
          with module.unflatten_params():
              ref_state_dict2 = clone_state_dict()
  
          # Verify it is still the same.
          assert objects_are_equal(ref_state_dict, ref_state_dict2)
  
          # if we load the new_state_dict, then the flat param should match new_flat_param
          module.load_state_dict(new_state_dict)
          assert len(module.flat_params) == len(new_flat_params)
          for i in range(len(module.flat_params)):
              torch.testing.assert_allclose(
                  module.flat_params[i], new_flat_params[i]
              )
  
imports: from collections import OrderedDict
  import unittest
  import torch
  from fairscale.fair_dev.testing.testing import objects_are_equal
  from fairscale.nn import FlattenParamsWrapper
label_desc: Use image node_id 24 for calling the TestFlattenParams obj's underlying member method code with example usage: obj.test_unflatten_params() and returns: OrderedDict