Skip to content

Commit d8716ff

Browse files
authored
Merge branch 'main' into toupstream/slice_op
2 parents 71fbef4 + 1f114f1 commit d8716ff

File tree

207 files changed

+9966
-2430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+9966
-2430
lines changed

.ci/docker/requirements-ci.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mpmath==1.3.0
22
numpy>=2.0.0; python_version >= '3.10'
33
PyYAML==6.0.1
4-
ruamel.yaml==0.17.32
4+
ruamel.yaml==0.18.15
55
sympy==1.12
66
timm==0.6.13
77
tomli==2.0.1

.ci/scripts/test-cuda-build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ test_executorch_cuda_build() {
2727
nvcc --version || echo "nvcc not found"
2828
nvidia-smi || echo "nvidia-smi not found"
2929

30-
# Set CMAKE_ARGS to enable CUDA build - ExecuTorch will handle PyTorch installation automatically
31-
export CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON"
32-
3330
echo "=== Starting ExecuTorch Installation ==="
3431
# Install ExecuTorch with CUDA support with timeout and error handling
3532
timeout 5400 ./install_executorch.sh || {

.ci/scripts/test_llama_lora.sh

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ cmake_build_llama_runner
5555
# Constants.
5656
RUNTIME_ARGS="--tokenizer_path=${DOWNLOADED_PATH}/tokenizer.model --temperature=0 --seq_len=20 --warmup=1"
5757
PROMPT="What happens if you eat watermelon seeds?"
58-
EXPECTED_PREFIX="What happens if you eat watermelon seeds? Watermelon seeds are a good source of vitamin C,"
58+
EXPECTED_PREFIX="What happens if you eat watermelon seeds? Watermelon seeds are a good source of vitamin C and"
5959

6060
# Export LoRA PTE file.
6161
MODEL_NAME="llama_3_2_1B_lora"
@@ -94,7 +94,7 @@ else
9494
exit 1
9595
fi
9696

97-
# Export LoRA PTE, PTD file.
97+
# Export LoRA PTE, foundation PTD file.
9898
MODEL_SEPARATE="${MODEL_NAME}_separate"
9999
$PYTHON_EXECUTABLE -m extension.llm.export.export_llm \
100100
base.checkpoint="${DOWNLOADED_PATH}/consolidated.00.pth" \
@@ -114,20 +114,62 @@ $PYTHON_EXECUTABLE -m extension.llm.export.export_llm \
114114
NOW=$(date +"%H:%M:%S")
115115
echo "Starting to run llama runner at ${NOW}"
116116
# shellcheck source=/dev/null
117-
cmake-out/examples/models/llama/llama_main --model_path=${MODEL_SEPARATE}.pte --data_path=${MODEL_SEPARATE}.ptd --prompt="${PROMPT}" ${RUNTIME_ARGS} > result2.txt
117+
cmake-out/examples/models/llama/llama_main --model_path=${MODEL_SEPARATE}.pte --data_paths=${MODEL_SEPARATE}.ptd --prompt="${PROMPT}" ${RUNTIME_ARGS} > result2.txt
118118
NOW=$(date +"%H:%M:%S")
119119
echo "Finished at ${NOW}"
120120

121121
RESULT2=$(cat result2.txt)
122122
if [[ "${RESULT2}" == "${EXPECTED_PREFIX}"* ]]; then
123123
echo "Expected result prefix: ${EXPECTED_PREFIX}"
124124
echo "Actual result: ${RESULT2}"
125+
# Do not clean up files if test passes, as they're re-used in the next test.
125126
echo "Success"
126-
cleanup_files
127127
else
128128
echo "Expected result prefix: ${EXPECTED_PREFIX}"
129129
echo "Actual result: ${RESULT2}"
130130
echo "Failure; results not the same"
131131
cleanup_files
132132
exit 1
133133
fi
134+
135+
# Export LoRA PTE, LoRA PTD, foundation PTD file.
136+
MODEL_PROGRAM_ONLY="${MODEL_NAME}_program"
137+
MODEL_LORA_WEIGHTS="lora_weights"
138+
MODEL_FOUNDATION_WEIGHTS="foundation_weights"
139+
$PYTHON_EXECUTABLE -m extension.llm.export.export_llm \
140+
base.checkpoint="${DOWNLOADED_PATH}/consolidated.00.pth" \
141+
base.params="${DOWNLOADED_PATH}/params.json" \
142+
base.adapter_checkpoint="${DOWNLOADED_PATH}/adapter_model.pt" \
143+
base.adapter_config="${DOWNLOADED_PATH}/adapter_config.json" \
144+
base.tokenizer_path="${DOWNLOADED_PATH}/tokenizer.model" \
145+
model.use_kv_cache=true \
146+
model.use_sdpa_with_kv_cache=true \
147+
model.dtype_override="fp32" \
148+
backend.xnnpack.enabled=true \
149+
backend.xnnpack.extended_ops=true \
150+
export.output_name="${MODEL_PROGRAM_ONLY}.pte" \
151+
export.foundation_weights_file="${MODEL_FOUNDATION_WEIGHTS}.ptd" \
152+
export.lora_weights_file="${MODEL_LORA_WEIGHTS}.ptd"
153+
154+
# Run llama runner.
155+
NOW=$(date +"%H:%M:%S")
156+
echo "Starting to run llama runner at ${NOW}"
157+
# shellcheck source=/dev/null
158+
cmake-out/examples/models/llama/llama_main --model_path=${MODEL_PROGRAM_ONLY}.pte --data_paths="${MODEL_FOUNDATION_WEIGHTS}.ptd,${MODEL_LORA_WEIGHTS}.ptd" --prompt="${PROMPT}" ${RUNTIME_ARGS} > result3.txt
159+
NOW=$(date +"%H:%M:%S")
160+
echo "Finished at ${NOW}"
161+
162+
RESULT3=$(cat result3.txt)
163+
if [[ "${RESULT3}" == "${EXPECTED_PREFIX}"* ]]; then
164+
echo "Expected result prefix: ${EXPECTED_PREFIX}"
165+
echo "Actual result: ${RESULT3}"
166+
echo "Success"
167+
else
168+
echo "Expected result prefix: ${EXPECTED_PREFIX}"
169+
echo "Actual result: ${RESULT3}"
170+
echo "Failure; results not the same"
171+
cleanup_files
172+
exit 1
173+
fi
174+
175+
cleanup_files

.githooks/pre-commit

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ if git diff --cached --name-only | grep -q "^torch_pin.py$"; then
88
echo "📝 Updating PyTorch commit pin..."
99

1010
# Run the update script
11-
if python .github/scripts/update_pytorch_pin.py; then
11+
hook_output=$(python .github/scripts/update_pytorch_pin.py 2>&1)
12+
hook_status=$?
13+
echo "$hook_output"
14+
15+
if [ $hook_status -eq 0 ]; then
1216
# Check if pytorch.txt was modified
1317
if ! git diff --quiet .ci/docker/ci_commit_pins/pytorch.txt; then
1418
echo "✅ PyTorch commit pin updated successfully"
@@ -19,9 +23,14 @@ if git diff --cached --name-only | grep -q "^torch_pin.py$"; then
1923
echo "ℹ️ PyTorch commit pin unchanged"
2024
fi
2125
else
22-
echo "❌ Failed to update PyTorch commit pin"
23-
echo "Please run: python .github/scripts/update_pytorch_pin.py"
24-
exit 1
26+
if echo "$hook_output" | grep -qi "rate limit exceeded"; then
27+
echo "⚠️ PyTorch commit pin not updated due to GitHub API rate limiting."
28+
echo " Please manually update .ci/docker/ci_commit_pins/pytorch.txt if needed."
29+
else
30+
echo "❌ Failed to update PyTorch commit pin"
31+
echo "Please run: python .github/scripts/update_pytorch_pin.py"
32+
exit 1
33+
fi
2534
fi
2635
fi
2736

.github/scripts/update_pytorch_pin.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55
import sys
66
import urllib.request
7-
from datetime import datetime
87

98

109
def parse_nightly_version(nightly_version):
@@ -53,7 +52,7 @@ def get_commit_hash_for_nightly(date_str):
5352
Commit hash string
5453
"""
5554
api_url = "https://api.github.com/repos/pytorch/pytorch/commits"
56-
params = f"?sha=nightly&per_page=100"
55+
params = f"?sha=nightly&per_page=50"
5756
url = api_url + params
5857

5958
req = urllib.request.Request(url)
@@ -74,14 +73,21 @@ def get_commit_hash_for_nightly(date_str):
7473
commit_msg = commit.get("commit", {}).get("message", "")
7574
# Check if the first line of commit message matches
7675
first_line = commit_msg.split("\n")[0].strip()
77-
if first_line == target_title or first_line.startswith(f"{date_str} nightly"):
78-
return commit["sha"]
76+
if first_line.startswith(f"{date_str} nightly"):
77+
return extract_hash_from_title(first_line)
7978

8079
raise ValueError(
8180
f"Could not find commit with title matching '{target_title}' in nightly branch"
8281
)
8382

8483

84+
def extract_hash_from_title(title):
85+
match = re.search(r"\(([0-9a-fA-F]{7,40})\)", title)
86+
if not match:
87+
raise ValueError(f"Could not extract commit hash from title '{title}'")
88+
return match.group(1)
89+
90+
8591
def update_pytorch_pin(commit_hash):
8692
"""
8793
Update .ci/docker/ci_commit_pins/pytorch.txt with the new commit hash.

.github/workflows/cuda.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test ExecuTorch CUDA Build Compatibility
22
# This workflow tests whether ExecuTorch can be successfully built with CUDA support
33
# across different CUDA versions (12.6, 12.8, 12.9) using the command:
4-
# CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON" ./install_executorch.sh
4+
# ./install_executorch.sh
55
#
66
# Note: ExecuTorch automatically detects the system CUDA version using nvcc and
77
# installs the appropriate PyTorch wheel. No manual CUDA/PyTorch installation needed.
@@ -43,7 +43,7 @@ jobs:
4343
set -eux
4444
4545
# Test ExecuTorch CUDA build - ExecuTorch will automatically detect CUDA version
46-
# and install the appropriate PyTorch wheel when CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON"
46+
# and install the appropriate PyTorch wheel
4747
source .ci/scripts/test-cuda-build.sh "${{ matrix.cuda-version }}"
4848
4949
# This job will fail if any of the CUDA versions fail
@@ -83,7 +83,7 @@ jobs:
8383
script: |
8484
set -eux
8585
86-
PYTHON_EXECUTABLE=python CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON" ./install_executorch.sh
86+
PYTHON_EXECUTABLE=python ./install_executorch.sh
8787
export LD_LIBRARY_PATH=/opt/conda/lib:$LD_LIBRARY_PATH
8888
PYTHON_EXECUTABLE=python source .ci/scripts/test_model.sh "${{ matrix.model }}" cmake cuda
8989
@@ -110,7 +110,7 @@ jobs:
110110
set -eux
111111
112112
echo "::group::Setup ExecuTorch"
113-
CMAKE_ARGS="-DEXECUTORCH_BUILD_CUDA=ON" ./install_executorch.sh
113+
./install_executorch.sh
114114
echo "::endgroup::"
115115
116116
echo "::group::Setup Huggingface"

.github/workflows/lint.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,28 @@ jobs:
143143
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
144144
timeout: 90
145145
script: |
146-
FILES_NEEDS_FORMAT=$(/opt/google-java-format -n \
147-
extension/android/executorch_android/src/main/java/org/pytorch/executorch/*.java \
148-
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm/*.java \
149-
extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations/*.java \
150-
extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch/*.java \
151-
extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench/*.java \
152-
extension/benchmark/android/benchmark/app/src/androidTest/java/org/pytorch/minibench/*.java)
146+
FILES_NEEDS_FORMAT=$(find extension/android/executorch_android/src/main/java/org/pytorch/executorch \
147+
extension/android/executorch_android/src/main/java/org/pytorch/executorch/extension/llm \
148+
extension/android/executorch_android/src/main/java/org/pytorch/executorch/annotations \
149+
extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch \
150+
extension/benchmark/android/benchmark/app/src/main/java/org/pytorch/minibench \
151+
extension/benchmark/android/benchmark/app/src/androidTest/java/org/pytorch/minibench \
152+
-type f -name "*.java" 2>/dev/null | \
153+
xargs -r /opt/google-java-format -n)
154+
153155
if [ -n "$FILES_NEEDS_FORMAT" ]; then
154-
echo "Warning: The following files need formatting. Please use google-java-format."
155-
echo "Use a binary from https://github.com/google/google-java-format/releases/"
156-
echo "For example:"
157-
echo "wget https://github.com/google/google-java-format/releases/download/v1.23.0/google-java-format_linux-x86-64"
158-
echo "chmod +x google-java-format_linux-x86-64"
159-
echo "./google-java-format_linux-x86-64 -i $FILES_NEEDS_FORMAT"
156+
echo "Warning: The following files need formatting:"
157+
echo "$FILES_NEEDS_FORMAT"
158+
echo ""
159+
echo "Please use google-java-format from https://github.com/google/google-java-format/releases/"
160+
echo ""
161+
echo "To fix, run one of these commands:"
162+
echo " # Using xargs (recommended):"
163+
echo " find <paths> -type f -name '*.java' | xargs google-java-format -i"
164+
echo ""
165+
echo " # Or format specific files:"
166+
echo "$FILES_NEEDS_FORMAT" | while IFS= read -r file; do
167+
echo " google-java-format -i \"$file\""
168+
done
160169
exit 1
161170
fi

.github/workflows/pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ jobs:
892892
# Install test requirements
893893
pip install -r backends/nxp/requirements-tests-pypi.txt
894894
pip install -r backends/nxp/requirements-tests-eiq.txt
895+
PYTHON_EXECUTABLE=python bash examples/nxp/setup.sh
895896
896897
# Run pytest
897898
PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ outputs = method.execute([torch.randn(1, 3, 224, 224)])
104104

105105
Module module("model.pte");
106106
auto tensor = make_tensor_ptr({2, 2}, {1.0f, 2.0f, 3.0f, 4.0f});
107-
auto outputs = module.forward({tensor});
107+
auto outputs = module.forward(tensor);
108108
```
109109
110110
**[Swift (iOS)](https://docs.pytorch.org/executorch/main/ios-section.html)**
111111
```swift
112+
import ExecuTorch
113+
112114
let module = Module(filePath: "model.pte")
113-
let input = Tensor<Float>([1.0, 2.0, 3.0, 4.0])
114-
let outputs: [Value] = try module.forward([input])
115+
let input = Tensor<Float>([1.0, 2.0, 3.0, 4.0], shape: [2, 2])
116+
let outputs = try module.forward(input)
115117
```
116118

117119
**[Kotlin (Android)](https://docs.pytorch.org/executorch/main/android-section.html)**
@@ -151,6 +153,8 @@ runner->generate("Hello, how are you?", config);
151153
152154
**[Swift (iOS)](https://docs.pytorch.org/executorch/main/llm/run-on-ios.html)**
153155
```swift
156+
import ExecuTorchLLM
157+
154158
let runner = TextRunner(modelPath: "llama.pte", tokenizerPath: "tiktoken.bin")
155159
try runner.generate("Hello, how are you?", Config {
156160
$0.sequenceLength = 128

backends/aoti/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2626
find_package_torch()
2727

2828
# Common AOTI functionality - combines all AOTI common components
29-
set(_aoti_common_sources aoti_model_container.cpp common_shims.cpp)
29+
set(_aoti_common_sources common_shims.cpp)
3030
add_library(aoti_common STATIC ${_aoti_common_sources})
3131
target_include_directories(
3232
aoti_common

0 commit comments

Comments
 (0)