Skip to content

Commit 9f6be16

Browse files
committed
Add CI
1 parent d72f53e commit 9f6be16

File tree

5 files changed

+75
-16
lines changed

5 files changed

+75
-16
lines changed

.github/workflows/pull.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ jobs:
5656
# Build and test ExecuTorch with the add model on portable backend.
5757
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "add" "${BUILD_TOOL}" "portable"
5858
59+
test-pip-install-editable-mode-linux:
60+
name: test-pip-install-editable-mode-linux
61+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
62+
permissions:
63+
id-token: write
64+
contents: read
65+
strategy:
66+
fail-fast: false
67+
with:
68+
runner: linux.2xlarge
69+
docker-image: executorch-ubuntu-22.04-clang12
70+
submodules: 'true'
71+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
72+
timeout: 90
73+
script: |
74+
# The generic Linux job chooses to use base env, not the one setup by the image
75+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
76+
conda activate "${CONDA_ENV}"
77+
# Debug
78+
which pip
79+
PYTHON_EXECUTABLE=python bash ./install_executorch.sh --editable-mode --pybind xnnpack --use-pt-pinned-commit
80+
# Try to import extension library
81+
python -c "from executorch.extension.llm.custom_ops import custom_ops"
82+
5983
test-models-linux:
6084
name: test-models-linux
6185
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
@@ -480,7 +504,7 @@ jobs:
480504
481505
# Setup install_requirements for llama
482506
PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh
483-
507+
484508
# Test static llama weight sharing and accuracy
485509
PYTHON_EXECUTABLE=python bash .ci/scripts/test_qnn_static_llama.sh
486510

.github/workflows/trunk.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ jobs:
3636
3737
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py --target-os macos --event "${GITHUB_EVENT_NAME}"
3838
39+
test-pip-install-editable-mode-macos:
40+
name: test-pip-install-editable-mode-macos
41+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
42+
permissions:
43+
id-token: write
44+
contents: read
45+
strategy:
46+
fail-fast: false
47+
with:
48+
runner: macos-m1-stable
49+
python-version: '3.11'
50+
submodules: 'true'
51+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
52+
timeout: 90
53+
script: |
54+
# The generic Linux job chooses to use base env, not the one setup by the image
55+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
56+
conda activate "${CONDA_ENV}"
57+
# Debug
58+
which pip
59+
bash .ci/scripts/setup-conda.sh
60+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash ./install_executorch.sh --editable-mode --pybind xnnpack --use-pt-pinned-commit
61+
# Try to import extension library
62+
python -c "from executorch.extension.llm.custom_ops import custom_ops"
63+
3964
test-models-macos:
4065
name: test-models-macos
4166
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main

extension/llm/custom_ops/custom_ops.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222
op2 = torch.ops.llama.fast_hadamard_transform.default
2323
assert op2 is not None
2424
except:
25-
import glob
26-
import os
27-
2825
# This is needed to ensure that custom ops are registered
2926
from executorch.extension.pybindings import portable_lib # noqa # usort: skip
3027

3128
# Ideally package is installed in only one location but usage of
3229
# PYATHONPATH can result in multiple locations.
3330
# ATM this is mainly used in CI for qnn runner. Will need to revisit this
3431
from pathlib import Path
32+
3533
package_path = Path(__file__).parent.resolve()
3634
logging.info(f"Looking for libcustom_ops_aot_lib.so in {package_path}")
3735

install_executorch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ def build_args_parser() -> argparse.ArgumentParser:
138138
action="store_true",
139139
help="build from the pinned PyTorch commit instead of nightly",
140140
)
141+
parser.add_argument(
142+
"--editable",
143+
"-e",
144+
action="store_true",
145+
help="build an editable pip wheel, changes to python code will be "
146+
"picked up without rebuilding the wheel. Extension libraries will be "
147+
"installed inside the source tree.",
148+
)
141149
return parser
142150

143151

