You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/01/18 07:04:05 UTC

[GitHub] [tvm] Cnly opened a new issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Cnly opened a new issue #9955:
URL: https://github.com/apache/tvm/issues/9955


   ### Expected behavior
   
   `topi.scatter` is implemented with `@hybrid.script` and its body has something that looks like
   
   ```py
   for i in range(data.shape[0]):
   ```
   
   which should not be a problem when a module using scatter is built.
   
   ### Actual behavior
   
   However, when `topi.scatter` gets interpreted by `te/hybrid/parser.py`, there'll be an error `'IntImm' object is not iterable` from this line
   
   https://github.com/apache/tvm/blob/211291fb9a59b5ca6aee6e83b7cd700f98463032/python/tvm/te/hybrid/parser.py#L379
   
   If I apply this patch, it seems to resolve the problem:
   
   ```diff
   ```
   
   ### Environment
   
   OS: Ubuntu 18.04.6 LTS
   TVM: Commit 211291fb9
   
   ### Steps to reproduce
   
   ```py
   import numpy as np
   import tvm
   import tvm.relay as relay
   
   idxes = np.array([[0, 1],
                     [2, 3],
                     [4, 5]])
   
   x = relay.zeros((3, 10), 'int32')
   y = relay.var("y", shape=idxes.shape, dtype='int32')
   z = relay.scatter(x, y, relay.full_like(y, relay.const(1)), -1)
   
   f = relay.Function([y], z)
   m = tvm.IRModule.from_expr(f)
   
   lib = relay.build(m, target='llvm')
   
   intrp = relay.create_executor('graph', mod=m)
   print(intrp.evaluate()(idxes))
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015407263


   Yeah sorry I was confused with something. I don't know what `args = 0` corresponds to in your scatter op workload.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Cnly commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Cnly commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015518259


   I guess this only affects operators implemented with `@hybrid.script`? A quick grep shows not much usage in tvm. To see if I'm using the scatter operator wrong and to confirm my guess, I tried with `relay.unique` and saw the same exception. Reproduction snippet:
   
   ```py
   import numpy as np
   import tvm
   import tvm.relay as relay
   
   idxes = np.array([[0, 1],
                     [2, 3],
                     [4, 5]])
   
   x = relay.zeros((3, 10), 'int32')
   y = relay.var("y", shape=idxes.shape, dtype='int32')
   z = relay.unique(relay.sum(x, axis=0))[0]
   
   f = relay.Function([], z)
   m = tvm.IRModule.from_expr(f)
   
   # Either line triggers the error:
   relay.build(m, target='llvm')
   relay.create_executor('graph', mod=m).evaluate()()
   ```
   
   The line pointed to by traceback:
   
   https://github.com/apache/tvm/blob/31de5bc40f22ba761361464921b9b73af51bb214/python/tvm/topi/unique.py#L273


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1019067327


   What's your Python version? Hybrid Script is not supported by Python3.9+ (only from my experience)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Cnly commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Cnly commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1019403686


   I see, thanks! Any suggestion on what to do about this issue? Should we close it? Or rename it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1019405112


   There is already an issue for 3.9 https://github.com/apache/tvm/issues/8577, we can close this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi edited a comment on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015254786


   Doesn't this mean that the rhs of the slice assignment `arr` is an array but the lhs is a scalar? I'm assuming `node.slice` is the lhs of assignment, but it may be the index of subscripting.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi edited a comment on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015254786


   Doesn't this mean that the rhs of the slice assignment `arr` is an array but the lhs is a scalar? I'm assuming `node.slice` is the lhs of assignment, but it may be the index of slice.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi closed issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi closed issue #9955:
URL: https://github.com/apache/tvm/issues/9955


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015459578


   I see, so does this mean the parser expects subscript index (named `args`) to be an array? It's a bit surprising that we didn't hit this error before, since I think scalar indexing like `shape[0]` is used all over the places.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Cnly commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Cnly commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015281089


   @masahi Sorry I don't think I follow you... but I tried adding `print` statements in `scatter()` and `visit_Subscript()` to see the arguments and here's what I get:
   
   ```
   scatter():
   data=Tensor(shape=[3, 10], op.name=placeholder)
   indices=Tensor(shape=[3, 2], op.name=placeholder)
   
   visit_Subscript():
   node=<ast.Subscript object at 0x7f17fea956a0>
   node.slice=<ast.Constant object at 0x7f17fea955e0>
   args=0
   node.value=<ast.Attribute object at 0x7f17fea95670>
   arr=[3, 10]
   ```
   
   Do you think this makes things clearer?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015786484


   hmm interesting... I believe `unique` op should be well tested so I don't know why it fails for that example. Can you send a PR with your proposed solution, along with test cases for `scatter` and `unique`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Hzfengsy commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Hzfengsy commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1019075274


   Hybrid Script is based on Python AST which may change between different Python versions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Cnly commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Cnly commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1019074056


   Oops, it's 3.9.9. Switching back to 3.6.9 did seem to fix the problem. Why is that?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Cnly commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
Cnly commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015411789


   I think it's from this line
   
   https://github.com/apache/tvm/blob/31de5bc40f22ba761361464921b9b73af51bb214/python/tvm/topi/scatter.py#L36
   
   If I changed the `0` to `99` then it prints `args=99` before the exception.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9955: [Bug] `'IntImm' object is not iterable` in hybrid.parser.visit_Subscript

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9955:
URL: https://github.com/apache/tvm/issues/9955#issuecomment-1015254786


   Doesn't this mean that the rhs of the slice assignment `arr` is an array but the lhs is a scalar?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org