Skip to content
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

[Bug]: NameError: name 'exit' is not defined #567

Closed
saforem2 opened this issue Mar 25, 2024 · 6 comments
Closed

[Bug]: NameError: name 'exit' is not defined #567

saforem2 opened this issue Mar 25, 2024 · 6 comments
Assignees
Labels
Bug Something isn't working CPU CPU specific issues

Comments

@saforem2
Copy link

Issue coming from:

Trying:

>>> from intel_extension_for_transformers.transformers import ViTImageProcessor
>>> processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
/lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/saforem2/stormer-dev/venvs/sunspot/q4-drop/lib/python3.9/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: ''If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
  warn(
ERROR! Intel® Extension for PyTorch* needs to work with PyTorch 2.4.*, but PyTorch 2.1.0a0+cxx11.abi is found. Pleaseswitch to the matching version and run again.

# ... see Full Traceback below ...
File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/intel/ipex/intel_extension_for_pytorch/__init__.py:36
     30 if torch_version == "" or ipex_version == "" or torch_version != ipex_version:
     31     print(
     32         "ERROR! Intel® Extension for PyTorch* needs to work with PyTorch "
     33         + f"{ipex_version}.*, but PyTorch {torch.__version__} is found. "
     34         + "Please switch to the matching version and run again."
     35     )
---> 36     exit(127)
     39 import os
     40 import sys

NameError: name 'exit' is not defined

Proposed fix:

if torch_version == "" or ipex_version == "" or torch_version != ipex_version:
    print(                                                                           
        "ERROR! Intel® Extension for PyTorch* needs to work with PyTorch "           
        + f"{ipex_version}.*, but PyTorch {torch.__version__} is found. "            
        + "Please switch to the matching version and run again."                     
    )
    import sys                                                                    
    sys.exit(127)
Full Traceback
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[1], line 1
----> 1 from intel_extension_for_transformers.transformers import ViTImageProcessor
      2 processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")

File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/saforem2/stormer-dev/venvs/sunspot/q4-drop/lib/python3.9/site-packages/intel_extension_for_transformers/transformers/__init__.py:56
     43 from .utils import (
     44     MixedPrecisionConfig,
     45     BitsAndBytesConfig,
   (...)
     53     objectives,
     54 )
     55 from .utils.utility import LazyImport
---> 56 from .modeling import (
     57     AutoModelForCausalLM,
     58     AutoModel,
     59     AutoModelForSeq2SeqLM,
     60     OptimizedModel
     61 )

File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/saforem2/stormer-dev/venvs/sunspot/q4-drop/lib/python3.9/site-packages/intel_extension_for_transformers/transformers/modeling/__init__.py:22
     18 """Modeling class."""
     21 from .model import OptimizedModel
---> 22 from .modeling_auto import (AutoModel, AutoModelForCausalLM,
     23                             AutoModelForSeq2SeqLM)

File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/saforem2/stormer-dev/venvs/sunspot/q4-drop/lib/python3.9/site-packages/intel_extension_for_transformers/transformers/modeling/modeling_auto.py:64
     41 from ..utils import (
     42     BitsAndBytesConfig,
     43     MixedPrecisionConfig,
   (...)
     51     LazyImport,
     52 )
     53 from ..utils.utility import (
     54     generate_dummy_past_key_values,
     55     generate_dummy_past_key_values_for_opt_llm,
   (...)
     62     SAFE_WEIGHTS_INDEX_NAME,
     63 )
---> 64 from ..llm.quantization.utils import (
     65     convert_dtype_str2torch,
     66     convert_dtype_torch2str,
     67     convert_to_quantized_model,
     68     replace_linear,
     69 )
     70 from ...tools.utils import get_gpu_family, is_ipex_available
     71 from neural_compressor.adaptor.torch_utils.model_wrapper import WeightOnlyLinear

File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/saforem2/stormer-dev/venvs/sunspot/q4-drop/lib/python3.9/site-packages/intel_extension_for_transformers/transformers/llm/quantization/utils.py:36
     33 from transformers import AutoTokenizer
     35 if is_ipex_available():
---> 36     import intel_extension_for_pytorch as ipex
     38 if is_autoround_available():
     39     from auto_round.export.export_to_itrex.model_wrapper import WeightOnlyLinear as auto_round_woqlinear # pylint: disable=E0401

File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/intel/ipex/intel_extension_for_pytorch/__init__.py:36
     30 if torch_version == "" or ipex_version == "" or torch_version != ipex_version:
     31     print(
     32         "ERROR! Intel® Extension for PyTorch* needs to work with PyTorch "
     33         + f"{ipex_version}.*, but PyTorch {torch.__version__} is found. "
     34         + "Please switch to the matching version and run again."
     35     )
---> 36     exit(127)
     39 import os
     40 import sys

NameError: name 'exit' is not defined
@hueyline
Copy link

Hi @saforem2, could you please provide the environment information using the following commands?

wget https://raw.githubusercontent.com/intel/intel-extension-for-pytorch/master/scripts/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

@ZhaoqiongZ ZhaoqiongZ added Bug Something isn't working CPU CPU specific issues labels Apr 24, 2024
@xiguiw
Copy link
Contributor

xiguiw commented May 20, 2024

@saforem2

Thank you for trying IPEX and pointed out this error.
Let me check if this is fixed or not.

BTW:
It looks Intel-extension-for-PyTorch version and PyTroch version mismatched.
IPEX works with corresponding/specific PyTorch verions.

Please following this instruction to install IPEX (choose your platform, device etc):
https://intel.github.io/intel-extension-for-pytorch/#installation?request=platform

@xiguiw
Copy link
Contributor

xiguiw commented May 20, 2024

Issue coming from:

Trying:

>>> from intel_extension_for_transformers.transformers import ViTImageProcessor
>>> processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
/lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/saforem2/stormer-dev/venvs/sunspot/q4-drop/lib/python3.9/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: ''If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
  warn(
ERROR! Intel® Extension for PyTorch* needs to work with PyTorch 2.4.*, but PyTorch 2.1.0a0+cxx11.abi is found. Pleaseswitch to the matching version and run again.

# ... see Full Traceback below ...
File /lus/gila/projects/Aurora_deployment/foremans/locations/sunspot/projects/intel/ipex/intel_extension_for_pytorch/__init__.py:36
     30 if torch_version == "" or ipex_version == "" or torch_version != ipex_version:
     31     print(
     32         "ERROR! Intel® Extension for PyTorch* needs to work with PyTorch "
     33         + f"{ipex_version}.*, but PyTorch {torch.__version__} is found. "
     34         + "Please switch to the matching version and run again."
     35     )
---> 36     exit(127)
     39 import os
     40 import sys

NameError: name 'exit' is not defined

I tried your case but did not find your issue "NameError: name 'exit' is not defined
"
ERROR! Intel® Extension for PyTorch* needs to work with PyTorch 2.3.*, but PyTorch 2.1.0.post2+cxx11.abi is found. Please switch to the matching version and run again.

Here is exit() in python:
In Python, the exit() function is a built-in that should always be available in the standard interpreter. It is used to exit from Python. However, if you are encountering a NameError for exit, it could be due to several reasons:

Restricted Environment: If you are running Python in a restricted environment or a custom interpreter that doesn't include the built-in functions, exit() might not be available.

Overwritten or Shadowed exit: If you have defined a variable or function named exit somewhere in your code before calling exit(), you might have overwritten the built-in exit function.

Running in a Non-Interactive Shell: The exit() function is intended for use in the interactive interpreter shell. If you are running a script non-interactively, you should use sys.exit() instead.

@xiguiw
Copy link
Contributor

xiguiw commented May 20, 2024

@saforem2
I reproduce your envrionment error (by install intel-extension-for-pytorch CPU version and Pytorch XPU version). But cannot reproduce the error of "NameError: name 'exit' is not defined"

1, For installation issue, install all CPU or XPU version. Do not mixed both version in your environment.
2. For the exit issue, I cannot_ reproduce it. Will ignore this if no furthere information from you.

@saforem2
Copy link
Author

yeah happy to close this, not sure what issue I was seeing here.

will open a new ticket if I encounter a new issue.

Thanks!

@xiguiw
Copy link
Contributor

xiguiw commented May 21, 2024

@saforem2

Thanks for your feedback :-)

Double check this, I believe it dependens how we create the environment.
Could you let me konw how you set up the environment?

I will try to reproduce it then submit PR to fix it.

The exit() function is not available by default in all contexts and typically requires importing the sys module.
 However, in some interactive environments like the Python REPL or certain IDEs, exit() and quit() are available 
as built-in functions. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working CPU CPU specific issues
Projects
None yet
Development

No branches or pull requests

4 participants