@@ -1495,16 +1495,29 @@ def CALL_FUNCTION_EX(self, inst):
1495
1495
null = self .pop ()
1496
1496
assert isinstance (null , NullVariable )
1497
1497
1498
- if (
1499
- isinstance (fn , GetAttrVariable )
1500
- and isinstance (fn .obj , TensorVariable )
1501
- and fn .name == "view"
1502
- and isinstance (argsvars , (ConstantVariable , TensorVariable ))
1503
- ):
1504
- # Hack to handle special case in some bert models. Converts
1505
- # x.view(*shape) into x.view(shape), which is correct for view()
1506
- # but not generally. See test_transpose_for_scores().
1507
- argsvars = TupleVariable ([argsvars ])
1498
+ if isinstance (fn , GetAttrVariable ) and isinstance (fn .obj , TensorVariable ):
1499
+ # realize is requires for Python 3.8
1500
+ kwargsvars = kwargsvars .realize ()
1501
+ if fn .name == "view" and isinstance (
1502
+ argsvars , (ConstantVariable , TensorVariable )
1503
+ ):
1504
+ # Hack to handle special case in some bert models. Converts
1505
+ # x.view(*shape) into x.view(shape), which is correct for view()
1506
+ # but not generally. See test_transpose_for_scores().
1507
+ argsvars = TupleVariable ([argsvars ])
1508
+ elif (
1509
+ fn .name == "random_"
1510
+ and isinstance (argsvars , TupleVariable )
1511
+ and len (argsvars .items ) == 0
1512
+ and isinstance (kwargsvars , ConstDictVariable )
1513
+ and ConstantVariable .create ("from" ) in kwargsvars
1514
+ ):
1515
+ # `from`` is python keyword. Adding random_ with `from` in the
1516
+ # Fx graph causes syntax error. Even if we convert the kwargs to
1517
+ # args, aot_autograd/inductor while lowering generates
1518
+ # aten.random.from, again causing syntax errors. Since this
1519
+ # usecase is uncommon, graph break.
1520
+ unimplemented ("random_ op is called with from keyword" )
1508
1521
1509
1522
if not isinstance (
1510
1523
argsvars , BaseListVariable
0 commit comments