Skip to content

TensorImpl de-virtualization #22815

@yf225

Description

@yf225

Motivation

We want to de-virtualize TensorImpl methods as much as possible, to achieve performance gain for common Tensor methods such as numel() / sizes() / dim().

Concerns

XLA relies on TensorImpl methods such as numel() / sizes() / dim() being virtual, so that they can have their own implementation and calculate those values lazily when requested, rather than eagerly when a size change event happens.

Proposal

  1. To support XLA's use case, we should add virtual methods such as virtual_numel() / virtual_sizes() / virtual_dim() to OpaqueTensorImpl, and in TensorImpl we should add conditional branching in numel() / sizes() / dim() to call the opaque virtual methods when the TensorImpl is OpaqueTensorImpl. (We should run benchmarks such as JIT LSTM to make sure adding conditional branching and de-virtualizing numel() / sizes() / dim() doesn't cause perf regression for our CPU / CUDA use cases.)

  2. We should ask XLA to move their XLATensorImpl to OpaqueTensorImpl, and ask them to override the opaque methods for their lazy size computation.

  3. We should de-virtualize TensorImpl and all of its subclasses in PyTorch core library (example PR: Remove virtual keyword from most functions in TensorImpl #20909).

cc. @gchanan @colesbury @ailzhang

cc @ezyang @gchanan @zou3519 @jerryzh168

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: dependency bugProblem is not caused by us, but caused by an upstream library we usemodule: internalsRelated to internal abstractions in c10 and ATenquansight-nackHigh-prio issues that have been reviewed by Quansight and are judged to be not actionable.triagedThis 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