docstr: Raise ValueError when input_ids exceeds the context.
code: def generate(
      self, config: GenerationConfig, input_ids: torch.Tensor
  ) -> torch.Tensor:
      """Raise ValueError when input_ids exceeds the context."""
      # NOTE: this implementation is only for decoder-only models
      # Recalculate the max number of tokens to avoid overflowing the context window
      input_len = input_ids.shape[1]
      if input_len >= self.max_context_size:
          raise ValueError(
              f"Input length {input_len} >= Context size {self.max_context_size}"
          )
      assert input_len < self.max_context_size
  
      max_context_size = min(
          self.max_context_size - input_len,
          config.max_new_tokens,
          config.max_length - input_len,
      )
      config = config.with_max_new_tokens_being(max_context_size)
  
      tf_config = config.to_transformers_generation_config(
          eos_token_id=self.tokenization_context.eos_token_id,
          pad_token_id=self.tokenization_context.pad_token_id,
      )
      attention_mask = input_ids.ne(
          self.tokenization_context.pad_token_id
      )
      # breakpoint()
      outputs = self.model.generate(
          input_ids=input_ids,
          attention_mask=attention_mask,
          generation_config=tf_config,
      )
      # input_len = input_ids.shape[1]
      return outputs[:, input_len:]
  
imports: from dataclasses import dataclass, field
  from enum import Enum
  from typing import Callable, Literal
  import torch
  from transformers import AutoModelForCausalLM, AutoTokenizer
  from transformers import GenerationConfig
  from transformers import PreTrainedModel, PreTrainedTokenizer
label_desc: Use image node_id 1 for calling the ModelContext obj's underlying member method code with example usage: obj.generate(config, input_ids) and returns: outputs