jakmro commited on
Commit
0e72980
·
verified ·
1 Parent(s): e14003c

Delete all-mpnet-base-v2.py

Browse files
Files changed (1) hide show
  1. all-mpnet-base-v2.py +0 -47
all-mpnet-base-v2.py DELETED
@@ -1,47 +0,0 @@
1
- import torch
2
- from transformers import AutoTokenizer, AutoModel
3
-
4
- from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
5
- from executorch.exir import to_edge_transform_and_lower
6
- from torch.export import export, Dim
7
- from executorch.runtime import Runtime
8
-
9
- model_name = f"all-mpnet-base-v2.pte"
10
- tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-mpnet-base-v2")
11
- model = AutoModel.from_pretrained("sentence-transformers/all-mpnet-base-v2")
12
- model.eval()
13
-
14
- sentences = ["This is an example sentence"]
15
- encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt")
16
- executorch_input = (encoded_input["input_ids"], encoded_input["attention_mask"])
17
-
18
- # Export the model
19
- executorch_program = to_edge_transform_and_lower(
20
- export(
21
- model,
22
- executorch_input,
23
- dynamic_shapes={
24
- "input_ids": {
25
- 1: Dim("tokens", min=1, max=384),
26
- },
27
- "attention_mask": {
28
- 1: Dim("tokens", min=1, max=384),
29
- },
30
- },
31
- ),
32
- partitioner=[XnnpackPartitioner()],
33
- ).to_executorch()
34
-
35
- # Save the model
36
- with open(model_name, "wb") as file:
37
- file.write(executorch_program.buffer)
38
-
39
- # Check the model output
40
- eager_reference_output = model(**encoded_input)
41
-
42
- runtime = Runtime.get()
43
- program = runtime.load_program(model_name)
44
- method = program.load_method("forward")
45
- output = method.execute(executorch_input)
46
-
47
- print(torch.allclose(output[0], eager_reference_output[0], rtol=1e-3, atol=1e-5))