add workflows (#17) #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: test-torch | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-test-torch: | |
| name: Test Python ${{ matrix.python-version }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest] | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libnuma-dev gcc g++ make | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| tf_ver=4.52 | |
| npy_ver=2.2 | |
| torch_ver=2.7 | |
| if [ "${{ matrix.python-version }}" = "3.9" ]; then | |
| npy_ver=1.26 | |
| tf_ver=4.40 | |
| torch_ver=2.1 | |
| elif [ "${{ matrix.python-version }}" = "3.10" ]; then | |
| torch_ver=2.3 | |
| elif [ "${{ matrix.python-version }}" = "3.11" ]; then | |
| torch_ver=2.5 | |
| elif [ "${{ matrix.python-version }}" = "3.12" ]; then | |
| torch_ver=2.6 | |
| fi | |
| pip install torch==${torch_ver} --index-url https://download.pytorch.org/whl/cpu | |
| pip install pytest pytest-cov setuptools_scm safetensors transformers==${tf_ver} numpy==${npy_ver} | |
| - name: Build package | |
| run: | | |
| pip install . | |
| - name: Run tests | |
| run: | | |
| cd tests | |
| LIBDIR=`python3 -c "import os; os.chdir('/tmp'); import fastsafetensors; print(os.path.dirname(fastsafetensors.__file__))"` | |
| mkdir -p /tmp/pytest-log | |
| COVERAGE_FILE=.coverage_0 pytest -s --cov=${LIBDIR} test_fastsafetensors.py > /tmp/pytest-log/0.log 2>&1 | |
| COVERAGE_FILE=.coverage_1 CUDA_VISIBLE_DEVICES="" pytest -s --cov=${LIBDIR} test_fastsafetensors.py > /tmp/pytest-log/1.log 2>&1 | |
| COVERAGE_FILE=.coverage_2 torchrun --nnodes=2 --master_addr=0.0.0.0 --master_port=1234 --node_rank=0 --no-python pytest -s --cov=${LIBDIR} test_multi.py > /tmp/pytest-log/2.log 2>&1 & | |
| COVERAGE_FILE=.coverage_3 torchrun --nnodes=2 --master_addr=0.0.0.0 --master_port=1234 --node_rank=1 --no-python pytest -s --cov=${LIBDIR} test_multi.py > /tmp/pytest-log/3.log 2>&1 | |
| coverage combine .coverage_0 .coverage_1 .coverage_2 .coverage_3 | |
| coverage html | |
| mv htmlcov /tmp/pytest-log | |
| - name: Upload Pytest log | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pytest-log-${{ matrix.python-version }} | |
| path: /tmp/pytest-log |