Skip to content

Commit 472918a

Browse files
committed
debug
1 parent ae6c3c9 commit 472918a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

chapter_compiler_frontend/Intermediate_Representation.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,37 @@ PyTorch framework.
208208

209209
Code `lst:torchscript` illustrates the use of the Scripting method
210210
to print a TorchScript IR graph.
211+
212+
**lst:torchscript**
213+
```python
214+
import torch
215+
216+
@torch.jit.script
217+
def test_func(input):
218+
rv = 10.0
219+
for i in range(5):
220+
rv = rv + input
221+
rv = rv/2
222+
return rv
223+
224+
print(test_func.graph)
225+
```
226+
227+
Code `lst:torchscriptir` shows the structure of this IR graph.
228+
229+
**lst:torchscriptir**
230+
```
231+
graph(%input.1 : Tensor):
232+
%9 : int = prim::Constant[value=1]()
233+
%5 : bool = prim::Constant[value=1]() # test.py:6:1
234+
%rv.1 : float = prim::Constant[value=10.]() # test.py:5:6
235+
%2 : int = prim::Constant[value=5]() # test.py:6:16
236+
%14 : int = prim::Constant[value=2]() # test.py:8:10
237+
%rv : float = prim::Loop(%2, %5, %rv.1) # test.py:6:1
238+
block0(%i : int, %rv.9 : float):
239+
%rv.3 : Tensor = aten::add(%input.1, %rv.9, %9) # <string>:5:9
240+
%12 : float = aten::FloatImplicit(%rv.3) # test.py:7:2
241+
%rv.6 : float = aten::div(%12, %14) # test.py:8:7
242+
-> (%5, %rv.6)
243+
return (%rv)
244+
```

0 commit comments

Comments
 (0)