code: def _global_threshold_generate(
      metrics: _METRICS,
      group: List[Tuple[str, str, PruningTargetSpace]],
      sparse_number: int,
  ) -> float:
      buffer = []
      buffer_elem = 0
      for module_name, target_name, target_space in group:
          metric = metrics[module_name][target_name]
          grain_size = target_space.target.numel() // metric.numel()  # type: ignore
          for m in metric.cpu().detach().view(-1):
              if buffer_elem <= sparse_number:
                  heapq.heappush(buffer, (-m.item(), grain_size))
                  buffer_elem += grain_size
              else:
                  _, previous_grain_size = heapq.heappushpop(
                      buffer, (-m.item(), grain_size)
                  )
                  buffer_elem += grain_size - previous_grain_size
      return -heapq.heappop(buffer)[0]
  
imports: from __future__ import annotations
  from collections import defaultdict
  from functools import reduce
  import heapq
  from typing import Callable, Dict, List, Tuple
  import numpy
  import torch
  from .calculate_metrics import _METRICS
  from ...base.compressor import _PRUNING_TARGET_SPACES
  from ...base.target_space import PruningTargetSpace, TargetType
label_desc: Use image node_id 10 for calling a global function with example usage: _global_threshold_generate(metrics, group, sparse_number) and returns: unknown