mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Currently the ir parser doesn't support parse ir like
```
graph():
%12 : float = prim::Constant[value=-inf]()
%13 : float = prim::Constant[value=inf]()
%14 : bool = prim::Constant[value=True]()
%15 : bool = prim::Constant[value=False]()
return (%12)
```
So the python script below will throw error.
```
#!/bin/env python
import torch
def test():
return [True, False]
f = torch.jit.script(test)
torch._C._jit_pass_constant_propagation(f.graph)
ts_str = f.graph.__repr__()
print(ts_str)
ts = torch.parse_ir(ts_str)
func = torch._C._create_function_from_graph("forward", ts)
ret = func()
assert ret == [True, False]
def test():
return [float("inf"), float("-inf")]
f = torch.jit.script(test)
torch._C._jit_pass_constant_propagation(f.graph)
ts_str = f.graph.__repr__()
print(ts_str)
ts = torch.parse_ir(ts_str)
func = torch._C._create_function_from_graph("forward", ts)
ret = func()
assert ret == [float("inf"), float("-inf")]
```
I add "inf" and bool cases for IRParser::parseScalarLiteral in irparser.cpp.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/163924
Approved by: https://github.com/ezyang
|
||
|---|---|---|
| .. | ||
| alias_analysis.cpp | ||
| alias_analysis.h | ||
| attributes.cpp | ||
| attributes.h | ||
| constants.cpp | ||
| constants.h | ||
| graph_node_list.h | ||
| graph_utils.cpp | ||
| graph_utils.h | ||
| ir_views.h | ||
| ir.cpp | ||
| ir.h | ||
| irparser.cpp | ||
| irparser.h | ||
| named_value.h | ||
| node_hashing.cpp | ||
| node_hashing.h | ||
| scope.cpp | ||
| scope.h | ||
| subgraph_matcher.cpp | ||
| subgraph_matcher.h | ||
| type_hashing.cpp | ||
| type_hashing.h | ||