Skip to content

Commit

Permalink
hooks: add hook for fvcore.nn
Browse files Browse the repository at this point in the history
Add hook for `fvcore.nn` 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 Dec 23, 2023
1 parent d343653 commit 7409fd1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/676.new.10.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``fvcore.nn`` to collect its source .py files for
TorchScript/JIT.
14 changes: 14 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-fvcore.nn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ------------------------------------------------------------------
# Copyright (c) 2023 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'
9 changes: 9 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_deep_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,12 @@ def forward(self, x):
print("Test X:", test_x.numpy())
print("Predicted Y:", observed_pred.mean.numpy())
""")


# 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):
pyi_builder.test_source("""
import fvcore.nn
""")

0 comments on commit 7409fd1

Please sign in to comment.