docstr: Save sharded model to checkpoint but only on master process.
  The model should be unwrapped in self.load_model via ModelWrapper.unwrap.
  As there is communication when getting state dict, model.state_dict() must be called on all processes.
docstr_tok: ["Save","sharded","model","to","checkpoint","but","only","on","master","process",".","The","model","should","be","unwrapped","in","self.load_model","via","ModelWrapper.unwrap",".","As","there","is","communication","when","getting","state","dict",",","model.state_dict","(",")","must","be","called","on","all","processes","."]
code: def save_unsharded_model(
      self,
      model: GeminiDDP,
      checkpoint: str,
      gather_dtensor: bool,
      use_safetensors: bool,
  ):
      """
      Save sharded model to checkpoint but only on master process.
      The model should be unwrapped in self.load_model via ModelWrapper.unwrap.
      As there is communication when getting state dict, model.state_dict() must be called on all processes.
      """
      assert isinstance(
          model, GeminiDDP
      ), "Please boost the model before saving!"
      state_dict = model.state_dict(only_rank_0=True)
      if self.coordinator.is_master():
          save_state_dict(state_dict, checkpoint, use_safetensors)
  
imports: import gc
  import logging
  import os
  import random
  from pathlib import Path
  from typing import Callable, Iterator, List, Optional, Tuple
  import numpy
  import torch
  import torch.distributed
  import torch.nn
  from torch.distributed.distributed_c10d import _get_default_group
  from torch.optim import Optimizer
  from torch.optim.lr_scheduler import _LRScheduler
  from torch.utils.data import DataLoader
  from torch.utils.data.distributed import DistributedSampler
  from colossalai.checkpoint_io import CheckpointIndexFile, CheckpointIO, GeneralCheckpointIO
  from colossalai.checkpoint_io.utils import get_model_base_filenames, get_optimizer_base_filenames, load_shard_state_dict, save_config_file, save_state_dict, save_state_dict_shards
  from colossalai.cluster import DistCoordinator, ProcessGroupMesh
  from colossalai.interface import ModelWrapper, OptimizerWrapper
  from colossalai.shardformer import ShardConfig, ShardFormer
  from colossalai.utils import get_current_device
  from colossalai.utils.device import IS_NPU_AVAILABLE
  from colossalai.zero import GeminiDDP, GeminiOptimizer
  from colossalai.zero.gemini.memory_tracer import MemStats
  from .dp_plugin_base import DPPluginBase
label_desc: Use image node_id 2 for calling the GeminiCheckpointIO obj's underlying member method code with example usage: obj.save_unsharded_model(model, checkpoint, gather_dtensor, use_safetensors) without return types