class_docstr: 实现 ``fairscale`` 功能的 ``Driver`` 。
  
  :param model: 传入给 ``Trainer`` 的 ``model`` 参数。
  :param parallel_device: 用于分布式训练的 ``gpu`` 设备。
  :param is_pull_by_torch_run: 标志当前的脚本的启动是否由 ``python -m torch.distributed.launch`` 启动的。
  :param fp16: 是否开启 fp16 训练。
  :param fairscale_kwargs:
  
      * *oss_kwargs* --
      * *sdp_kwargs* --
      * *fsdp_kwargs* --
      * *ddp_kwargs* --
      * *set_grad_to_none* -- 是否在训练过程中在每一次 optimizer 更新后将 grad 置为 ``None``
      * *non_blocking* -- 表示用于 :meth:`torch.Tensor.to` 方法的参数 non_blocking
      * *gradscaler_kwargs* -- 用于 ``fp16=True`` 时，提供给 :class:`torch.amp.cuda.GradScaler` 的参数
  :kwargs:
      * *wo_auto_param_call* (``bool``) -- 是否关闭在训练时调用我们的 ``auto_param_call`` 函数来自动匹配 batch 和前向函数的参数的行为
  
      .. note::
  
          关于该参数的详细说明，请参见 :class:`~fastNLP.core.controllers.Trainer` 中的描述；函数 ``auto_param_call`` 详见 :func:`fastNLP.core.utils.auto_param_call`。
class_docstr_tok: ["\u5b9e\u73b0","``","fairscale","``","\u529f\u80fd\u7684","``","Driver","``","\u3002",":","param","model",":","\u4f20\u5165\u7ed9","``","Trainer","``","\u7684","``","model","``","\u53c2\u6570\u3002",":","param","parallel_device",":","\u7528\u4e8e\u5206\u5e03\u5f0f\u8bad\u7ec3\u7684","``","gpu","``","\u8bbe\u5907\u3002",":","param","is_pull_by_torch_run",":","\u6807\u5fd7\u5f53\u524d\u7684\u811a\u672c\u7684\u542f\u52a8\u662f\u5426\u7531","``","python","-m","torch.distributed.launch","``","\u542f\u52a8\u7684\u3002",":","param","fp16",":","\u662f\u5426\u5f00\u542f","fp16","\u8bad\u7ec3\u3002",":","param","fairscale_kwargs",":","*","*","oss_kwargs","*","--","*","*","sdp_kwargs","*","--","*","*","fsdp_kwargs","*","--","*","*","ddp_kwargs","*","--","*","*","set_grad_to_none","*","--","\u662f\u5426\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u5728\u6bcf\u4e00\u6b21","optimizer","\u66f4\u65b0\u540e\u5c06","grad","\u7f6e\u4e3a","``","None","``","*","*","non_blocking","*","--","\u8868\u793a\u7528\u4e8e",":","meth",":","`","torch.Tensor.to","`","\u65b9\u6cd5\u7684\u53c2\u6570","non_blocking","*","*","gradscaler_kwargs","*","--","\u7528\u4e8e","``","fp16=True","``","\u65f6\uff0c\u63d0\u4f9b\u7ed9",":","class",":","`","torch.amp.cuda.GradScaler","`","\u7684\u53c2\u6570",":","kwargs",":","*","*","wo_auto_param_call","*","(","``","bool","``",")","--","\u662f\u5426\u5173\u95ed\u5728\u8bad\u7ec3\u65f6\u8c03\u7528\u6211\u4eec\u7684","``","auto_param_call","``","\u51fd\u6570\u6765\u81ea\u52a8\u5339\u914d","batch","\u548c\u524d\u5411\u51fd\u6570\u7684\u53c2\u6570\u7684\u884c\u4e3a","..","note",":",":","\u5173\u4e8e\u8be5\u53c2\u6570\u7684\u8be6\u7ec6\u8bf4\u660e\uff0c\u8bf7\u53c2\u89c1",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u4e2d\u7684\u63cf\u8ff0\uff1b\u51fd\u6570","``","auto_param_call","``","\u8be6\u89c1",":","func",":","`","fastNLP.core.utils.auto_param_call","`","\u3002"]
docstr: 从 folder 中加载权重并赋值到当前 driver 的模型上。
  
  :param filepath: 加载权重或模型的路径
  :param load_state_dict: 保存的内容是否只是权重。
  :param kwargs:
  :return:
docstr_tok: ["\u4ece","folder","\u4e2d\u52a0\u8f7d\u6743\u91cd\u5e76\u8d4b\u503c\u5230\u5f53\u524d","driver","\u7684\u6a21\u578b\u4e0a\u3002",":","param","filepath",":","\u52a0\u8f7d\u6743\u91cd\u6216\u6a21\u578b\u7684\u8def\u5f84",":","param","load_state_dict",":","\u4fdd\u5b58\u7684\u5185\u5bb9\u662f\u5426\u53ea\u662f\u6743\u91cd\u3002",":","param","kwargs",":",":","return",":"]
code: def load_model(
      self, filepath: str, only_state_dict: bool = True, **kwargs
  ):
      """
      从 folder 中加载权重并赋值到当前 driver 的模型上。
  
      :param filepath: 加载权重或模型的路径
      :param load_state_dict: 保存的内容是否只是权重。
      :param kwargs:
      :return:
      """
      states = torch.load(filepath, map_location="cpu")
      if isinstance(states, dict) and only_state_dict is False:
          logger.rank_zero_warning(
              f"It seems like that {filepath} only contains state, you may need to use "
              f"`only_state_dict=True`"
          )
      elif not isinstance(states, dict) and only_state_dict is True:
          logger.rank_zero_warning(
              f"It seems like that {filepath} is not state, you may need to use "
              f"`only_state_dict=False`"
          )
      if not isinstance(states, Mapping):
          states = states.state_dict()
  
      if self.fs_type in ("ddp", "sdp"):
          model = self.model.module.model
      else:
          model = self.model
          states = {f"model.{k}": v for k, v in states.items()}
  
      model.load_state_dict(states)
  
imports: from typing import List, Sequence, Union, Dict, Mapping
  from pathlib import Path
  import os
  import functools
  from fastNLP.envs.imports import _NEED_IMPORT_FAIRSCALE
  from ...log import logger
  from .utils import _DDPWrappingModel
  from .ddp import TorchDDPDriver
  from .torch_driver import TorchDriver
  from .utils import _build_fp16_env
  from ....envs.distributed import all_rank_call_context
  from fastNLP.envs import FASTNLP_DISTRIBUTED_CHECK
  from .utils import optimizer_state_to_device
label_desc: Use image node_id 5 for calling the FairScaleDriver obj's underlying member method code with example usage: obj.load_model(filepath, only_state_dict) without return types