from typing import Any, List, Tuple

import torch

from vllm.distributed.parallel_state import TensorMetadata
from vllm_mlu.mlu_hijack_utils import MluHijackObject
from vllm.model_executor.models.llama import LlamaForCausalLM

def vllm__module_executor__models__llama__LlamaForCausalLM__get_intermediate_tensor_metadata(
    self,
    batch_size: int,
    dtype: torch.dtype,
    device: torch.device,
) -> List[Tuple[str, Any]]:
    metadata_list: List[Tuple[str, Any]] = []
    size = torch.Size([batch_size, self.config.hidden_size])
    metadata_list.append(("hidden_states", TensorMetadata(device.type, dtype, size)))
    return metadata_list

MluHijackObject.apply_hijack(
    LlamaForCausalLM,
    "get_intermediate_tensor_metadata",
    vllm__module_executor__models__llama__LlamaForCausalLM__get_intermediate_tensor_metadata
)
