Skip to content

Commit

Permalink
hooks: add hook for fairscale
Browse files Browse the repository at this point in the history
Add hook for `fairscale` to collect its source .py files for
torchscript/JIT.

Add a basic import test that demonstrates the need for that.
  • Loading branch information
rokm committed Jan 18, 2024
1 parent 21d3e53 commit 29c475a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions news/692.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``fairscale`` to collect its source .py files for
TorchScript/JIT.
14 changes: 14 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-fairscale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------------------------------------
# Copyright (c) 2024 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

# Collect source .py files for JIT/torchscript. Requires PyInstaller >= 5.3, no-op in older versions.
module_collection_mode = 'pyz+py'
13 changes: 11 additions & 2 deletions src/_pyinstaller_hooks_contrib/tests/test_deep_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def forward(self, x):
""")


# Basic import test for fvcore.nn, which shows that we need to collect its source.py files for TorchScript/JIT.
# Basic import test for fvcore.nn, which shows that we need to collect its source .py files for TorchScript/JIT.
@importorskip('fvcore')
@onedir_only
def test_fvcore(pyi_builder):
Expand All @@ -294,7 +294,7 @@ def test_fvcore(pyi_builder):
""")


# Basic test for detectron2, which shows that we need to collect its source.py files for TorchScript/JIT.
# Basic test for detectron2, which shows that we need to collect its source .py files for TorchScript/JIT.
@importorskip('detectron2')
@onedir_only
def test_detectron2(pyi_builder):
Expand Down Expand Up @@ -350,3 +350,12 @@ def test_accelerate(pyi_builder):
print("Model:", model)
print("Optimizer:", optimizer)
""")


# Basic import test for fairscale, which shows that we need to collect its source .py files for TorchScript/JIT.
@importorskip('fairscale')
@onedir_only
def test_fairscale(pyi_builder):
pyi_builder.test_source("""
import fairscale
""")

0 comments on commit 29c475a

Please sign in to comment.