From f716ac691b447acad913ba7bddc15775e297aaa1 Mon Sep 17 00:00:00 2001 From: NullSenseStudio <47096043+NullSenseStudio@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:38:16 -0400 Subject: [PATCH] support zipped dependencies --- generator_process/actor.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/generator_process/actor.py b/generator_process/actor.py index 916952b3..af881b4f 100644 --- a/generator_process/actor.py +++ b/generator_process/actor.py @@ -10,6 +10,19 @@ from ..absolute_path import absolute_path from .future import Future +def _patch_zip_direct_transformers_import(): + # direct_transformers_import() implementation doesn't work when transformers is in a zip archive + # since it relies on existing file paths. The function appears to ensure the correct root module + # is obtained when there could be another loadable transformers module or it isn't in any sys.path + # directory during development testing, both not being a concern in this environment. + def direct_transformers_import(*_, **__): + import transformers + return transformers + from transformers.utils import import_utils + import_utils.direct_transformers_import = direct_transformers_import + from transformers import utils + utils.direct_transformers_import = direct_transformers_import + def _load_dependencies(): site.addsitedir(absolute_path(".python_dependencies")) deps = sys.path.pop(-1) @@ -20,6 +33,9 @@ def _load_dependencies(): python3_path = os.path.abspath(os.path.join(sys.executable, "..\\..\\..\\..\\python3.dll")) if os.path.exists(python3_path): os.add_dll_directory(os.path.dirname(python3_path)) + if os.path.exists(absolute_path(".python_dependencies.zip")): + sys.path.insert(1, absolute_path(".python_dependencies.zip")) + _patch_zip_direct_transformers_import() main_thread_rendering = False is_actor_process = current_process().name == "__actor__"