code: def apply_factories(sharded_state_dict: ShardedStateDict):
      def apply(x):
          if isinstance(x, ShardedTensorFactory):
              x = x.build()
          return x
  
      dict_list_map_inplace(apply, sharded_state_dict)
  
imports: import logging
  from dataclasses import dataclass, replace
  from itertools import chain
  from typing import Any, Callable, Dict, Optional, Tuple, Union
  import numpy
  import torch
  from .core import CheckpointingException
  from .dict_utils import dict_list_map_inplace, dict_list_map_outplace
label_desc: Use image node_id 2 for calling a global function with example usage: apply_factories(sharded_state_dict) and returns: x