code: def swap_state(model, state):
      """
      Context manager that swaps the state of a model, e.g:
  
          # model is in old state
          with swap_state(model, new_state):
              # model in new state
          # model back to old state
      """
      old_state = copy_state(model.state_dict())
      model.load_state_dict(state)
      try:
          yield
      finally:
          model.load_state_dict(old_state)
  
file_path: fairseq/examples/speech_synthesis/preprocessing/denoiser/utils.py
imports: import functools
  import logging
  from contextlib import contextmanager
  import inspect
  import time
label_desc: Use image node_id 5 for calling a global function with example usage: swap_state(model, state) without return types