Skip to content

Commit ee5b4c5

Browse files
Michael Norrismeta-codesync[bot]
authored andcommitted
Index serialization backward compatibility test (facebookresearch#4706)
Summary: Pull Request resolved: facebookresearch#4706 Test backwards compatibility by checking the conda build of the a Faiss release vs current code (built by cmake). This will run as a Github Action. Reviewed By: alibeklfc Differential Revision: D88085793 fbshipit-source-id: 2b217bf7518fc4ee560fd60e608782dfd5afaff3
1 parent dcb84d1 commit ee5b4c5

9 files changed

Lines changed: 671 additions & 1 deletion

File tree

.github/actions/build_cmake/action.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@ inputs:
1616
description: 'Enable ROCm support.'
1717
required: false
1818
default: OFF
19+
setup_conda:
20+
description: 'Setup miniconda environment.'
21+
required: false
22+
default: 'true'
23+
upload_artifacts:
24+
description: 'Upload test artifacts. Prevents collisions when multiple jobs need to run build_cmake.'
25+
required: false
26+
default: 'true'
1927
runs:
2028
using: composite
2129
steps:
2230
- name: Setup miniconda
31+
if: inputs.setup_conda == 'true'
2332
uses: conda-incubator/setup-miniconda@v3
2433
with:
2534
python-version: '3.11'
@@ -186,7 +195,7 @@ runs:
186195
FAISS_DISABLE_CPU_FEATURES=AVX2 LD_DEBUG=libs $CONDA/bin/python -c "import faiss" 2>&1 | grep faiss.so
187196
LD_DEBUG=libs $CONDA/bin/python -c "import faiss" 2>&1 | grep faiss_avx2.so
188197
- name: Upload test results
189-
if: always()
198+
if: inputs.upload_artifacts == 'true'
190199
uses: actions/upload-artifact@v4
191200
with:
192201
name: test-results-arch=${{ runner.arch }}-opt=${{ inputs.opt_level }}-gpu=${{ inputs.gpu }}-cuvs=${{ inputs.cuvs }}-rocm=${{ inputs.rocm }}

.github/workflows/build-pull-request.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,7 @@ jobs:
144144
fetch-tags: true
145145
- name: Build and Package (conda)
146146
uses: ./.github/actions/build_conda
147+
index-io-backward-compatibility:
148+
needs: linux-x86_64-cmake
149+
name: Index serialization backward compatibility
150+
uses: ./.github/workflows/index-io-backward-compatibility.yml
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: Index serialization backward compatibility test
2+
3+
on:
4+
workflow_call:
5+
6+
env:
7+
OMP_NUM_THREADS: '10'
8+
MKL_THREADING_LAYER: GNU
9+
10+
jobs:
11+
# Scenario 1: CMake writes files, then Conda reads them
12+
cmake-write-conda-read:
13+
name: CMake Write -> Conda Read
14+
runs-on: ubuntu-latest
15+
env:
16+
# run_id does not change if we re-run the job, so this is safe for
17+
# the partway-failure-rerun scenario.
18+
SHARED_DATA_DIR: /tmp/faiss-serialization-backward-compatibility-${{ github.run_id }}-cmake-write
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
# Step 1: Build with CMake and write files
24+
- name: Build with CMake
25+
uses: ./.github/actions/build_cmake
26+
with:
27+
upload_artifacts: 'false'
28+
29+
- name: Create shared data directory
30+
shell: bash
31+
run: |
32+
mkdir -p ${{ env.SHARED_DATA_DIR }}
33+
chmod 777 ${{ env.SHARED_DATA_DIR }}
34+
35+
- name: Run CMake writer (write Faiss index and metadata)
36+
shell: bash
37+
run: |
38+
eval "$(conda shell.bash hook)"
39+
conda activate
40+
$CONDA/bin/python tests/index_io_backward_compatibility/cmake_writer.py ${{ env.SHARED_DATA_DIR }}
41+
42+
- name: Verify files were written
43+
shell: bash
44+
run: |
45+
echo "Files created by CMake build:"
46+
ls -lh ${{ env.SHARED_DATA_DIR }}
47+
48+
# Step 2: Install conda faiss-cpu and read files
49+
- name: Clean cmake-built packages
50+
shell: bash
51+
run: |
52+
eval "$(conda shell.bash hook)"
53+
conda activate
54+
# Remove packages that conflict with faiss-cpu
55+
conda remove -y numpy scipy pytest gflags swig cmake make mkl mkl-devel || true
56+
57+
- name: Install faiss-cpu from pytorch channel
58+
shell: bash
59+
run: |
60+
eval "$(conda shell.bash hook)"
61+
conda activate
62+
conda list
63+
conda install -y -c pytorch faiss-cpu=1.13.1
64+
conda list
65+
66+
- name: Run Conda reader (read Faiss index and verify)
67+
shell: bash
68+
run: |
69+
eval "$(conda shell.bash hook)"
70+
conda activate
71+
python tests/index_io_backward_compatibility/conda_reader.py ${{ env.SHARED_DATA_DIR }}
72+
73+
- name: Upload artifacts from cmake->conda test
74+
if: always()
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: cmake-write-conda-read-data
78+
path: ${{ env.SHARED_DATA_DIR }}
79+
80+
# Scenario 2: Conda writes files, then CMake reads them
81+
conda-write-cmake-read:
82+
name: Conda Write -> CMake Read
83+
runs-on: ubuntu-latest
84+
env:
85+
SHARED_DATA_DIR: /tmp/faiss-serialization-backward-compatibility-${{ github.run_id }}-conda-write
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v4
89+
with:
90+
fetch-depth: 0
91+
fetch-tags: true
92+
93+
# Step 1: Install conda faiss-cpu package and write files
94+
- name: Setup miniconda
95+
uses: conda-incubator/setup-miniconda@v3
96+
with:
97+
python-version: '3.11'
98+
miniforge-version: latest
99+
100+
- name: Install faiss-cpu from pytorch channel
101+
shell: bash
102+
run: |
103+
eval "$(conda shell.bash hook)"
104+
conda activate
105+
# Install pre-built faiss-cpu
106+
conda install -y -c pytorch faiss-cpu=1.13.1
107+
conda list
108+
109+
- name: Create shared data directory
110+
shell: bash
111+
run: |
112+
mkdir -p ${{ env.SHARED_DATA_DIR }}
113+
chmod 777 ${{ env.SHARED_DATA_DIR }}
114+
115+
- name: Run Conda writer (write Faiss index and metadata)
116+
shell: bash
117+
run: |
118+
eval "$(conda shell.bash hook)"
119+
conda activate
120+
python tests/index_io_backward_compatibility/conda_writer.py ${{ env.SHARED_DATA_DIR }}
121+
122+
- name: Verify files were written
123+
shell: bash
124+
run: |
125+
echo "Files created by Conda build:"
126+
ls -lh ${{ env.SHARED_DATA_DIR }}
127+
128+
# Step 2: Rebuild with CMake and read files
129+
- name: Clean conda artifacts
130+
shell: bash
131+
run: |
132+
# Uninstall conda-built faiss to avoid conflicts
133+
eval "$(conda shell.bash hook)"
134+
conda activate
135+
conda uninstall -y faiss-cpu || true
136+
137+
- name: Build with CMake
138+
uses: ./.github/actions/build_cmake
139+
with:
140+
setup_conda: 'false'
141+
upload_artifacts: 'false'
142+
143+
- name: Run CMake reader (read Faiss index and verify)
144+
shell: bash
145+
run: |
146+
eval "$(conda shell.bash hook)"
147+
conda activate
148+
$CONDA/bin/python tests/index_io_backward_compatibility/cmake_reader.py ${{ env.SHARED_DATA_DIR }}
149+
150+
- name: Upload artifacts from conda->cmake test
151+
if: always()
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: conda-write-cmake-read-data
155+
path: ${{ env.SHARED_DATA_DIR }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
"""
7+
Index serialization testing package for Faiss.
8+
9+
This package contains test scripts for validating file I/O compatibility
10+
between cmake-built and conda-built Faiss installations.
11+
"""
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
#!/usr/bin/env python3
7+
"""
8+
CMake Reader: Tests deserialization of conda-written index files using
9+
cmake-built Faiss.
10+
Validates that all index types written by conda can be loaded and searched
11+
without crashing.
12+
"""
13+
14+
import sys
15+
from common_io import read_test_all_files
16+
17+
18+
if __name__ == "__main__":
19+
if len(sys.argv) != 2:
20+
print("Usage: python cmake_reader.py <input_directory>")
21+
sys.exit(1)
22+
23+
input_dir = sys.argv[1]
24+
exit_code = read_test_all_files(
25+
reader="cmake", writer="conda", input_dir=input_dir
26+
)
27+
sys.exit(exit_code)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
#!/usr/bin/env python3
7+
"""
8+
CMake Writer: Tests serialization of all Faiss index types using cmake-built
9+
Faiss.
10+
Creates index files that will be read by conda-built Faiss to test index
11+
serialization backward compatibility.
12+
"""
13+
14+
import sys
15+
from common_io import write_test_all_files
16+
17+
18+
if __name__ == "__main__":
19+
if len(sys.argv) != 2:
20+
print("Usage: python cmake_writer.py <output_directory>")
21+
sys.exit(1)
22+
23+
output_dir = sys.argv[1]
24+
exit_code = write_test_all_files(
25+
writer="cmake", output_dir=output_dir, seed=1234
26+
)
27+
sys.exit(exit_code)

0 commit comments

Comments
 (0)