zhiweili
commited on
Commit
Β·
6e0dbac
1
Parent(s):
13ce7ee
test compile first
Browse files- app_tensorrt.py +19 -3
app_tensorrt.py
CHANGED
@@ -34,10 +34,26 @@ base_pipe.scheduler = DDPMScheduler.from_pretrained(
|
|
34 |
)
|
35 |
|
36 |
backend = "torch_tensorrt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
|
43 |
|
|
|
34 |
)
|
35 |
|
36 |
backend = "torch_tensorrt"
|
37 |
+
import torch_tensorrt
|
38 |
+
print('Compiling model...')
|
39 |
+
compiledModel = torch.compile(
|
40 |
+
base_pipe.unet,
|
41 |
+
backend=backend,
|
42 |
+
options={
|
43 |
+
"truncate_long_and_double": True,
|
44 |
+
"enabled_precisions": {torch.float32, torch.float16},
|
45 |
+
},
|
46 |
+
dynamic=False,
|
47 |
+
)
|
48 |
+
print('Model compiled!')
|
49 |
+
|
50 |
+
print('Saving compiled model...')
|
51 |
+
torch_tensorrt.save(compiledModel, "compiled_pipe.ep")
|
52 |
+
print('Compiled model saved!')
|
53 |
|
54 |
+
print('Loading compiled model...')
|
55 |
+
loadedModel = torch_tensorrt.load("compiled_pipe.ep").module()
|
56 |
+
print('Compiled model loaded!')
|
57 |
|
58 |
|
59 |
|