Skip to content

Commit be15945

Browse files
committed
Run Python unit test CI on Windows
ghstack-source-id: dcb321c ghstack-comment-id: 3226055310 Pull-Request: #13716
1 parent 4c4cbdf commit be15945

File tree

11 files changed

+63
-23
lines changed

11 files changed

+63
-23
lines changed

.ci/scripts/unittest-windows.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
param (
2+
[bool]$editable
3+
)
4+
5+
Set-PSDebug -Trace 1
6+
$ErrorActionPreference = 'Stop'
7+
$PSNativeCommandUseErrorActionPreference = $true
8+
9+
conda create --yes --quiet -n et python=3.12
10+
conda activate et
11+
12+
# Activate the VS environment - this is required for Dynamo to work, as it uses MSVC.
13+
# There are a bunch of environment variables that it requires.
14+
# See https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line.
15+
& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64
16+
17+
install_executorch.bat --editable:$editable
18+
if ($LASTEXITCODE -ne 0) {
19+
Write-Host "Installation was unsuccessful. Exit code: $LASTEXITCODE."
20+
exit $LASTEXITCODE
21+
}
22+
23+
# Run pytest with coverage
24+
# pytest -n auto --cov=./ --cov-report=xml
25+
pytest -n auto --continue-on-collection-errors
26+
if ($LASTEXITCODE -ne 0) {
27+
Write-Host "Pytest invocation was unsuccessful. Exit code: $LASTEXITCODE."
28+
exit $LASTEXITCODE
29+
}

.github/workflows/_unittest.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,13 @@ jobs:
5252
# This is needed to get the prebuilt PyTorch wheel from S3
5353
${CONDA_RUN} --no-capture-output pip install awscli==1.37.21
5454
.ci/scripts/unittest-macos.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}"
55+
56+
windows:
57+
uses: pytorch/test-infra/.github/workflows/windows_job.yml@main
58+
with:
59+
if: ${{ inputs.build-tool == 'cmake' }}
60+
submodules: 'recursive'
61+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
62+
script: |
63+
conda init powershell
64+
powershell .ci/scripts/unittest-windows.ps1 -editable "${{ inputs.editable }}"

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ xcuserdata/
6565

6666
# Android
6767
*.aar
68+
69+
# Windows
70+
*.dll
71+
*.pyd

backends/xnnpack/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ endforeach()
6262
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
6363
set(MV_COMMAND
6464
powershell -Command
65-
"Move-Item -Path ${_xnnpack_flatbuffer__outputs} -Destination ${_xnnpack_schema__outputs}"
65+
"Move-Item -Path ${_xnnpack_flatbuffer__outputs} -Destination ${_xnnpack_schema__outputs} -Force"
6666
)
6767
else()
6868
set(MV_COMMAND mv ${_xnnpack_flatbuffer__outputs} ${_xnnpack_schema__outputs})

examples/models/llama/source_transformation/custom_kv_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def replace_kv_cache_with_quantized_kv_cache(module):
269269
executorch_package_path = executorch.__path__[-1]
270270
libs = list(
271271
glob.glob(
272-
f"{executorch_package_path}/**/libquantized_ops_aot_lib.*",
272+
f"{executorch_package_path}/**/*quantized_ops_aot_lib.*",
273273
recursive=True,
274274
)
275275
)

extension/llm/custom_ops/custom_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
package_path = Path(__file__).parent.resolve()
3434
logging.info(f"Looking for libcustom_ops_aot_lib.so in {package_path}")
3535

36-
libs = list(package_path.glob("**/libcustom_ops_aot_lib.*"))
36+
libs = list(package_path.glob("**/*custom_ops_aot_lib.*"))
3737

3838
assert len(libs) == 1, f"Expected 1 library but got {len(libs)}"
3939
logging.info(f"Loading custom ops library: {libs[0]}")

extension/llm/custom_ops/op_tile_crop_aot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
tile_crop = torch.ops.preprocess.tile_crop.default
1414
assert tile_crop is not None
1515
except:
16-
libs = list(Path(__file__).parent.resolve().glob("libcustom_ops_aot_lib.*"))
16+
libs = list(Path(__file__).parent.resolve().glob("*custom_ops_aot_lib.*"))
1717
assert len(libs) == 1, f"Expected 1 library but got {len(libs)}"
1818
logging.info(f"Loading custom ops library: {libs[0]}")
1919
torch.ops.load_library(libs[0])

install_executorch.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,6 @@ def main(args):
194194
clean()
195195
return
196196

197-
cmake_args = [os.getenv("CMAKE_ARGS", "")]
198-
# Use ClangCL on Windows.
199-
# ClangCL is an alias to Clang that configures it to work in an MSVC-compatible
200-
# mode. Using it on Windows to avoid compiler compatibility issues for MSVC.
201-
if os.name == "nt":
202-
cmake_args.append("-T ClangCL")
203-
os.environ["CMAKE_ARGS"] = " ".join(cmake_args)
204-
205197
check_and_update_submodules()
206198
# This option is used in CI to make sure that PyTorch build from the pinned commit
207199
# is used instead of nightly. CI jobs wouldn't be able to catch regression from the

kernels/quantized/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
try:
88
from pathlib import Path
99

10-
libs = list(Path(__file__).parent.resolve().glob("**/libquantized_ops_aot_lib.*"))
10+
libs = list(Path(__file__).parent.resolve().glob("**/*quantized_ops_aot_lib.*"))
1111
del Path
1212
assert len(libs) == 1, f"Expected 1 library but got {len(libs)}"
1313
import torch as _torch

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ def run(self): # noqa C901
672672
f"-DCMAKE_BUILD_TYPE={cmake_build_type}",
673673
]
674674

675+
# Use ClangCL on Windows.
676+
if _is_windows():
677+
cmake_configuration_args += ["-T ClangCL"]
678+
675679
# Allow adding extra cmake args through the environment. Used by some
676680
# tests and demos to expand the set of targets included in the pip
677681
# package.
@@ -769,7 +773,7 @@ def run(self): # noqa C901
769773
# platform-specific files using InstallerBuildExt.
770774
ext_modules=[
771775
BuiltFile(
772-
src_dir="%CMAKE_CACHE_DIR%/third-party/flatbuffers_external_project/bin/",
776+
src_dir="%CMAKE_CACHE_DIR%/third-party/flatc_proj/bin/",
773777
src_name="flatc",
774778
dst="executorch/data/bin/",
775779
is_executable=True,
@@ -795,7 +799,8 @@ def run(self): # noqa C901
795799
dependent_cmake_flags=["EXECUTORCH_BUILD_EXTENSION_TRAINING"],
796800
),
797801
BuiltExtension(
798-
src="codegen/tools/selective_build.*",
802+
src_dir="%CMAKE_CACHE_DIR%/codegen/tools/%BUILD_TYPE%/",
803+
src="selective_build.cp*" if _is_windows() else "selective_build.*",
799804
modpath="executorch.codegen.tools.selective_build",
800805
dependent_cmake_flags=["EXECUTORCH_BUILD_PYBIND"],
801806
),

0 commit comments

Comments
 (0)