Skip to content

Проблема с удалением артефактов (?) в _optimization_info.py #262

@astrovvv

Description

@astrovvv

Если указать в пресете:

  - node_type: decision
    target_metric: decision_f1

Получаю ошибку Failed to save optimization info

Трейс ошибки
[I 2025-08-28 09:45:03,556] A new study created in RDB with name: NodeType.scoring
Failed to save optimization info
Traceback (most recent call last):
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\optimization_info\_optimization_info.py", line 245, in dump
  shutil.rmtree(target_path)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
  return _rmtree_unsafe(path, onerror)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 626, in _rmtree_unsafe
  onerror(os.rmdir, path, sys.exc_info())
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 624, in _rmtree_unsafe
  os.rmdir(path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'data\\runs\\breakable_fly_08-28-2025_09-45-03\\optimization_info\\pydantic'
Failed to save optimization info
Traceback (most recent call last):
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\optimization_info\_optimization_info.py", line 245, in dump
  shutil.rmtree(target_path)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
  return _rmtree_unsafe(path, onerror)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
  onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 620, in _rmtree_unsafe
  os.unlink(fullname)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'data\\runs\\breakable_fly_08-28-2025_09-45-03\\optimization_info\\pydantic\\trials\\model_dump.json'
Failed to save optimization info
Traceback (most recent call last):
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\optimization_info\_optimization_info.py", line 245, in dump
  shutil.rmtree(target_path)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
  return _rmtree_unsafe(path, onerror)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 626, in _rmtree_unsafe
  onerror(os.rmdir, path, sys.exc_info())
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 624, in _rmtree_unsafe
  os.rmdir(path)
OSError: [WinError 145] The directory is not empty: 'data\\runs\\breakable_fly_08-28-2025_09-45-03\\optimization_info\\pydantic'
Failed to save optimization info
Traceback (most recent call last):
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\optimization_info\_optimization_info.py", line 245, in dump
  shutil.rmtree(target_path)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
  return _rmtree_unsafe(path, onerror)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
  onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 620, in _rmtree_unsafe
  os.unlink(fullname)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'data\\runs\\breakable_fly_08-28-2025_09-45-03\\optimization_info\\pydantic\\artifacts\\class_info.json'
[W 2025-08-28 09:46:16,305] Trial 0 failed with parameters: {'module_idx': 0} because of the following error: FileNotFoundError(2, 'The system cannot find the path specified').
Traceback (most recent call last):
File "D:\intent-classifier\.venv\Lib\site-packages\optuna\study\_optimize.py", line 201, in _run_trial
  value_or_values = func(trial)
                    ^^^^^^^^^^^
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\nodes\_node_optimizer.py", line 163, in objective
  context.dump_optimization_info()
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\_context.py", line 88, in dump_optimization_info
  self.optimization_info.dump(self.logging_config.dirpath)
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\optimization_info\_optimization_info.py", line 245, in dump
  shutil.rmtree(target_path)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
  return _rmtree_unsafe(path, onerror)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 626, in _rmtree_unsafe
  onerror(os.rmdir, path, sys.exc_info())
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 624, in _rmtree_unsafe
  os.rmdir(path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'data\\runs\\breakable_fly_08-28-2025_09-45-03\\optimization_info\\pydantic'
[W 2025-08-28 09:46:16,314] Trial 10 failed with parameters: {'module_idx': 0} because of the following error: FileNotFoundError(2, 'The system cannot find the file specified').
Traceback (most recent call last):
File "D:\intent-classifier\.venv\Lib\site-packages\optuna\study\_optimize.py", line 201, in _run_trial
  value_or_values = func(trial)
                    ^^^^^^^^^^^
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\nodes\_node_optimizer.py", line 163, in objective
  context.dump_optimization_info()
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\_context.py", line 88, in dump_optimization_info
  self.optimization_info.dump(self.logging_config.dirpath)
File "D:\intent-classifier\.venv\Lib\site-packages\autointent\context\optimization_info\_optimization_info.py", line 245, in dump
  shutil.rmtree(target_path)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
  return _rmtree_unsafe(path, onerror)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
  onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\Astrov\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 620, in _rmtree_unsafe
  os.unlink(fullname)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'data\\runs\\breakable_fly_08-28-2025_09-45-03\\optimization_info\\pydantic\\trials\\model_dump.json'

Временный фикс - подавил ошибки FileNotFoundError, PermissionError здесь. В причинах/последствиях не разбирался

        with tempfile.TemporaryDirectory(dir=path) as temp_dir:
            temp_path = Path(temp_dir)

            # Try to save to the temporary directory first
            try:
                Dumper.dump(self, temp_path, exists_ok=False, exclude=exclude)

                # If successful, move the contents to the final destination
                if target_path.exists():
                    for sub in target_path.iterdir():
                        if sub.is_dir():
                            try:
                                shutil.rmtree(sub)
                            except (FileNotFoundError, PermissionError):
                                logger.warning(f"Could not remove directory {sub}")
                                pass
                        else:
                            try:
                                sub.unlink()
                            except (FileNotFoundError, PermissionError):
                                logger.warning(f"Could not remove file {sub}")
                                pass
                else:
                    target_path.mkdir(parents=True, exist_ok=True)
                shutil.move(temp_path, target_path)

            except Exception:
                logger.exception("Failed to save optimization info")
                raise

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions