masahi edited a comment on issue #4964: [Torch] Add initial control flow support URL: https://github.com/apache/incubator-tvm/pull/4964#issuecomment-592798088 Tests passed!! > can you dont call it parse? parse is for converting strings to an ast. converting ast to ast is a converter. no probelm, will do. @alexwong @zhiics a good way to get familiar with torch script is to try and tweak simple examples. For example, ```Python import torch class SimpleLoop(torch.nn.Module): def forward(self, inp): a = inp for i in range(10): a += i return a class SimpleWhileLoop(torch.nn.Module): def forward(self, inp): a = inp i = 0 while i < 10: a += i i += 1 return a print(torch.jit.script(SimpleLoop()).graph) print(torch.jit.script(SimpleWhileLoop()).graph) ``` would print ``` graph(%self : __torch__.SimpleLoop, %inp.1 : Tensor): %10 : int = prim::Constant[value=1]() %6 : bool = prim::Constant[value=1]() # test.py:7:8 %3 : int = prim::Constant[value=10]() # test.py:7:23 %a : Tensor = prim::Loop(%3, %6, %inp.1) # test.py:7:8 block0(%i.1 : int, %a.5 : Tensor): %a.2 : Tensor = aten::add_(%a.5, %i.1, %10) # test.py:8:12 -> (%6, %a.2) return (%a) graph(%self : __torch__.SimpleWhileLoop, %inp.1 : Tensor): %i.1 : int = prim::Constant[value=0]() # test.py:15:12 %4 : int = prim::Constant[value=9223372036854775807]() # test.py:16:8 %6 : int = prim::Constant[value=10]() # test.py:16:18 %16 : int = prim::Constant[value=1]() # test.py:18:17 %39 : bool = prim::Constant[value=1]() %a : Tensor, %i : int = prim::Loop(%4, %39, %inp.1, %i.1) # test.py:16:8 block0(%8 : int, %a.5 : Tensor, %i.8 : int): %a.2 : Tensor = aten::add_(%a.5, %i.8, %16) # test.py:17:12 %i.6 : int = aten::add(%i.8, %16) # test.py:18:12 %7 : bool = aten::lt(%i.6, %6) # test.py:16:14 -> (%7, %a.2, %i.6) return (%a) ``` hopefully it is much simpler than tensorflow control flow.
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services