-
Notifications
You must be signed in to change notification settings - Fork 24.9k
[BE] detect CXX pytree requirement with TorchVersion
#151102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/151102
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 9f93511 with merge base 9e50c21 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ghstack-source-id: 586d3ba Pull Request resolved: pytorch#151102
sorry please dont' land this yet it might merge conflict with #151257 |
@@ -170,16 +172,16 @@ class _SerializeNodeDef(NamedTuple): | |||
# NB: we try really hard to not import _cxx_pytree (which depends on optree) | |||
# as much as possible. This is for isolation: a user who is not using C++ pytree | |||
# shouldn't pay for it, and it helps makes things like cpython upgrades easier. | |||
_optree_minimum_version = _TorchVersion("0.13.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB: TorchVersion
is a subclass of str
while the rich comparison is semantic version comparison rather than alphabetic dictionary order.
ghstack-source-id: 2d246a3 Pull Request resolved: pytorch#151102
ghstack-source-id: b334675 Pull Request resolved: pytorch#151102
ghstack-source-id: 7bb2cd3 Pull Request resolved: pytorch#151102
# In-tree installation may have VCS-based versioning. Update the previous static version. | ||
python_pytree._optree_version = _TorchVersion(optree.__version__) # type: ignore[attr-defined] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned this elsewhere but from the naming it sounds like _TorchVersion
is for torch versions, not for third-party library versions. Should we do something about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it sounds like
_TorchVersion
is for torch versions, not for third-party library versions
No. TorchVersion
is widely used in the codebase for version comparison, such as CUDA/ROCm version, and triton
version.
Lines 2305 to 2309 in 3719997
cuda_version = None | |
if hasattr(torch, "version"): | |
from torch.torch_version import TorchVersion | |
cuda_version = TorchVersion(getattr(torch.version, "cuda", "0.0")) |
pytorch/tools/dynamo/verify_dynamo.py
Lines 33 to 53 in 3719997
# based on torch/utils/cpp_extension.py | |
def get_cuda_version(): | |
from torch.torch_version import TorchVersion | |
from torch.utils import cpp_extension | |
CUDA_HOME = cpp_extension._find_cuda_home() | |
if not CUDA_HOME: | |
raise VerifyDynamoError(cpp_extension.CUDA_NOT_FOUND_MESSAGE) | |
nvcc = os.path.join(CUDA_HOME, "bin", "nvcc") | |
cuda_version_str = ( | |
subprocess.check_output([nvcc, "--version"]) | |
.strip() | |
.decode(*cpp_extension.SUBPROCESS_DECODE_ARGS) | |
) | |
cuda_version = re.search(r"release (\d+[.]\d+)", cuda_version_str) | |
if cuda_version is None: | |
raise VerifyDynamoError("CUDA version not found in `nvcc --version` output") | |
cuda_str_version = cuda_version.group(1) | |
return TorchVersion(cuda_str_version) |
pytorch/tools/dynamo/verify_dynamo.py
Lines 56 to 79 in 3719997
def get_rocm_version(): | |
from torch.torch_version import TorchVersion | |
from torch.utils import cpp_extension | |
ROCM_HOME = cpp_extension._find_rocm_home() | |
if not ROCM_HOME: | |
raise VerifyDynamoError( | |
"ROCM was not found on the system, please set ROCM_HOME environment variable" | |
) | |
hipcc = os.path.join(ROCM_HOME, "bin", "hipcc") | |
hip_version_str = ( | |
subprocess.check_output([hipcc, "--version"]) | |
.strip() | |
.decode(*cpp_extension.SUBPROCESS_DECODE_ARGS) | |
) | |
hip_version = re.search(r"HIP version: (\d+[.]\d+)", hip_version_str) | |
if hip_version is None: | |
raise VerifyDynamoError("HIP version not found in `hipcc --version` output") | |
hip_str_version = hip_version.group(1) | |
return TorchVersion(hip_str_version) |
pytorch/torch/_inductor/kernel/mm.py
Lines 61 to 68 in 3719997
try: | |
import triton | |
triton_version = TorchVersion(triton.__version__) | |
has_triton = True | |
except ImportError: | |
triton_version = TorchVersion("0.0.0") | |
has_triton = False |
pytorch/torch/_inductor/cpp_builder.py
Lines 208 to 217 in 3719997
def _is_intel_compiler(cpp_compiler: str) -> bool: | |
def _check_minimal_version(compiler_version: TorchVersion) -> None: | |
""" | |
On Windows: early version icx has `-print-file-name` issue, and can't preload correctly for inductor. | |
""" | |
min_version = "2024.2.1" if _IS_WINDOWS else "0.0.0" | |
if compiler_version < TorchVersion(min_version): | |
raise RuntimeError( | |
f"Intel Compiler error: less than minimal version {min_version}." | |
) |
Also, torch.torch_version.TorchVersion
is an exported API:
pytorch/torch/torch_version.py
Line 8 in 3719997
__all__ = ["TorchVersion"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, thanks for pointing that out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thank you
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
ghstack-source-id: 7bb2cd3 Pull Request resolved: pytorch#151102
Stack from ghstack (oldest at bottom):
__module__
#148328torch.pytree
#148180torch.utils.pytree
#137400tree_*
functions accept both Python and C++PyTreeSpec
#152624TorchVersion
#151102