code: def test_deepspeed_load_checkpoint_optimzer_state_requested(
      _, optimzer_state_requested, tmp_path
  ):
      """Test that the DeepSpeed strategy loads the optimizer state only when requested."""
      from deepspeed import DeepSpeedEngine
  
      strategy = DeepSpeedStrategy()
      optimizer = Mock(spec=Optimizer)
      model = Mock(spec=DeepSpeedEngine, optimizer=optimizer)
      model.modules.return_value = [model]
  
      # required, otherwise mock cannot be unpacked
      model.load_checkpoint.return_value = [None, {}]
  
      state = {"model": model}
      if optimzer_state_requested:
          state["optimizer"] = optimizer
  
      strategy.load_checkpoint(path=tmp_path, state=state)
      model.load_checkpoint.assert_called_with(
          tmp_path,
          tag="checkpoint",
          load_optimizer_states=optimzer_state_requested,
          load_lr_scheduler_states=False,
          load_module_strict=True,
      )
  
imports: import json
  from re import escape
  from unittest import mock
  from unittest.mock import ANY, Mock
  import pytest
  import torch
  from lightning.fabric.accelerators import CPUAccelerator, CUDAAccelerator
  from lightning.fabric.strategies import DeepSpeedStrategy
  from torch.optim import Optimizer
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 20 for calling a global function with example usage: test_deepspeed_load_checkpoint_optimzer_state_requested(_, optimzer_state_requested, tmp_path) without return types