MCPcopy Create free account
hub / github.com/pytorch/executorch / __torch_function__

Method __torch_function__

exir/tracer.py:264–291  ·  view source on GitHub ↗
(
        cls,
        # pyre-ignore: Missing parameter annotation [2]
        func,
        # pyre-ignore: Missing parameter annotation [2]
        types,
        args: Tuple[Value, ...] = (),
        kwargs: Optional[Dict[str, Value]] = None,
    )

Source from the content-addressed store, hash-verified

262
263 @classmethod
264 def __torch_function__(
265 cls,
266 # pyre-ignore: Missing parameter annotation [2]
267 func,
268 # pyre-ignore: Missing parameter annotation [2]
269 types,
270 args: Tuple[Value, ...] = (),
271 kwargs: Optional[Dict[str, Value]] = None,
272 ) -> Value:
273 if kwargs is None:
274 kwargs = {}
275 if torch.is_inference_mode_enabled():
276 if func is torch.nn.functional.layer_norm:
277 args, kwargs = normalize_function(func, args, kwargs) # pyre-fixme[23]
278 input, normalized_shape = args
279 normalized_shape = list(normalized_shape)
280 return cls.__torch_dispatch__(
281 torch.ops.aten.layer_norm.default,
282 types,
283 (input, normalized_shape),
284 kwargs,
285 )
286 elif func is torch.nn.functional.linear:
287 return cls.__torch_dispatch__(
288 torch.ops.aten.linear.default, types, args, kwargs
289 )
290 with DisableTorchFunctionSubclass():
291 return func(*args, **kwargs)
292
293 @classmethod
294 def __torch_dispatch__( # noqa: C901

Callers

nothing calls this directly

Calls 1

__torch_dispatch__Method · 0.45

Tested by

no test coverage detected