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

Zip Dependencies with Long Paths #788

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
shell: bash
run: 'python -m pip install -r requirements/win-linux-cuda.txt --no-cache-dir --target .python_dependencies'
working-directory: dream_textures
- name: Zip dependencies with long paths
shell: bash
run: 'python ./dream_textures/scripts/zip_dependencies.py'
- name: Archive Release
uses: thedoctor0/zip-release@main
with:
Expand Down Expand Up @@ -73,6 +76,9 @@ jobs:
shell: bash
run: 'python -m pip install -r requirements/win-dml.txt --no-cache-dir --target .python_dependencies'
working-directory: dream_textures
- name: Zip dependencies with long paths
shell: bash
run: 'python ./dream_textures/scripts/zip_dependencies.py'
- name: Archive Release
uses: thedoctor0/zip-release@main
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __pycache__/
*.so

# Distribution / packaging
.python_dependencies.zip
.Python
build/
develop-eggs/
Expand Down
16 changes: 16 additions & 0 deletions generator_process/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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__"
Expand Down
26 changes: 26 additions & 0 deletions scripts/zip_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import shutil
import zipfile
from pathlib import Path


def main():
root = Path(__file__).parent.parent
deps = root / '.python_dependencies'
deps_to_zip = [deps / 'transformers']

for dep in deps_to_zip:
if not dep.exists():
raise FileNotFoundError(dep)
elif not dep.is_dir():
raise EnvironmentError(f"not a directory {dep}")

zip_deps_path = root / '.python_dependencies.zip'
zip_deps_path.unlink(True)
with zipfile.PyZipFile(str(zip_deps_path), mode='x') as zip_deps:
for dep in deps_to_zip:
zip_deps.writepy(str(dep))
shutil.rmtree(str(dep))


if __name__ == '__main__':
main()
Loading