def preprocess_text(self, data_samples: List[DataSample],
                        device: torch.device) -> List[DataSample]:
        """Preprocess text in advance before fed into language model.

        Args:
            data_samples (List[DataSample]): The annotation
                data of every samples. Defaults to None.
            device (torch.device): Device for text to put on.

        Returns:
            List[DataSample]: Return list of data samples.
        """
        tokens = []
        for sample in data_samples:
            prompt = self.prompt_tmpl.format(**sample.to_dict())
            input_ids = []
            while '<image>' in prompt:
                prefix, _, prompt = prompt.partition('<image>')
                input_ids.extend(
                    self.tokenizer(prefix, add_special_tokens=False).input_ids)
                input_ids.append(-200)
            if prompt:
                input_ids.extend(
                    self.tokenizer(prompt, add_special_tokens=False).input_ids)
            tokens.append(dict(input_ids=input_ids))

        self.tokenizer.padding_side = 'left'
        input_text = self.tokenizer.pad(
            tokens,
            padding='longest',
            return_tensors='pt',
            max_length=2000,
        ).to(device)
        return input_text
Preprocess text in advance before fed into language model.

        Args:
            data_samples (List[DataSample]): The annotation
                data of every samples. Defaults to None.
            device (torch.device): Device for text to put on.

        Returns:
            List[DataSample]: Return list of data samples.
        
mmpretrain/models/multimodal/llava/llava.py