class_docstr: Dimensioning properties
docstr: See ``DSInferenceModelBase.maybe_allocate_kv`` for documentation.
  
  This method assumes an autoregressive dense attention pattern. Override this method
  if this does not match the model's attention pattern.
docstr_tok: ["See","``","DSInferenceModelBase.maybe_allocate_kv","``","for","documentation",".","This","method","assumes","an","autoregressive","dense","attention","pattern",".","Override","this","method","if","this","does","not","match","the","model","'s","attention","pattern","."]
code: def maybe_allocate_kv(
      self, sequence: DSSequenceDescriptor, n_new_tokens: int
  ) -> None:
      """
      See ``DSInferenceModelBase.maybe_allocate_kv`` for documentation.
  
      This method assumes an autoregressive dense attention pattern. Override this method
      if this does not match the model's attention pattern.
      """
      _, n_needed_blocks = self.get_kv_requirements(
          sequence, n_new_tokens, self.state_manager.free_blocks
      )
  
      if n_needed_blocks > 0:
          new_blocks = self.state_manager.allocate_blocks(
              n_needed_blocks
          )
          sequence.extend_kv_cache(new_blocks)
  
imports: from abc import abstractmethod
  from typing import Optional
  import torch
  from deepspeed.accelerator import get_accelerator
  from ..config_v2 import RaggedInferenceEngineConfig
  from ..inference_utils import ActivationType, ceil_div, is_gated
  from ..model_implementations import *
  from ..model_implementations.sharding import *
  from ..modules.configs import DSEmbeddingsConfig, DSLinearConfig, DSMoEConfig, DSNormConfig, DSSelfAttentionConfig, DSUnembedConfig, NormTypeEnum, PositionalEmbeddingType
  from ..modules import heuristics
  from ..ragged import DSSequenceDescriptor, KVCacheConfig, RaggedBatchWrapper
  from .inference_model_base import DSInferenceModelBase, DSModelImplementationConfig, MPType
  from ..inference_parameter import InferenceParameter
label_desc: Use image node_id 25 for calling the DSTransformerModelBase obj's underlying member method code with example usage: obj.maybe_allocate_kv(sequence, n_new_tokens) without return types