code: def _get_maximum_possible_sequence_length(
      config: "ModelConfig", default_max_sequence_length: int
  ) -> int:
      """Returns the maximum possible sequence length for the LLM model based on the model config."""
      max_possible_sequence_length = default_max_sequence_length
      if (
          config.output_features[0].preprocessing.max_sequence_length
          is not None
      ):
          # Note: We don't need to check for max between feature.preprocessing.max_sequence_length and
          # defaults.text.preprocessing.max_sequence_length because the latter is only applied to input features.
          max_possible_sequence_length = max(
              default_max_sequence_length,
              config.output_features[
                  0
              ].preprocessing.max_sequence_length,
          )
      elif config.preprocessing.global_max_sequence_length is not None:
          # This is not perfect since it includes tokens from both input + output features, but this at least
          # ensures that max possible of the sequence length is used. It is very likely that the model learns
          # to generate sequences than this value.
          max_possible_sequence_length = max(
              max_possible_sequence_length,
              config.preprocessing.global_max_sequence_length,
          )
      elif max_possible_sequence_length == default_max_sequence_length:
          # It's possible that both max_sequence_length and global_max_sequence_length are not set, in which case
          # we should fall back to the window size of the pretrained model. By this point, because of schema validation
          # checks, we know that the base_model exists so we can safely grab the base model's config.
          # TODO (Arnav): Figure out how to factor in rope scaling factor into this calculation.
          model_config = AutoConfig.from_pretrained(config.base_model)
          max_possible_sequence_length = get_context_len(model_config)
          # Artifically leave a buffer of half the total model window size to trade off
          # runtime while likely covering a majority of the max sequence length.
          max_possible_sequence_length = (
              max_possible_sequence_length // 2
          )
      return max_possible_sequence_length
  
imports: import copy
  import logging
  import sys
  import warnings
  from typing import Any, Dict, List, Mapping, Set, TYPE_CHECKING
  from marshmallow import ValidationError
  from transformers import AutoConfig
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import CATEGORY, COMBINED, DECODER, DEFAULTS, ENCODER, GRID_SEARCH, INPUT_FEATURES, LOSS, MODEL_ECD, MODEL_LLM, OUTPUT_FEATURES, PARAMETERS, PREPROCESSING, SEQUENCE, SPACE, TEXT, TYPE
  from ludwig.features.feature_utils import compute_feature_hash
  from ludwig.schema.features.utils import output_config_registry
  from ludwig.schema.hyperopt.scheduler import BaseHyperbandSchedulerConfig
  from ludwig.schema.llms.generation import LLMGenerationConfig
  from ludwig.schema.trainer import ECDTrainerConfig
  from ludwig.types import HyperoptConfigDict, ModelConfigDict
  from ludwig.utils.data_utils import get_sanitized_feature_name
  from ludwig.utils.llm_utils import get_context_len
label_desc: Use image node_id 14 for calling a global function with example usage: _get_maximum_possible_sequence_length(config, default_max_sequence_length) and returns: max_possible_sequence_length