Skip to content

Let backends specify a schema version when registering kernels #54546

@bdhirsh

Description

@bdhirsh

Right now, any time we make a change to the schema of an operator, we have to add a corresponding patch to the kernel registration logic in any external backends, e.g. XLA. This causes a temporary window when master is broken for the external backend, when we've merged our change in pytorch core but the corresponding patch hasn't merged yet.

See #53583 for an example, which code mods Scalar to const Scalar& in every op signature, and required corresponding changes in XLA.

To avoid breaking external backends during these changes, we could version our API's. The required changes would look something like:

  • maintain a notion of versions (we could use a counter, or just new/old if we want to enforce no more than 2 versions)
  • Somewhere in the codegen (probably translate.py), add branching logic to determine if we should generate schema according to the new version or the old version
  • In PyTorch core, always codegen dispatcher registrations for the newest version
  • In external backends, explicitly pass in information to tell the dispatcher which version of the API to use. This would incur a small runtime cost: we would probably need something like a hacky_wrapper to do the translation from whatever version to the "latest" version that the dispatcher expects.

This will also be easier to do when/if we end up using codegen to register external backend kernels.

cc @ezyang @bhosmer @smessmer @ljk53 @bdhirsh @ailzhang

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: backendnon-standard backend supportmodule: codegenIssues related to the codegen for Aten and Autogradmodule: 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