Skip to content

Plan for Migrating ATen ops to the c10 dispatcher #24132

@smessmer

Description

@smessmer

We currently have two separate dispatchers for ATen.

  • globalATenDispatch which replaced the vtable dispatch mechanism and is used for ops in native_functions.yaml
  • the c10 dispatcher which is used for custom ops and caffe2 ops that are exported to PyTorch.

The c10 dispatcher was designed to be "one dispatcher to rule them all", and we are now planning to cash in on that promise and remove globalATenDispatch.

Overview: native_functions.yaml codegen will generate operator registrations for the c10 dispatcher instead of for globalATenDispatch. While ultimately, we are considering switching these operators to be called in a boxed fashion, that is not part of this plan yet. For now, the c10 dispatcher will have two types of operators - boxed ones and unboxed ones - and store them separately. This simplifies the migration and allows us to tackle the boxing issue separately.

Steps:

Additional concern: Registering ops with JIT
The c10 dispatcher registers its operators with JIT in register_c10_ops.cpp and there is a codegen'ed register_aten_ops.cpp for registering ATen ops with JIT. Once an ATen operator is added to c10, it would be registered twice. We plan to

  • at first, we're going to codegen a global std::unordered_set with the names of the ATen operators that are added to c10, and use this set as a blacklist for c10 ops that are exported to JIT. ATen operators, even when on c10, will use the register_aten_ops.cpp mechanism (Register ATen ops with c10 #23667)
  • later, we're planning to change that so that register_aten_ops.cpp ignores these ops and they use the generic non-codegen code from register_c10_ops.cpp instead ([wip] Remove manual boxing wrappers #26865)

Additional concern: Extension backends
Extension backends use globalATenDispatch to overwrite ops and it would be very bad UX to ask them to use globalATenDispatch for some ops but the c10 torch::RegisterOperators for others, and have that list constantly change as we move ops to c10. We will, instead,

  • change torch::RegisterOperators registration in a way that forwards registration to globalATenDispatch for the ops that don't have use_c10: True, using the same global std::unordered_set mentioned above. (Call aten ops through c10 dispatcher #23668)
  • migrate all extension backends to use torch::RegisterOperators instead of globalATenDispatch. After this, we can start moving ops to c10 without breaking backend extensions.

Additional concern: Benchmarks
Benchmarks show no relevant regression, see here: https://docs.google.com/document/d/1gpzKZcFf1JJameY1vKxF7Cloul9s6D8HKIK2_Pp1hFo/edit?usp=sharing

Out of scope: Boxing
This will get us to a world where we have only one dispatcher, but the dispatcher has two kinds of operators: boxed and unboxed. We need to auto-generate wrappers in both directions so that boxed/unboxed kernels can be called using the unboxed/boxed API as well. This is, however, out of scope for this plan.

Out of scope: Getting rid of Codegen
While this plan will get rid of some codegen (namely register_aten_ops.cpp), most things codegen'ed today will still be codegen'ed after this. We're just planning to change the codegen'ed registrations to register the functions with a different dispatcher. Getting rid of codegen is out of scope and will potentially be tackled later on.

Out of scope: Redesigning autograd
There are some ideas on how autograd could be done better, for example the generic dispatch proposal currently in flow. This is orthogonal and out of scope for this plan. In this plan, we will handle autograd exactly as globalATenDispatch does it, i.e. each op can store one autograd kernel that will be called if is_variable() == True, just move that functionality to the c10 dispatcher.

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: internalsRelated to internal abstractions in c10 and ATentriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions