From 361bce60594eb49c06067dc1bfda473cfcf476c0 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Thu, 13 Jun 2024 11:44:20 -0700 Subject: [PATCH 1/2] Add torchao.__version__ --- torchao/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/torchao/__init__.py b/torchao/__init__.py index d3e1eecaf7..a43947e7e2 100644 --- a/torchao/__init__.py +++ b/torchao/__init__.py @@ -1,11 +1,20 @@ import torch import logging +# We use this "hack" to set torchao.__version__ correctly +# For local development this will default to whatever is version.txt +# For release builds this will be set the version+architecture_postfix +import pkg_resources +try: + __version__ = pkg_resources.get_distribution('torchao').version +except pkg_resources.DistributionNotFound: + __version__ = 'unknown' + + _IS_FBCODE = ( hasattr(torch._utils_internal, "IS_FBSOURCE") and torch._utils_internal.IS_FBSOURCE ) - if not _IS_FBCODE: try: from . import _C From d2ca1399303c095b26c46ccd934bfc39f90885d8 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Thu, 13 Jun 2024 12:08:13 -0700 Subject: [PATCH 2/2] push --- torchao/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/torchao/__init__.py b/torchao/__init__.py index a43947e7e2..81051dcc3d 100644 --- a/torchao/__init__.py +++ b/torchao/__init__.py @@ -2,14 +2,14 @@ import logging # We use this "hack" to set torchao.__version__ correctly +# the version of ao is dependent on environment variables for multiple architectures # For local development this will default to whatever is version.txt # For release builds this will be set the version+architecture_postfix -import pkg_resources +from importlib.metadata import version, PackageNotFoundError try: - __version__ = pkg_resources.get_distribution('torchao').version -except pkg_resources.DistributionNotFound: - __version__ = 'unknown' - + __version__ = version("torchao") +except PackageNotFoundError: + __version__ = 'unknown' # In case this logic breaks don't break the build _IS_FBCODE = ( hasattr(torch._utils_internal, "IS_FBSOURCE") and