@@ -226,6 +234,7 @@ def main(args):
226234
"-m",
227235
"pip",
228236
"install",
237+
"-e" if args.editable_mode else "",
229238
".",
230239
"--no-build-isolation",
231240
"-v",

setup.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
import os
5151
import platform
5252
import re
53-
import sys
5453
import site
54+
import sys
5555

5656
# Import this before distutils so that setuptools can intercept the distuils
5757
# imports.
@@ -372,12 +372,13 @@ def dst_path(self, installer: "InstallerBuildExt") -> Path:
372372

373373
class InstallerBuildExt(build_ext):
374374
"""Installs files that were built by cmake."""
375+
375376
def __init__(self, *args, **kwargs):
376377
self._ran_build = False
377378
super().__init__(*args, **kwargs)
378379

379380
def run(self):
380-
# Run the build command first in editable mode. Since `build` command
381+
# Run the build command first in editable mode. Since `build` command
381382
# will also trigger `build_ext` command, only run this once.
382383
if self._ran_build:
383384
return
@@ -387,10 +388,9 @@ def run(self):
387388
self.run_command("build")
388389
super().run()
389390

390-
391391
def copy_extensions_to_source(self) -> None:
392-
"""For each extension in `ext_modules`, we need to copy the extension
393-
file from the build directory to the correct location in the local
392+
"""For each extension in `ext_modules`, we need to copy the extension
393+
file from the build directory to the correct location in the local
394394
directory.
395395
396396
This should only be triggered when inplace mode (editable mode) is enabled.
@@ -399,11 +399,11 @@ def copy_extensions_to_source(self) -> None:
399399
400400
Returns:
401401
"""
402-
build_py = self.get_finalized_command('build_py')
402+
build_py = self.get_finalized_command("build_py")
403403
for ext in self.extensions:
404404
if isinstance(ext, BuiltExtension):
405-
modpath = ext.name.split('.')
406-
package = '.'.join(modpath[:-1])
405+
modpath = ext.name.split(".")
406+
package = ".".join(modpath[:-1])
407407
package_dir = os.path.abspath(build_py.get_package_dir(package))
408408
else:
409409
# HACK: get rid of the leading "executorch" in ext.dst.
@@ -412,9 +412,11 @@ def copy_extensions_to_source(self) -> None:
412412

413413
# Ensure that the destination directory exists.
414414
self.mkpath(os.fspath(package_dir))
415-
415+
416416
regular_file = ext.src_path(self)
417-
inplace_file = os.path.join(package_dir, os.path.basename(ext.src_path(self)))
417+
inplace_file = os.path.join(
418+
package_dir, os.path.basename(ext.src_path(self))
419+
)
418420

419421
# Always copy, even if source is older than destination, to ensure
420422
# that the right extensions for the current Python/platform are
@@ -428,7 +430,6 @@ def copy_extensions_to_source(self) -> None:
428430
# Always compile stub and remove the original (leave the cache behind)
429431
# (this behaviour was observed in previous iterations of the code)
430432

431-
432433
# TODO(dbort): Depend on the "build" command to ensure it runs first
433434

434435
def build_extension(self, ext: _BaseExtension) -> None:
@@ -688,7 +689,9 @@ def run(self):
688689
# Dry run should log the command but not actually run it.
689690
(Path(cmake_cache_dir) / "CMakeCache.txt").unlink(missing_ok=True)
690691
# Set PYTHONPATH to the location of the pip package.
691-
os.environ["PYTHONPATH"] = site.getsitepackages()[0] + ";" + os.environ["PYTHONPATH"]
692+
os.environ["PYTHONPATH"] = (
693+
site.getsitepackages()[0] + ";" + os.environ.get("PYTHONPATH", "")
694+
)
692695
with Buck2EnvironmentFixer():
693696
# The context manager may patch the environment while running this
694697
# cmake command, which happens to run buck2 to get some source

0 commit comments

Comments
 (0)