Skip to content

✨[Feature] Create Decorator for Python functions Incompatible with Legacy Torch Versions #1733

Closed
@gs-olive

Description

@gs-olive

Context

Some functions in the code base are incompatible with certain versions of Torch such as 1.13.1. Adding a general-purpose utility decorator which detects whether the Torch version is incompatible with certain key functions could be helpful in notifying the user when such mismatches occur.

Desired Solution

A decorator of the form:

@req_torch_version(2)
def f(...):

This decorator would throw a clear error when the detected Torch version differs from that required to use the decorated function.

Temporary Alternative

A temporary alternative, which is already in use in PR #1731, is to add logic to each function with compatibility issues, raising an error if any versioning issues are detected. While this is a functional solution, it is difficult to scale and can lead to repetitive code.

Additional Context

Certain imports are also not compatible across Torch versions (as in import torchdynamo in Torch 1.13 versus import torch._dynamo in 2.0). To resolve this issue, the imports can be moved inside the functions using them so as to encapsulate all version-specific code within one area.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions