Skip to content

Commit e822e97

Browse files
mcr229facebook-github-bot
authored andcommitted
updated backend delegate doc for lifted params
Summary: as above Reviewed By: mergennachin Differential Revision: D47927468 fbshipit-source-id: 50157b88585eaaec556ec4bdc46a670055a97087
1 parent f354a96 commit e822e97

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/website/docs/tutorials/backend_delegate.md

+21
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ def preprocess(
2626
) -> bytes:
2727
```
2828

29+
The demo preprocess is implemented here: executorch/backends/tests/backend_with_compiler_demo.py. The demo loops through the nodes in the graph module of the `edge_program` and serializes the add, mul, and sin instructions into a string, which is later parsed and executed at runtime.
30+
31+
The graph module being preprocessed is a lifted graph, this means that static data like weights and biases are supplied as inputs to the graph. However, we can access the weights and biases ahead-of-time through the exported program. An example of accessing these parameters from a given node looks like this:
32+
33+
```python
34+
def get_param_from_node(
35+
node: torch.fx.Node, edge_program: ExportedProgram
36+
) -> Optional[torch.nn.Parameter]:
37+
"""
38+
Returns the parameter associated with the given node in the edge program.
39+
Returns None if the node is not a parameter within the edge_program
40+
"""
41+
if node.name in edge_program.graph_signature.inputs_to_parameters:
42+
parameter_name = edge_program.graph_signature.inputs_to_parameters[node.name]
43+
return edge_program.state_dict[parameter_name]
44+
45+
return None
46+
```
47+
48+
**Runtime initialization and execution interface**
49+
2950
```cpp
3051
// Following apis are defined in backend_registry.h
3152
// runtime initialization

0 commit comments

Comments
 (0)