How to get around `'Proxy' object does not support item assignment`

Here’s the line that triggers this error during torch.quantization.quantize_fx.prepare_fx

patch_embed[:, 1:] = patch_embed[:, 1:] + self.proj(self.norm1_proj(pixel_embed).reshape(B, N - 1, -1))

Is there some way to get around this without having to avoid item assignment? Can I somehow inform that particular proxy instance that this should be okay?

You would likely want to lose the indexing on the left hand side (which makes the assignment necessarily in-place). How to do that depends on more context than shown here - as shown here, you might just keep the first column of patch_embed separately or so.

Best regards


1 Like

Thanks for your response!

Well, I kind of feel like I got away with a crime, but this didn’t throw the error:

patch_embed_rest = patch_embed[:, 1:]
patch_embed_rest += self.proj(self.norm1_proj(pixel_embed).reshape(B, N - 1, -1))

Cool! Likely this is similar to “when can I use inplace without autograd complaining”… :slight_smile:

:slight_smile: hope you don’t mind I marked my answer as the solution. Thanks again