@@ -2249,33 +2249,29 @@ def topk(g, self, k, dim, largest, sorted, out=None):
22492249
22502250def to (g , self , * args ):
22512251
2252- def is_aten_to_device_only (* args ):
2252+ def is_aten_to_device_only (args ):
22532253 if len (args ) == 4 :
22542254 # aten::to(Tensor, Device, bool, bool, memory_format)
2255- if args [0 ].node ().kind () == "prim::device" or \
2256- args [0 ].type ().isSubtypeOf (ListType .ofInts ()):
2257- return True
2258- if sym_help ._is_value (args [0 ]) and \
2259- args [0 ].node ().kind () == "onnx::Constant" and \
2260- isinstance (args [0 ].node ()["value" ], str ):
2261- return True
2255+ return args [0 ].node ().kind () == "prim::device" or \
2256+ args [0 ].type ().isSubtypeOf (ListType .ofInts ()) or \
2257+ (sym_help ._is_value (args [0 ]) and
2258+ args [0 ].node ().kind () == "onnx::Constant" and
2259+ isinstance (args [0 ].node ()["value" ], str ))
22622260 elif len (args ) == 5 :
22632261 # aten::to(Tensor, Device, ScalarType, bool, bool, memory_format)
2262+ # When dtype is None, this is a aten::to(device) call
22642263 dtype = sym_help ._get_const (args [1 ], "i" , "dtype" )
2265- if not dtype :
2266- # When dtype is None, this is a aten::to(device) call
2267- return True
2268- elif len (args ) >= 6 and len (args ) <= 7 :
2264+ return dtype is None
2265+ elif len (args ) in (6 , 7 ):
22692266 # aten::to(Tensor, ScalarType, Layout, Device, bool, bool, memory_format) -> Tensor
22702267 # aten::to(Tensor, ScalarType, Layout, Device, bool, bool, bool, memory_format) -> Tensor
2268+ # When dtype is None, this is a aten::to(device) call
22712269 dtype = sym_help ._get_const (args [0 ], "i" , "dtype" )
2272- if not dtype :
2273- # When dtype is None, this is a aten::to(device) call
2274- return True
2270+ return dtype is None
22752271 return False
22762272
22772273 # ONNX doesn't have a concept of a device, so we ignore device-only casts
2278- if is_aten_to_device_only (* args ):
2274+ if is_aten_to_device_only (args ):
22792275 return self
22802276
22812277 if len (args ) == 4 :
0 commit comments