awslabs / awslabs/raf

[Bug] structural_equal always not equal

Open
#137 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
145
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Hello. In #123, when I was writing the unit test, I tried to use `structural_equal` to examine whether the generated IR matches the expected IR or not. Here is the IR I want to examine:

```python
def @main(%x: Tensor[(4, 4), float64], %y: Tensor[(4, 4), float64]) -> Tensor[(2, 4), float64] {
%0 = raf.op.add(%x, %y) /* ty=Tensor[(4, 4), float64] */;
%1 = raf.op.strided_slice(%0, [0, 0], [2, 4], [1, 1], str"end") /* ty=Tensor[(2, 4), float64] */;
%2 = raf.op.relu(%1) /* ty=Tensor[(2, 4), float64] */;
raf.op.relu(%2) /* ty=Tensor[(2, 4), float64] */
}
```

And the following code is to produce the expected IR:

```python
def expected():
x = extended_var("x", shape=(4, 4), dtype="float64")
y = extended_var("y", shape=(4, 4), dtype="float64")
v0 = Call(GetOp("raf.op.add"), [x, y])
v1 = raf.ir.op.strided_slice(v0, raf.ir.const([0, 0]), raf.ir.const([2, 4]), raf.ir.const([1, 1]), raf.ir.const("end"))
v2 = raf.ir.op.relu(v1)
v3 = raf.ir.op.relu(v2)
return tvm.IRModule.from_expr(relay.Function([x, y], v3))
```

Then even if I printed the generated IR and expected IR with `AsText`, `print str`, or `print repr`, and the outputs are exact same, `structural_equal` always returns false. I also compared the Graph Nodes one by one with `structural_equal`, and it still always returns false.

The full example is here: [https://github.com/Tonny-Gu/raf/blob/sharding-pr2-issue/tests/python/pass/test_pass_sharding.py](https://github.com/Tonny-Gu/raf/blob/sharding-pr2-issue/tests/python/pass/test_pass_sharding.py)

Contributor guide

Open the contributing guide

Research direction

The reproducible example is in tests/python/pass/test_pass_sharding.py; start by running that test and comparing the generated module with expected() using structural_equal. Trace the structural_equal calls on the IRModule and individual graph nodes, and consider the issue done when equivalent generated and expected IR return true.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.