Skip to content

Commit 7c412cb

Browse files
authored
Merge branch 'hoist-activation-quant' into persistent-on-hoist
2 parents e544b86 + 4de4b04 commit 7c412cb

94 files changed

Lines changed: 1400 additions & 2470 deletions

File tree

Some content is hidden

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

.ci/scripts/test_backend.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export PYTHON_EXECUTABLE=python
3535

3636
# CMake options to use, in addition to the defaults.
3737
EXTRA_BUILD_ARGS=""
38+
PYTEST_RETRY_ARGS=()
3839

3940
if [[ "$FLOW" == *qnn* ]]; then
4041
# Setup QNN sdk and deps - note that this is a bit hacky due to the nature of the
@@ -57,6 +58,7 @@ if [[ "$FLOW" == *vulkan* ]]; then
5758
fi
5859

5960
if [[ "$FLOW" == *arm* ]]; then
61+
PYTEST_RETRY_ARGS=(--reruns 2 --reruns-delay 1)
6062

6163
# Setup ARM deps.
6264
if [[ "$FLOW" == *vgf* ]]; then
@@ -95,6 +97,6 @@ GOLDEN_DIR="${ARTIFACT_DIR}/golden-artifacts"
9597
export GOLDEN_ARTIFACTS_DIR="${GOLDEN_DIR}"
9698

9799
EXIT_CODE=0
98-
${CONDA_RUN_CMD} pytest -c /dev/null -n auto backends/test/suite/$SUITE/ -m flow_$FLOW --json-report --json-report-file="$REPORT_FILE" || EXIT_CODE=$?
100+
${CONDA_RUN_CMD} pytest -c /dev/null -n auto "${PYTEST_RETRY_ARGS[@]}" backends/test/suite/$SUITE/ -m flow_$FLOW --json-report --json-report-file="$REPORT_FILE" || EXIT_CODE=$?
99101
# Generate markdown summary.
100102
${CONDA_RUN_CMD} python -m executorch.backends.test.suite.generate_markdown_summary_json "$REPORT_FILE" > ${GITHUB_STEP_SUMMARY:-"step_summary.md"} --exit-code $EXIT_CODE

.ci/scripts/test_coreml_bc.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source "${REPO_ROOT}/.ci/scripts/utils.sh"
2323
# Create a conda environment with Python 3.10 for compatibility with old ET versions
2424
# ET 1.0.0 only supports Python >=3.10,<3.13
2525
CONDA_ENV_NAME="coreml_bc_test_env"
26-
conda create -y -n "${CONDA_ENV_NAME}" python=3.10
26+
conda create -y -n "${CONDA_ENV_NAME}" python=3.10 pip packaging
2727

2828
# Use conda run to execute commands in the new environment
2929
CONDA_RUN="conda run --no-capture-output -n ${CONDA_ENV_NAME}"
@@ -69,7 +69,7 @@ git submodule sync --recursive
6969
git submodule update --init --recursive
7070

7171
# Install executorch
72-
${CONDA_RUN} pip install --upgrade pip
72+
${CONDA_RUN} python -m pip install --upgrade pip
7373
${CONDA_RUN} python install_executorch.py
7474

7575
# Step 3: Export model
@@ -129,7 +129,7 @@ git submodule update --init --recursive
129129

130130
# Step 5: Install current version
131131
echo "=== Step 5: Installing current ET version ==="
132-
${CONDA_RUN} pip install --upgrade pip
132+
${CONDA_RUN} python -m pip install --upgrade pip
133133
${CONDA_RUN} python install_executorch.py
134134

135135
# Step 6: Run the old pte file

.ci/scripts/test_huggingface_optimum_model.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import gc
33
import logging
44
import math
5+
import shutil
56
import subprocess
67
import tempfile
8+
import time
79
from pathlib import Path
810
from typing import List
911

@@ -25,6 +27,17 @@
2527
)
2628

2729

30+
EXPORT_RETRIES = 3
31+
32+
33+
def _clear_export_dir(model_dir):
34+
for path in Path(model_dir).iterdir():
35+
if path.is_dir() and not path.is_symlink():
36+
shutil.rmtree(path)
37+
else:
38+
path.unlink()
39+
40+
2841
def cli_export(command, model_dir):
2942
p = Path(model_dir)
3043
if p.exists():
@@ -34,11 +47,19 @@ def cli_export(command, model_dir):
3447
raise Exception(
3548
f"Existing directory {model_dir} is non-empty. Please remove it first."
3649
)
37-
try:
38-
subprocess.run(command, check=True)
39-
print("Export completed successfully.")
40-
except subprocess.CalledProcessError as e:
41-
print(f"Export failed with error: {e}")
50+
51+
for attempt in range(1, EXPORT_RETRIES + 1):
52+
try:
53+
subprocess.run(command, check=True)
54+
print("Export completed successfully.")
55+
return
56+
except subprocess.CalledProcessError as e:
57+
print(f"Export attempt {attempt}/{EXPORT_RETRIES} failed with error: {e}")
58+
if attempt == EXPORT_RETRIES:
59+
raise
60+
if p.exists():
61+
_clear_export_dir(model_dir)
62+
time.sleep(attempt * 10)
4263

