code: def load_v3(state, overwrite_config=None, rank=0, world_size=1):
      saved_config = pytext_config_from_json(state[CONFIG_JSON])
      if overwrite_config:
          config = overwrite_config
          print(f"Use config from current task")
      else:
          config = saved_config
          print(f"Use config saved in snapshot")
  
      model_state = state[MODEL_STATE]
      training_state = state[TRAINING_STATE]
      if training_state and training_state.tensorizers:
          tensorizers = training_state.tensorizers
      else:
          tensorizers = state[TENSORIZERS]
      # importing in file level generates circular import/dependency failures,
      # that need refator later to fix
      from .task import create_task
  
      task = create_task(
          config.task,
          metadata=state[DATA_STATE],
          model_state=model_state,
          tensorizers=tensorizers,
          rank=rank,
          world_size=world_size,
      )
  
      # TODO: T53664090 @stevenliu save & load state_dict() of optimizer and scheduler
      if training_state:
          if training_state.model is None and task.model:
              training_state.model = task.model
          if training_state.optimizer and task.trainer.optimizer:
              """
              https://pytorch.org/tutorials/beginner/saving_loading_models.html
              Unpickling optimizer object from checkpoint could result in a
              different parameter copy from model parameters. Especially in
              mixied precision training, which optimizer param_groups maintains
              master weights copy instead of the model parameters.
  
              The suggested loading mechanism is
  
              model = TheModelClass(*args, **kwargs)
              optimizer = TheOptimizerClass(model.parameters(), *args, **kwargs)
  
              checkpoint = torch.load(PATH)
              model.load_state_dict(checkpoint['model_state_dict'])
              optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
              """
  
              optimizer = task.trainer.optimizer
              optimizer.load_state_dict(
                  training_state.optimizer.state_dict()
              )
              training_state.optimizer = optimizer
  
      return task, config, training_state
  
imports: import io
  import logging
  import os
  from typing import Dict, Optional
  import torch
  from pytext.config import config_to_json, pytext_config_from_json, PyTextConfig
  from pytext.data import CommonMetadata
  from pytext.data.tensorizers import Tensorizer
  from pytext.models import Model
  from pytext.trainers.training_state import TrainingState
  from pytext.utils.file_io import PathManager
  from .pytext_checkpoint_management import get_checkpoint_manager
label_desc: Use image node_id 4 for calling a global function with example usage: load_v3(state, overwrite_config, rank, world_size) and returns: task,  config,  training_state