From 884109473b3dfa182922295645792f78b44295a4 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Thu, 13 Jun 2024 13:41:15 -0700 Subject: [PATCH] Add torchao.__version__ (#359) * Add torchao.__version__ * push --- torchao/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/torchao/__init__.py b/torchao/__init__.py index d3e1eecaf..81051dcc3 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 +# 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 +from importlib.metadata import version, PackageNotFoundError +try: + __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 torch._utils_internal.IS_FBSOURCE ) - if not _IS_FBCODE: try: from . import _C