code: def test_catch_grad_grad():
      with temp_files_ctx(num=1) as temp_files:
          # Check that ShardedDDP exposes the original module's attributes
          dist.init_process_group(
              init_method="file://" + temp_files[0],
              backend="gloo",
              rank=0,
              world_size=1,
          )
  
          model = Sequential(Linear(2, 3), Linear(3, 3))
          model.train()
          chained_grad = torch.zeros_like(next(model.parameters()))
          chained_grad.requires_grad = True
          next(model.parameters()).grad = chained_grad
  
          optimizer = OSS(
              params=model.parameters(),
              optim=torch.optim.SGD,
              lr=1e-3,
              momentum=0.99,
          )
          ddp_model = ShardedDataParallel(model, optimizer)
  
          inputs = torch.rand(100, 2)
          with pytest.raises(RuntimeError):
              _ = ddp_model(inputs)
  
          dist.destroy_process_group()
  
imports: from contextlib import suppress
  import numpy
  import pytest
  import torch
  import torch.distributed
  import torch.multiprocessing
  from torch.nn import Linear, Sequential
  from fairscale.fair_dev.testing.testing import GPT2, SGDWithPausingCompute, available_devices, check_same_models_across_ranks, skip_if_less_than_four_gpu, skip_if_no_cuda, skip_if_single_gpu, temp_files_ctx
  from fairscale.nn.data_parallel import ShardedDataParallel
  from fairscale.optim import OSS
label_desc: Use image node_id 9 for calling a global function with example usage: test_catch_grad_grad() without return types