pytorch / pytorch

Tensors and Dynamic neural networks in Python with strong GPU acceleration
https://pytorch.org
Other
81.98k stars 21.99k forks source link

AttributeError: module 'z3' has no attribute 'ExprRef' #123022

Closed jikechao closed 1 month ago

jikechao commented 5 months ago

πŸ› Describe the bug

The following script will crash and throw "AttributeError: module 'z3' has no attribute 'ExprRef'".

import torch

def f(x):
    return (x.relu() + 1) * x.pow(5)

def custom_backend(gm, example_inputs):
    print(gm.compile_subgraph_reason)
    print(gm.graph)
    print(gm.code)
    return gm.forward

input = torch.randn(5, 5, 5)
opt_f = torch.compile(f, backend=custom_backend)
output = opt_f(input)  # crash here

Full Traceback

Traceback (most recent call last):
  File "D:/code/python/HelloTest/bugs/test1.py", line 16, in <module>
    output = opt_f(input)  # crash here
  File "C:\software\conda\lib\site-packages\torch\_dynamo\eval_frame.py", line 489, in _fn
    return fn(*args, **kwargs)
  File "C:\software\conda\lib\site-packages\torch\_dynamo\eval_frame.py", line 655, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state)
  File "C:\software\conda\lib\site-packages\torch\_dynamo\convert_frame.py", line 727, in _convert_frame
    result = inner_convert(frame, cache_entry, hooks, frame_state)
  File "C:\software\conda\lib\site-packages\torch\_dynamo\convert_frame.py", line 383, in _convert_frame_assert
    compiled_product = _compile(
  File "C:\software\conda\lib\site-packages\torch\_dynamo\convert_frame.py", line 492, in _compile
    from torch.fx.experimental.validator import (
  File "C:\software\conda\lib\site-packages\torch\fx\experimental\validator.py", line 58, in <module>
    def z3str(e: z3.ExprRef) -> str:
AttributeError: module 'z3' has no attribute 'ExprRef'

Versions

PyTorch version: 2.2.2+cpu Is debug build: False CUDA used to build PyTorch: Could not collect ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 δΌδΈšη‰ˆ GCC version: (tdm64-1) 4.9.2 Clang version: Could not collect CMake version: Could not collect Libc version: N/A

Python version: 3.8.3 (default, May 19 2020, 06:50:17) [MSC v.1916 64 bit (AMD64)] (64-bit runtime) Python platform: Windows-10-10.0.19041-SP0 Is CUDA available: False CUDA runtime version: 10.0.130 CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1660 Ti Nvidia driver version: 537.70 cuDNN version: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\cudnn_ops_train64_8.dll HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU:

Revision=

Versions of relevant libraries: [pip3] numpy==1.24.3 [pip3] torch==2.2.2 [pip3] torch-struct==0.5 [pip3] torchvision==0.11.1 [conda] numpy 1.24.3 pypi_0 pypi [conda] torch 2.2.2 pypi_0 pypi [conda] torch-struct 0.5 pypi_0 pypi [conda] torchvision 0.11.1 pypi_0 pypi

Process finished with exit code 0

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm @vladimir-aubrecht @iremyux @Blackhex @cristianPanaite @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang

tringwald commented 5 months ago

Thank you for your bug report. Unfortunately, I can't reproduce this with the given code. A similar discussion here points to a local setup problem. Can you try again in a clean environment?

jikechao commented 5 months ago

@tringwald Thanks for the suggestion. I had figured out this issue.

The crash was caused by the environment package z3, After uninstalling the package z3, the above script can run well.

jikechao commented 5 months ago

@tringwald. I am curious about how you handle the conflict package issue in common. 1) Solve it in the PyTorch when installing the PyTorch package? 2)Giving a warning information in the crash message? 3)Or do nothing?

malfet commented 5 months ago

torch.compile is still not supported on Windows, so removing needs reproduction

But imo we should have a test for z3 version when it's used, and if an incompatible version is installed we should print a warning of sorts

alinpahontu2912 commented 1 month ago

Hey @jikechao, @aliencaocao, currently torch.compile is not supported on Windows. You can stay updated by following this thread. Would it be alright to close this issue for now?

jikechao commented 1 month ago

Hey @jikechao, @aliencaocao, currently torch.compile is not supported on Windows. You can stay updated by following this thread. Would it be alright to close this issue for now?

@alinpahontu2912 Thanks for your investigation and explanation.