Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Conversation

yanboliang
Copy link
Contributor

This is the 3/N issue found from #156.

Problem:

  • Failed test case: test_achaiah_pywick.py:RefineNet4Cascade
  • Error: RuntimeError: Given groups=1, weight of size [256, 256, 3, 3], expected input[4, 512, 2, 2] to have 256 channels, but got 512 channels instead

Minimal code to reproduce:

from typing import List
import torch
import torchdynamo
import numpy as np

def fn(input):
    y = 0
    for i, x in enumerate(input[2:], 1):
        y = y + x
    return y

def my_compiler(gm: torch.fx.GraphModule, example_inputs: List[torch.Tensor]):
    return gm.forward

with torchdynamo.optimize(my_compiler):
    print(fn([1, 2, 3]))

The correct output of the above code is: 3.
However, it print out 6 in the current main.

Root cause and solution:

  • If we print out the original bytecode and modified bytecode, we'll found BINARY_SUBSCR is missing. BINARY_SUBSCR is used to generate input[2:], so it outputs wrong result which is the sum of the whole list rather than the slice elements.
  • Then dig into PyCodegen.__call__ and found the error comes from source reconstruction. The ListVariable.source should be GetItemSource but is LocalSource now. This list was created at BaseListVariable.getitem_const by cloning, but don't pass in the correct source.

@yanboliang yanboliang merged commit 243222e into pytorch:main May 10, 2022
@yanboliang yanboliang deleted the slice branch May 10, 2022 01:13
jansel added a commit to jansel/torchdynamo that referenced this pull request May 12, 2022
yanboliang pushed a commit that referenced this pull request May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants