code: def test_averaging_cancel():
      averagers = tuple(
          DecentralizedAverager(
              averaged_tensors=[torch.randn(3)],
              dht=dht,
              min_matchmaking_time=0.5,
              request_timeout=0.3,
              client_mode=(i % 2 == 0),
              prefix="mygroup",
              start=True,
          )
          for i, dht in enumerate(launch_dht_instances(4))
      )
  
      step_controls = [
          averager.step(
              wait=False, scheduled_time=hivemind.get_dht_time() + 1
          )
          for averager in averagers
      ]
  
      time.sleep(0.05)
      step_controls[0].cancel()
      step_controls[1].cancel()
  
      for i, control in enumerate(step_controls):
          if i in (0, 1):
              assert control.cancelled()
          else:
              assert (
                  control.result() is not None
                  and len(control.result()) == 2
              )
  
      for averager in averagers:
          averager.shutdown()
  
imports: import random
  import time
  import numpy
  import pytest
  import torch
  import hivemind
  from hivemind.averaging import DecentralizedAverager
  from hivemind.averaging.allreduce import AveragingMode
  from hivemind.averaging.control import AveragingStage
  from hivemind.averaging.key_manager import GroupKeyManager
  from hivemind.averaging.load_balancing import load_balance_peers
  from hivemind.averaging.partition import AllreduceException
  from hivemind.p2p import PeerID
  from test_utils.dht_swarms import launch_dht_instances
label_desc: Use image node_id 17 for calling a global function with example usage: test_averaging_cancel() without return types