code: def top_k_top_p_filtering(
      logits: torch.FloatTensor,
      top_k: int = 0,
      top_p: float = 1.0,
      filter_value: float = -float("Inf"),
      min_tokens_to_keep: int = 1,
  ) -> torch.FloatTensor:
      """
      Filter a distribution of logits using top-k and/or nucleus (top-p) filtering
  
      Args:
          logits: logits distribution shape (batch size, vocabulary size)
          top_k (`int`, *optional*, defaults to 0):
              If > 0, only keep the top k tokens with highest probability (top-k filtering)
          top_p (`float`, *optional*, defaults to 1.0):
              If < 1.0, only keep the top tokens with cumulative probability >= top_p (nucleus filtering). Nucleus
              filtering is described in Holtzman et al. (http://arxiv.org/abs/1904.09751)
          min_tokens_to_keep (`int`, *optional*, defaults to 1):
              Minimumber of tokens we keep per batch example in the output.
  
      From: https://gist.github.com/thomwolf/1a5a29f6962089e871b94cbd09daf317
      """
      warnings.warn(
          "`top_k_top_p_filtering` is scheduled for deletion in v4.39. Use `TopKLogitsWarper` and `TopPLogitsWarper` "
          "instead.",
          DeprecationWarning,
      )
  
      if top_k > 0:
          logits = TopKLogitsWarper(
              top_k=top_k,
              filter_value=filter_value,
              min_tokens_to_keep=min_tokens_to_keep,
          )(None, logits)
  
      if 0 <= top_p <= 1.0:
          logits = TopPLogitsWarper(
              top_p=top_p,
              filter_value=filter_value,
              min_tokens_to_keep=min_tokens_to_keep,
          )(None, logits)
  
      return logits
  
imports: import copy
  import inspect
  import warnings
  from dataclasses import dataclass
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  import torch.distributed
  from torch import nn
  from ..cache_utils import Cache, DynamicCache
  from ..integrations.deepspeed import is_deepspeed_zero3_enabled
  from ..modeling_outputs import CausalLMOutputWithPast, Seq2SeqLMOutput
  from ..models.auto import MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING, MODEL_FOR_CAUSAL_LM_MAPPING, MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING, MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING, MODEL_FOR_VISION_2_SEQ_MAPPING
  from ..utils import ExplicitEnum, ModelOutput, is_accelerate_available, logging
  from .beam_constraints import DisjunctiveConstraint, PhrasalConstraint
  from .beam_search import BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
  from .candidate_generator import AssistedCandidateGenerator, CandidateGenerator, PromptLookupCandidateGenerator, _crop_past_key_values, _prepare_attention_mask, _prepare_token_type_ids
  from .configuration_utils import GenerationConfig
  from .logits_process import EncoderNoRepeatNGramLogitsProcessor, EncoderRepetitionPenaltyLogitsProcessor, EpsilonLogitsWarper, EtaLogitsWarper, ExponentialDecayLengthPenalty, ForcedBOSTokenLogitsProcessor, ForcedEOSTokenLogitsProcessor, ForceTokensLogitsProcessor, HammingDiversityLogitsProcessor, InfNanRemoveLogitsProcessor, LogitNormalization, LogitsProcessorList, MinLengthLogitsProcessor, MinNewTokensLengthLogitsProcessor, NoBadWordsLogitsProcessor, NoRepeatNGramLogitsProcessor, PrefixConstrainedLogitsProcessor, RepetitionPenaltyLogitsProcessor, SequenceBiasLogitsProcessor, SuppressTokensAtBeginLogitsProcessor, SuppressTokensLogitsProcessor, TemperatureLogitsWarper, TopKLogitsWarper, TopPLogitsWarper, TypicalLogitsWarper, UnbatchedClassifierFreeGuidanceLogitsProcessor
  from .stopping_criteria import MaxLengthCriteria, MaxTimeCriteria, StoppingCriteria, StoppingCriteriaList, validate_stopping_criteria
label_desc: Use image node_id 3 for calling a global function with example usage: top_k_top_p_filtering(logits, top_k, top_p, filter_value, min_tokens_to_keep) and returns: logits