code: def _process_dispatched_task(
      task: Future, detect_anomalies: bool
  ) -> Optional[Tuple[torch.Tensor]]:
      if task.exception() or task.cancelled():
          logger.warning(
              f"Task {task} failed: {type(task.exception())}"
          )
          return None
  
      outputs = task.result()
      for tensor in outputs:
          if detect_anomalies and not tensor.isfinite().all():
              logger.error(
                  f"Task {task} failed: output tensor contains nan/inf values"
              )
              return None
  
      return outputs
  
imports: from __future__ import annotations
  import time
  from concurrent.futures import Future
  from queue import Empty, Queue
  from typing import Any, Dict, List, Optional, Tuple
  import torch
  import torch.nn
  from torch.autograd.function import once_differentiable
  from hivemind.compression import serialize_torch_tensor
  from hivemind.dht import DHT
  from hivemind.moe.client.beam_search import MoEBeamSearcher
  from hivemind.moe.client.expert import DUMMY, RemoteExpert, expert_backward, expert_forward, get_server_stub
  from hivemind.moe.client.remote_expert_worker import RemoteExpertWorker
  from hivemind.moe.expert_uid import UID_DELIMITER
  from hivemind.p2p.p2p_daemon_bindings.control import P2PDaemonError
  from hivemind.utils import nested_flatten, nested_map, nested_pack
  from hivemind.utils.logging import get_logger
label_desc: Use image node_id 1 for calling a global function with example usage: _process_dispatched_task(task, detect_anomalies) and returns: outputs, None, None