Skip to content

Commit

Permalink
updated backend delegate doc for lifted params
Browse files Browse the repository at this point in the history
Summary: as above

Reviewed By: mergennachin

Differential Revision: D47927468

fbshipit-source-id: 50157b88585eaaec556ec4bdc46a670055a97087
  • Loading branch information
mcr229 authored and facebook-github-bot committed Jul 31, 2023
1 parent f354a96 commit e822e97
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/website/docs/tutorials/backend_delegate.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ def preprocess(
) -> bytes:
```

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.

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:

```python
def get_param_from_node(
node: torch.fx.Node, edge_program: ExportedProgram
) -> Optional[torch.nn.Parameter]:
"""
Returns the parameter associated with the given node in the edge program.
Returns None if the node is not a parameter within the edge_program
"""
if node.name in edge_program.graph_signature.inputs_to_parameters:
parameter_name = edge_program.graph_signature.inputs_to_parameters[node.name]
return edge_program.state_dict[parameter_name]

return None
```

**Runtime initialization and execution interface**

```cpp
// Following apis are defined in backend_registry.h
// runtime initialization
Expand Down

0 comments on commit e822e97

Please sign in to comment.