optimum-intel icon indicating copy to clipboard operation
optimum-intel copied to clipboard

Failed to remove Tmp directory on Windows after export openvino model

Open TianmengChen opened this issue 1 year ago • 2 comments

openvino 2024.2.0 openvino-telemetry 2024.1.0 optimum 1.22.0.dev0 optimum-intel 1.18.0.dev0

Script

from optimum.intel import OVModelForCausalLM
from transformers import AutoTokenizer

MODEL_ID = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"

model = OVModelForCausalLM.from_pretrained(MODEL_ID, export=True)
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)

Error log

(optimum-intel-sd-controlnet) PS C:\Users\openvino\chen\demo_optimum-intel-sd-controlnet> python .\test.py
Framework not specified. Using pt to export the model.
The model will be converted with no weights quantization. Quantization of the weights to int8 requires nncf.please install it with `pip install nncf`
Using framework PyTorch: 2.3.1+cpu
Overriding 1 configuration item(s)
        - use_cache -> True
C:\Users\openvino\chen\venv\optimum-intel-sd-controlnet\lib\site-packages\optimum\exporters\openvino\model_patcher.py:467: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if sequence_length != 1:
Compiling the model to CPU ...
Traceback (most recent call last):
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 618, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\openvino\\AppData\\Local\\Temp\\tmpjab0hfix\\openvino_model.bin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 843, in onerror
    _os.unlink(path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\openvino\\AppData\\Local\\Temp\\tmpjab0hfix\\openvino_model.bin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\weakref.py", line 667, in _exitfunc
    f()
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\weakref.py", line 591, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 859, in _cleanup
    cls._rmtree(name, ignore_errors=ignore_errors)
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 855, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 750, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 620, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 846, in onerror
    cls._rmtree(path, ignore_errors=ignore_errors)
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\tempfile.py", line 855, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 750, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 601, in _rmtree_unsafe
    onerror(os.scandir, path, sys.exc_info())
  File "C:\Users\openvino\AppData\Local\Programs\Python\Python310\lib\shutil.py", line 598, in _rmtree_unsafe
    with os.scandir(path) as scandir_it:
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\openvino\\AppData\\Local\\Temp\\tmpjab0hfix\\openvino_model.bin'

TianmengChen avatar Jul 16 '24 01:07 TianmengChen

@helena-intel, I see that you try to fix similar issue: https://github.com/huggingface/optimum-intel/pull/749, which is already available on https://github.com/huggingface/optimum-intel/releases/tag/v1.18.0 But it seems not fix this issue in optimum-intel 1.18.0dev, Could you please kindly check this issue with reproducer above?

sammysun0711 avatar Jul 16 '24 02:07 sammysun0711

@TianmengChen please verify potential fix after https://github.com/huggingface/optimum-intel/pull/925 merge.

sammysun0711 avatar Oct 21 '24 09:10 sammysun0711