in optimum/exporters/executorch/integrations.py [0:0]
def _export_encoder(self, encoder_input_ids):
wrapped_encoder = Seq2SeqLMEncoderExportableModule(self.encoder).to("cpu").eval()
# Define dynamic sequence length for encoder
if isinstance(self.full_model, WhisperForConditionalGeneration):
assert (
encoder_input_ids.shape == self._expected_encoder_input_shape
), f"""This version of Whisper only accepts encoder input of shape {self._expected_encoder_input_shape}, passed shape: {encoder_input_ids.shape}.
For more infromation, please refer to the Whisper preprocessor config."""
dynamic_shapes = None
elif isinstance(self.full_model, T5ForConditionalGeneration):
encoder_seq_len_dim = torch.export.Dim("encoder_hidden_seq_length", max=self.max_hidden_seq_length)
dynamic_shapes = {"input_ids": {1: encoder_seq_len_dim}}
else:
raise ValueError(
f"Unsupported model type {type(self.full_model)} for Seq2SeqLMExportableModule encoder export."
)
# Export the encoder
with torch.no_grad():
exported_encoder = torch.export.export(
wrapped_encoder,
(encoder_input_ids,),
dynamic_shapes=dynamic_shapes,
strict=True,
)
return exported_encoder