4364

4465
def check_causal_lm_output_quality(

.ci/scripts/test_lora.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ cleanup_files() {
3333
rm result*.txt
3434
}
3535

36+
matches_base_response_prefix() {
37+
local output_file="$1"
38+
python - "$output_file" <<'PY'
39+
import pathlib
40+
import re
41+
import sys
42+
43+
text = pathlib.Path(sys.argv[1]).read_text()
44+
pattern = re.compile(
45+
r"^<\|im_start\|>user Calculate 15% of 80\?<\|im_end\|><\|im_start\|>assistant:\n"
46+
r"(?:<think>\n)+"
47+
r"Okay, so I need to calculate 15% of 80\.",
48+
re.MULTILINE,
49+
)
50+
sys.exit(0 if pattern.match(text) else 1)
51+
PY
52+
}
53+
3654
# Hosting lora adapter in personal repo for now.
3755
python -m pip install -q huggingface_hub
3856
HF_ADAPTER_REPO="lucylq/qwen3_06B_lora_math"
@@ -142,6 +160,13 @@ To calculate 15% of 80, we can multiply 80 by 15/100.
142160
So, 15% of 80 is equal to (80 * 15) / 100 = 1200 / 100 = 12.
143161
#### 12
144162
The answer is: 12<|im_end|>"
163+
EXPECTED_QUANT_LORA_ALTERNATE_PREFIX="
164+
<|im_start|>user Calculate 15% of 80?<|im_end|><|im_start|>assistant
165+
To calculate 15% of 80, we can multiply 80 by 15/100.
166+
80 * 15/100 = 12.
167+
So, 15% of 80 is 12.
168+
#### 12
169+
The answer is: 12<|im_end|>"
145170

146171
# Export Quantized PTE, PTD file, no LoRA.
147172
# override base.lora_config=null to avoid creating a lora model
@@ -186,7 +211,7 @@ cmake-out/examples/models/llama/llama_main --model_path=qwen_q.pte --data_paths=
186211
NOW=$(date +"%H:%M:%S")
187212
echo "Finished at ${NOW}"
188213
RESULT=$(cat result.txt)
189-
if [[ "${RESULT}" == "${EXPECTED_QUANT_PREFIX}"* ]]; then
214+
if matches_base_response_prefix result.txt; then
190215
echo "Expected result prefix: ${EXPECTED_QUANT_PREFIX}"
191216
echo "Actual result: ${RESULT}"
192217
echo "Test 3: Success"
@@ -207,12 +232,13 @@ NOW=$(date +"%H:%M:%S")
207232
echo "Finished at ${NOW}"
208233

209234
RESULT=$(cat result.txt)
210-
if [[ "${RESULT}" == "${EXPECTED_QUANT_LORA_PREFIX}"* ]]; then
235+
if [[ "${RESULT}" == "${EXPECTED_QUANT_LORA_PREFIX}"* ]] || [[ "${RESULT}" == "${EXPECTED_QUANT_LORA_ALTERNATE_PREFIX}"* ]]; then
211236
echo "Expected result prefix: ${EXPECTED_QUANT_LORA_PREFIX}"
212237
echo "Actual result: ${RESULT}"
213238
echo "Test 4: Success"
214239
else
215240
echo "Expected result prefix: ${EXPECTED_QUANT_LORA_PREFIX}"
241+
echo "Alternate expected result prefix: ${EXPECTED_QUANT_LORA_ALTERNATE_PREFIX}"
216242
echo "Actual result: ${RESULT}"
217243
echo "Test 4: Failure; results not the same"
218244
cleanup_files

.ci/scripts/test_lora_multimethod.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ cleanup_files() {
3333
rm -f result*.txt
3434
}
3535

36+
matches_base_response_prefix() {
37+
local output_file="$1"
38+
python - "$output_file" <<'PY'
39+
import pathlib
40+
import re
41+
import sys
42+
43+
text = pathlib.Path(sys.argv[1]).read_text()
44+
pattern = re.compile(
45+
r"^<\|im_start\|>user Calculate 15% of 80\?<\|im_end\|><\|im_start\|>assistant:\n"
46+
r"(?:<think>\n)+"
47+
r"Okay, so I need to calculate 15% of 80\.",
48+
re.MULTILINE,
49+
)
50+
sys.exit(0 if pattern.match(text) else 1)
51+
PY
52+
}
53+
3654
# Download LoRA adapter.
3755
python -m pip install -q huggingface_hub
3856
HF_ADAPTER_REPO="lucylq/qwen3_06B_lora_math"
@@ -107,7 +125,7 @@ NOW=$(date +"%H:%M:%S")
107125
echo "Finished at ${NOW}"
108126

109127
RESULT=$(cat result_base.txt)
110-
if [[ "${RESULT}" == "${EXPECTED_BASE_PREFIX}"* ]]; then
128+
if matches_base_response_prefix result_base.txt; then
111129
echo "Test 2 (base_forward): Success"
112130
else
113131
echo "Test 2 (base_forward): Failure"

.ci/scripts/test_model_e2e.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,19 @@ fi
258258
if [ "$AUDIO_URL" != "" ]; then
259259
curl -L $AUDIO_URL -o ${MODEL_DIR}/$AUDIO_FILE
260260
elif [[ "$MODEL_NAME" == *whisper* ]] || [ "$MODEL_NAME" = "voxtral_realtime" ]; then
261-
conda install -y -c conda-forge "ffmpeg<8"
261+
if ! command -v ffmpeg >/dev/null; then
262+
if [ "$(uname -s)" = "Linux" ] && command -v apt-get >/dev/null; then
263+
if [ "$(id -u)" -eq 0 ]; then
264+
apt-get update
265+
apt-get install -y --no-install-recommends ffmpeg
266+
else
267+
sudo apt-get update
268+
sudo apt-get install -y --no-install-recommends ffmpeg
269+
fi
270+
else
271+
conda install -y -c conda-forge ffmpeg
272+
fi
273+
fi
262274
pip install datasets soundfile
263275
# We pushd'd into EXECUTORCH_ROOT above, so torch_pin is importable here.
264276
TORCHCODEC_PKG=$(python -c "from torch_pin import torchcodec_spec; print(torchcodec_spec())")

.github/workflows/_android.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ jobs:
109109
ram-size: 16384M
110110
heap-size: 12288M
111111
force-avd-creation: false
112-
disable-animations: true
113-
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
112+
# The action's built-in animation disabling runs immediately after
113+
# boot and is not retried. Software-emulated boots can briefly drop
114+
# adb there, so scripts/run_android_emulator.sh handles it instead.
115+
disable-animations: false
116+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-metrics
114117
emulator-boot-timeout: 900

.github/workflows/_test_backend.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ jobs:
129129

130130
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
131131
with:
132+
default-packages: ""
132133
ref: ${{ inputs.ref }}
133134
runner: macos-m1-stable
134135
python-version: "3.12"

.github/workflows/_test_cadence.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ jobs:
4545
4646
./install_requirements.sh > /dev/null
4747
pip install -e . --no-build-isolation > /dev/null
48-
pip install beartype later pyre_extensions pytest-xdist
48+
pip install beartype later pyre_extensions pytest-rerunfailures==15.1 pytest-xdist
4949
50-
python -m pytest backends/cadence/aot/tests/ -v -n auto
50+
python -m pytest backends/cadence/aot/tests/ -v -n auto --reruns 2 --reruns-delay 1
5151
5252
test-ops:
5353
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
@@ -66,12 +66,12 @@ jobs:
6666
6767
./install_requirements.sh > /dev/null
6868
pip install -e . --no-build-isolation > /dev/null
69-
pip install beartype later pyre_extensions pytest-xdist
69+
pip install beartype later pyre_extensions pytest-rerunfailures==15.1 pytest-xdist
7070
7171
# Use the pre-built runner from the build job
7272
mkdir -p cmake-out/backends/cadence
7373
cp "${RUNNER_ARTIFACT_DIR}/cadence_runner" cmake-out/backends/cadence/cadence_runner
7474
chmod +x cmake-out/backends/cadence/cadence_runner
7575
7676
export PYTHONPATH="${PYTHONPATH:-}:$(pwd)/backends/cadence/utils/FACTO"
77-
python -m pytest examples/cadence/operators/ -v -n auto
77+
python -m pytest examples/cadence/operators/ -v -n auto --reruns 2 --reruns-delay 1

.github/workflows/_unittest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
macos:
4545
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
4646
with:
47+
default-packages: ""
4748
runner: macos-m1-stable
4849
python-version: '3.11'
4950
submodules: 'recursive'

0 commit comments

Comments
 (0)