code: def _closest_ref_length(
      references: Sequence[Sequence[Any]], hyp_len: int
  ) -> int:
      ref_lens = (len(reference) for reference in references)
      closest_ref_len = min(
          ref_lens,
          key=lambda ref_len: (abs(ref_len - hyp_len), ref_len),
      )
      return closest_ref_len
  
imports: import math
  from typing import Any, Callable, Sequence, Tuple, Union
  import torch
  from ignite.exceptions import NotComputableError
  from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce
  from ignite.metrics.nlp.utils import modified_precision
label_desc: Use image node_id 1 for calling a global function with example usage: _closest_ref_length(references, hyp_len) and returns: closest_ref_len