Skip to content

Commit 6c57adb

Browse files
committed
feat: add ci test for sentence_transformer example
1 parent a44f6f5 commit 6c57adb

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
# Script to test sentence_transformer example export and validation
11+
# This is used in CI to ensure the sentence_transformer example works correctly
12+
13+
MODEL_NAME="sentence-transformers/all-MiniLM-L6-v2"
14+
EXAMPLE_DIR="examples/models/sentence_transformer"
15+
TEST_OUTPUT_DIR="./sentence_transformer_ci_test"
16+
17+
echo "========================================="
18+
echo "Testing sentence_transformer example"
19+
echo "========================================="
20+
21+
# Navigate to example directory
22+
cd "${EXAMPLE_DIR}"
23+
24+
# Clean up any previous test outputs
25+
rm -rf "${TEST_OUTPUT_DIR}"
26+
mkdir -p "${TEST_OUTPUT_DIR}"
27+
28+
# Install dependencies
29+
echo ""
30+
echo "Installing dependencies..."
31+
pip install transformers tokenizers scikit-learn numpy
32+
33+
# Test 1: Export with XNNPack backend
34+
echo ""
35+
echo "========================================="
36+
echo "Test 1: Export with XNNPack backend"
37+
echo "========================================="
38+
python export_sentence_transformer.py \
39+
--model "${MODEL_NAME}" \
40+
--backend xnnpack \
41+
--output-dir "${TEST_OUTPUT_DIR}/xnnpack_export" \
42+
--max-seq-length 128
43+
44+
# Verify export succeeded
45+
if [ ! -f "${TEST_OUTPUT_DIR}/xnnpack_export/model.pte" ]; then
46+
echo "ERROR: XNNPack export failed - model.pte not found"
47+
exit 1
48+
fi
49+
echo "✓ XNNPack export succeeded"
50+
51+
# Test 2: Export with CPU backend
52+
echo ""
53+
echo "========================================="
54+
echo "Test 2: Export with CPU backend"
55+
echo "========================================="
56+
python export_sentence_transformer.py \
57+
--model "${MODEL_NAME}" \
58+
--backend cpu \
59+
--output-dir "${TEST_OUTPUT_DIR}/cpu_export" \
60+
--max-seq-length 128
61+
62+
# Verify export succeeded
63+
if [ ! -f "${TEST_OUTPUT_DIR}/cpu_export/model.pte" ]; then
64+
echo "ERROR: CPU export failed - model.pte not found"
65+
exit 1
66+
fi
67+
echo "✓ CPU export succeeded"
68+
69+
# Test 3: Validate embeddings (XNNPack)
70+
echo ""
71+
echo "========================================="
72+
echo "Test 3: Validate embeddings (XNNPack)"
73+
echo "========================================="
74+
python compare_embeddings.py \
75+
--model-path "${TEST_OUTPUT_DIR}/xnnpack_export/model.pte" \
76+
--model-name "${MODEL_NAME}" \
77+
--sentences "This is a test sentence for CI validation." \
78+
--max-length 128
79+
80+
echo "✓ XNNPack embedding validation passed"
81+
82+
# Test 4: Validate embeddings (CPU)
83+
echo ""
84+
echo "========================================="
85+
echo "Test 4: Validate embeddings (CPU)"
86+
echo "========================================="
87+
python compare_embeddings.py \
88+
--model-path "${TEST_OUTPUT_DIR}/cpu_export/model.pte" \
89+
--model-name "${MODEL_NAME}" \
90+
--sentences "This is a test sentence for CI validation." \
91+
--max-length 128
92+
93+
echo "✓ CPU embedding validation passed"
94+
95+
# Test 5: Quick benchmark test (reduced iterations for CI)
96+
echo ""
97+
echo "========================================="
98+
echo "Test 5: Quick benchmark test"
99+
echo "========================================="
100+
# Skip full benchmark in CI, just verify the tool runs
101+
python benchmark_backends.py \
102+
--iterations 5 \
103+
--warmup-iterations 2 \
104+
--output-dir "${TEST_OUTPUT_DIR}/benchmark_test" \
105+
--max-seq-length 128
106+
107+
echo "✓ Benchmark tool runs successfully"
108+
109+
# Clean up
110+
echo ""
111+
echo "Cleaning up test outputs..."
112+
rm -rf "${TEST_OUTPUT_DIR}"
113+
114+
echo ""
115+
echo "========================================="
116+
echo "All tests passed! ✓"
117+
echo "========================================="
118+
echo ""
119+
echo "Tests completed:"
120+
echo " ✓ XNNPack export"
121+
echo " ✓ CPU export"
122+
echo " ✓ XNNPack embedding validation"
123+
echo " ✓ CPU embedding validation"
124+
echo " ✓ Benchmark tool execution"
125+
echo ""

0 commit comments

Comments
 (0)