pytorch
33998763 - [PyTorch] Avoid schema parsing in lightweight dispatch (#74069)

Commit
2 years ago
[PyTorch] Avoid schema parsing in lightweight dispatch (#74069) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/74069 RFC: pytorch/rfcs#40 In #69881 we added the ability to generate codegen unboxing source files. Notice that the generated code to register an operator looks like this: ``` // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor OperatorGenerator( TORCH_SELECTIVE_SCHEMA("aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor"), [](Stack & stack) { RECORD_FUNCTION("add", std::vector<c10::IValue>()); at::unboxing::add_Tensor(stack); }, aliasAnalysisFromSchema() ), ``` However, this means we have to parse the schema and get back arguments with default values in static init time. As written in the RFC, there's a more performant option: providing these arguments with default values using codegen, then we don't have to do expensive regex pattern matching in parsing. Here's how it looks like: ``` // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor OperatorGenerator( "aten::add", "Tensor", { c10::Argument("self", nullptr, c10::nullopt, c10::IValue(c10::nullopt)), c10::Argument("other", nullptr, c10::nullopt, c10::IValue(c10::nullopt)), c10::Argument("alpha", nullptr, c10::nullopt, c10::IValue(1)) }, { c10::Argument("") }, [](Stack & stack) { RECORD_FUNCTION("add", std::vector<c10::IValue>()); at::unboxing::add_Tensor(stack); }, aliasAnalysisFromSchema() ), ``` We also added corresponding APIs in `operator.h` to take in the arguments. Test Plan: Rely on CI Reviewed By: kimishpatel Differential Revision: D33077733 fbshipit-source-id: e7f13a2f162c70d4e506b4f64cdbb7afec39f4e6 (cherry picked from commit 08a076935f480d5ab11c75e78d8627a8e2ba7d1a)
Author
Committer
Parents
Loading