in optimum/exporters/executorch/integrations.py [0:0]
def export(self, input_ids=None, attention_mask=None) -> Dict[str, ExportedProgram]:
max_position_embeddings = getattr(self.model.config, "max_position_embeddings", 64)
max_seq_length = max(max_position_embeddings - 1, 1)
# Create dummy inputs with expected shapes
batch_size = 1
seq_length = max_seq_length
vocab_size = self.model.config.vocab_size
# Create example inputs (no need for tokenizer)
dummy_input_ids = (
torch.randint(0, vocab_size, (batch_size, seq_length), dtype=torch.long)
if input_ids is None
else input_ids
)
dummy_attention_mask = (
torch.ones((batch_size, seq_length), dtype=torch.long) if attention_mask is None else attention_mask
)
# Define dynamic shapes with Dim objects, always use Auto
dynamic_shapes = {
"input_ids": {1: torch.export.Dim.AUTO},
"attention_mask": {1: torch.export.Dim.AUTO},
}
# Export the model with dynamic dimensions
with torch.no_grad():
return {
"model": torch.export.export(
self.model,
args=(dummy_input_ids,),
kwargs={"attention_mask": dummy_attention_mask},
dynamic_shapes=dynamic_shapes,
strict=True,
)
}