code: def optimizer_state_to_device(state, device):
      r"""
      将一个 ``optimizer`` 的 ``state_dict`` 迁移到对应的设备。
  
      :param state: :func:`optimzier.state_dict` 获取的 state_dictt
      :param device: 要迁移到的目的设备。
      :return: 迁移后的新的 state_dict。
      """
      new_state = {}
      for name, param in state.items():
          if isinstance(param, dict):
              new_state[name] = optimizer_state_to_device(param, device)
          elif isinstance(param, oneflow.Tensor):
              new_state[name] = param.to(device).clone()
          else:
              new_state[name] = param
      return new_state
  
imports: import os
  from typing import Any, Dict, Optional
  from enum import IntEnum
  import contextlib
  import random
  import numpy
  import inspect
  from fastNLP.envs.imports import _NEED_IMPORT_ONEFLOW
  from fastNLP.envs.utils import get_global_seed
  from fastNLP.envs import get_global_rank, FASTNLP_BACKEND_LAUNCH, FASTNLP_GLOBAL_SEED
  from fastNLP.core.samplers import ReproducibleBatchSampler
  from fastNLP.core.utils import auto_param_call
  from fastNLP.core.log import logger
label_desc: Use image node_id 5 for calling a global function with example usage: optimizer_state_to_device(state, device) and returns: new_state