    def generate(
        self,
        input_ids,
        prompt_mels=None,
        prompt_output_ids=None,
        max_length=2000,
        temperature=0.8,
        top_k=50,
        top_p=0.9,
        repeat_penalty=1.0,
        min_new_tokens=50,
    ):
        """
        Generate for one sample.

        Args:
            input_ids: [1, T]
            prompt_mels: [1, T, n_mels]
            prompt_output_ids: [1, T] if is not None
            max_length: int
            temperature: float
            top_k: int
            top_p: float
            repeat_penalty: float
        Returns:
            gen_tokens: [1, T]
        """
        (
            input_ids,
            _,
            _,
        ) = self.padding_for_input(
            input_ids,
            torch.ones_like(input_ids),
            self.input_eos_token_id,
            self.input_bos_token_id,
            self.pad_token_id,
        )

        if prompt_output_ids is not None:
            prompt_output_ids, _, _ = self.padding_for_output(
                prompt_output_ids,
                torch.ones_like(prompt_output_ids),
                self.output_eos_token_id,
                self.output_bos_token_id,
                self.pad_token_id,
            )
            prompt_output_ids = prompt_output_ids[:, :-1]  # remove the eos token

        if self.use_global_style_encoder:
            # When using global style encoder, prompt_mels is required
            assert prompt_mels is not None

            input_emb = self.model.model.embed_tokens(input_ids)
            global_style_emb = self.global_encoder(
                prompt_mels,
                torch.ones_like(prompt_mels[:, :, 0]).to(prompt_mels.device),
            ).unsqueeze(1)

            llama_input_emb = torch.cat([input_emb, global_style_emb], dim=1)

            if prompt_output_ids is not None:
                prompt_output_emb = self.model.model.embed_tokens(prompt_output_ids)
                llama_input_emb = torch.cat([llama_input_emb, prompt_output_emb], dim=1)

            input_length = llama_input_emb.shape[1]

            gen_tokens = self.model.generate(
                inputs_embeds=llama_input_emb,
                do_sample=True,
                max_length=max_length,
                pad_token_id=self.pad_token_id,
                eos_token_id=self.output_eos_token_id,
                temperature=temperature,
                top_k=top_k,
                top_p=top_p,
                repetition_penalty=repeat_penalty,
                min_new_tokens=min_new_tokens,
            )
        else:
            # When not using global style encoder, prompt_output_ids is required
            assert prompt_output_ids is not None

            llama_input_ids = torch.cat([input_ids, prompt_output_ids], dim=-1)
            input_length = llama_input_ids.shape[1]

            gen_tokens = self.model.generate(
                llama_input_ids,
                do_sample=True,
                max_length=max_length,
                pad_token_id=self.pad_token_id,
                eos_token_id=self.output_eos_token_id,
                temperature=temperature,
                top_k=top_k,
                top_p=top_p,
                repetition_penalty=repeat_penalty,
                min_new_tokens=min_new_tokens,
            )

            gen_tokens = gen_tokens[:, input_length:]

        if gen_tokens[:, 0] == self.output_bos_token_id:
            gen_tokens = gen_tokens[:, 1:]
        if gen_tokens[:, -1] == self.output_eos_token_id:
            gen_tokens = gen_tokens[:, :-1]

        return gen_tokens
Generate for one sample.

Args:
input_ids: [1, T]
prompt_mels: [1, T, n_mels]
prompt_output_ids: [1, T] if is not None
max_length: int
temperature: float
top_k: int
top_p: float
repeat_penalty: float
Returns:
gen_tokens: [1, T]
models/vc/autoregressive_transformer/ar_model.py