31
31
32
32
.. code-block:: text
33
33
34
- Program methods: ( 'forward', 'forward2')
34
+ Program methods: { 'forward'}
35
35
Ran forward((tensor([[1., 1.],
36
36
[1., 1.]]), tensor([[1., 1.],
37
37
[1., 1.]])))
38
- outputs: [tensor([[1., 1.],
39
- [1., 1.]])]
38
+ outputs: [tensor([[2., 2.],
39
+ [2., 2.]])]
40
+
41
+ Example usage with ETDump generation:
42
+
43
+ .. code-block:: python
44
+
45
+ from pathlib import Path
46
+ import os
47
+
48
+ import torch
49
+ from executorch.runtime import Verification, Runtime, Program, Method
50
+
51
+ # Create program with etdump generation enabled
52
+ et_runtime: Runtime = Runtime.get()
53
+ program: Program = et_runtime.load_program(
54
+ Path("/tmp/program.pte"),
55
+ verification=Verification.Minimal,
56
+ enable_etdump=True,
57
+ debug_buffer_size=1e7, # A large buffer size to ensure that all debug info is captured
58
+ )
59
+
60
+ # Load method and execute
61
+ forward: Method = program.load_method("forward")
62
+ inputs = (torch.ones(2, 2), torch.ones(2, 2))
63
+ outputs = forward.execute(inputs)
64
+
65
+ # Write etdump result to file
66
+ etdump_file = "/tmp/etdump_output.etdp"
67
+ debug_file = "/tmp/debug_output.bin"
68
+ program.write_etdump_result_to_file(etdump_file, debug_file)
69
+
70
+ # Check that files were created
71
+ print(f"ETDump file created: {os.path.exists(etdump_file)}")
72
+ print(f"Debug file created: {os.path.exists(debug_file)}")
73
+ print("Directory contents:", os.listdir("/tmp"))
74
+
75
+ Example output:
76
+
77
+ .. code-block:: text
78
+
79
+ Program methods: {'forward'}
80
+ ETDump file created: True
81
+ Debug file created: True
82
+ Directory contents: ['program.pte', 'etdump_output.etdp', 'debug_output.bin']
40
83
"""
41
84
42
85
import functools
@@ -137,6 +180,17 @@ def metadata(self, method_name: str) -> MethodMeta:
137
180
"""
138
181
return self ._program .method_meta (method_name )
139
182
183
+ def write_etdump_result_to_file (
184
+ self , etdump_path : str , debug_buffer_path : str
185
+ ) -> None :
186
+ """Writes the etdump and debug result to a file.
187
+
188
+ Args:
189
+ etdump_path: The path to the etdump file.
190
+ debug_buffer_path: The path to the debug buffer file.
191
+ """
192
+ self ._program .write_etdump_result_to_file (etdump_path , debug_buffer_path )
193
+
140
194
141
195
class BackendRegistry :
142
196
"""The registry of backends that are available to the runtime."""
@@ -201,6 +255,8 @@ def load_program(
201
255
data : Union [bytes , bytearray , BinaryIO , Path , str ],
202
256
* ,
203
257
verification : Verification = Verification .InternalConsistency ,
258
+ enable_etdump : bool = False ,
259
+ debug_buffer_size : int = 0 ,
204
260
) -> Program :
205
261
"""Loads an ExecuTorch program from a PTE binary.
206
262
@@ -214,8 +270,8 @@ def load_program(
214
270
if isinstance (data , (Path , str )):
215
271
p = self ._legacy_module ._load_program (
216
272
str (data ),
217
- enable_etdump = False ,
218
- debug_buffer_size = 0 ,
273
+ enable_etdump = enable_etdump ,
274
+ debug_buffer_size = debug_buffer_size ,
219
275
program_verification = verification ,
220
276
)
221
277
return Program (p , data = None )
0 commit comments