# How to get graph weights in torch compile with custom backend?

**URL:** <https://dev-discuss.pytorch.org/t/how-to-get-graph-weights-in-torch-compile-with-custom-backend/3285>\
**Category:** FX\
**Created:** [January 12, 2026, 2:12am UTC](https://dev-discuss.pytorch.org/t/how-to-get-graph-weights-in-torch-compile-with-custom-backend/3285 "2026-01-12T02:12:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RunnerZhong](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/runnerzhong/32/3108_2.png) [@RunnerZhong](https://dev-discuss.pytorch.org/u/RunnerZhong)\
**Post date:** [January 12, 2026, 2:12am UTC](https://dev-discuss.pytorch.org/t/how-to-get-graph-weights-in-torch-compile-with-custom-backend/3285/1 "2026-01-12T02:12:33Z")

</div>

In custom backend fx graph, all weights or parameters are lifted to placeholder type. And how can I get the weights/parameters origin value in this FX graph ? I want to do something in custom backend during compile.

---

<div class="post-metadata">

**Author:** ![Lucaskabela](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/lucaskabela/32/3126_2.png) [@Lucaskabela](https://dev-discuss.pytorch.org/u/Lucaskabela)\
**Post date:** [January 27, 2026, 10:53pm UTC](https://dev-discuss.pytorch.org/t/how-to-get-graph-weights-in-torch-compile-with-custom-backend/3285/2 "2026-01-27T22:53:57Z")

</div>

Hi @RunnerZhong - would `target`/`name` attribute on the placeholder node be sufficient for this use case? Since the order matches `example_inputs` I imagine you could use those with some heuristic to identify naming - weights/parameters look something like `l_self_modules_linear_parameters_weight_`

```python
def my_custom_backend(gm: torch.fx.GraphModule, example_inputs: list[torch.Tensor], **kwargs):

    placeholders = [n for n in gm.graph.nodes if n.op == 'placeholder']
    for i, ph, inp in enumerate(zip(placeholders, example_inputs)):
        print(f"Placeholder {i}: {ph.name}, target={ph.target}")
        print(f"inp is: {inp}")

    return gm

```
