# Support for \_set with other mutations in graph

**URL:** <https://dev-discuss.pytorch.org/t/support-for-set-with-other-mutations-in-graph/2535>\
**Category:** compiler\
**Created:** [October 16, 2024, 12:27pm UTC](https://dev-discuss.pytorch.org/t/support-for-set-with-other-mutations-in-graph/2535 "2024-10-16T12:27:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdziado](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@mdziado](https://dev-discuss.pytorch.org/u/mdziado)\
**Post date:** [October 16, 2024, 12:27pm UTC](https://dev-discuss.pytorch.org/t/support-for-set-with-other-mutations-in-graph/2535/1 "2024-10-16T12:27:06Z")

</div>

Hi,  
Is there any plan to support \_set with other mutations in graph?

For below reproducer there’s:

```auto
AssertionError: Encountered a set_ on a graph input, but the input has other mutations that we cannot keep in the graph. This is not supported today. Current state:
  keep_input_mutations=True
  mutates_data=False
  mutates_metadata=True
  mutations_hidden_from_autograd=False
  mutations_under_no_grad_or_inference_mode=False
  mutation_inductor_storage_resize=False
  requires_grad=True

```

```auto
import torch
import torch.nn as nn

class SomeModule(nn.Module):
    def __init__ (self):
        super(). __init__ ()
        self.param = nn.Parameter(torch.randn(5, 5))

    def forward(self, x):
        r1 = torch.empty(self.param.shape, dtype=self.param.dtype, device=self.param.device)
        r1.copy_(x)
        self.param.data = r1.data

        return self.param

model = SomeModule()
compiled_model = torch.compile(model)

input_tensor = torch.randn(5,5)
output = compiled_model(input_tensor)

```

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [October 17, 2024, 1:57pm UTC](https://dev-discuss.pytorch.org/t/support-for-set-with-other-mutations-in-graph/2535/2 "2024-10-17T13:57:54Z")

</div>

Hey!

Why are you doing `self.param.data = r1.data`, I would expect you never use `.data =`.

If you just want to update the content of the param in a differentiable way, you can do `self.param.copy_(r1)`.And if you want to do it in a non-differentiable way, you can do the same thing (the .copy\_ above) after wrapping it into a `with torch.no_grad():` context.

---

<div class="post-metadata">

**Author:** ![mdziado](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@mdziado](https://dev-discuss.pytorch.org/u/mdziado)\
**Post date:** [October 18, 2024, 9:24am UTC](https://dev-discuss.pytorch.org/t/support-for-set-with-other-mutations-in-graph/2535/3 "2024-10-18T09:24:50Z")

</div>

Thanks for explanation.

That’s reduced part of deepsped code, I was interested if that somewhat somewhen would be possible to support with compile but now I get it, thanks.
