187 lines
6.4 KiB
YAML
187 lines
6.4 KiB
YAML
name: Tests
|
|
|
|
# TODO: Consider enabling all tests (pytest, applications, etc.) with NNX in the future
|
|
# Currently only basic flow tests run with NNX enabled
|
|
|
|
on:
|
|
push:
|
|
branches: [ master ]
|
|
pull_request:
|
|
release:
|
|
types: [created]
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
run_cpu_tests:
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
backend: [tensorflow, jax, torch, numpy, openvino]
|
|
nnx_enabled: [false]
|
|
include:
|
|
- backend: jax
|
|
nnx_enabled: true
|
|
|
|
container:
|
|
image: python:3.11-slim
|
|
options: --privileged --network host
|
|
|
|
name: ${{ format('Run tests on CPU ({0}{1})', matrix.backend, matrix.nnx_enabled && ', NNX' || '') }}
|
|
runs-on: linux-x86-n2-16
|
|
timeout-minutes: 120
|
|
|
|
env:
|
|
KERAS_HOME: .github/workflows/config/${{ matrix.backend }}
|
|
|
|
steps:
|
|
- name: Install binary dependencies
|
|
# build-essential is the C++ compiler for Torch Dynamo
|
|
# curl, git, gpg are for codecov/codecov-action
|
|
run: |
|
|
apt-get update
|
|
apt-get -y install build-essential
|
|
apt-get -y install curl
|
|
apt-get -y install git
|
|
apt-get -y install gnupg
|
|
git config --global --add safe.directory '*'
|
|
|
|
- name: Checkout ${{ github.ref }}
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Check for changes in keras/src/applications
|
|
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
applications:
|
|
- 'keras/src/applications/**'
|
|
wrappers:
|
|
- 'keras/src/wrappers/**'
|
|
|
|
- name: Install Python dependencies
|
|
run: |
|
|
pip install -r requirements.txt
|
|
pip install --no-deps tf_keras
|
|
|
|
- name: Run Tests for applications
|
|
if: ${{ steps.filter.outputs.applications == 'true' && matrix.nnx_enabled == false }}
|
|
run: |
|
|
pytest keras/src/applications --cov=keras/src/applications --cov-config=pyproject.toml
|
|
coverage xml --include='keras/src/applications/*' -o apps-coverage.xml
|
|
|
|
- name: Upload Coverage for applications
|
|
if: ${{ steps.filter.outputs.applications == 'true' && matrix.nnx_enabled == false }}
|
|
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v5
|
|
with:
|
|
env_vars: PYTHON,KERAS_HOME
|
|
flags: keras.applications,keras.applications-${{ matrix.backend }}
|
|
files: apps-coverage.xml
|
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
fail_ci_if_error: false
|
|
|
|
- name: Run Tests for wrappers
|
|
if: ${{ steps.filter.outputs.wrappers == 'true' && matrix.nnx_enabled == false }}
|
|
run: |
|
|
pytest keras/src/wrappers --cov=keras/src/wrappers --cov-config=pyproject.toml
|
|
coverage xml --include='keras/src/wrappers/*' -o wrappers-coverage.xml
|
|
|
|
- name: Upload Coverage for wrappers
|
|
if: ${{ steps.filter.outputs.wrappers == 'true' && matrix.nnx_enabled == false }}
|
|
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v5
|
|
with:
|
|
env_vars: PYTHON,KERAS_HOME
|
|
flags: keras.wrappers,keras.wrappers-${{ matrix.backend }}
|
|
files: wrappers-coverage.xml
|
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
fail_ci_if_error: false
|
|
|
|
- name: Test integrations
|
|
if: ${{ matrix.backend != 'numpy' && matrix.nnx_enabled == false }}
|
|
run: |
|
|
python integration_tests/import_test.py
|
|
python integration_tests/numerical_test.py
|
|
|
|
- name: Test JAX-specific integrations
|
|
if: ${{ matrix.backend == 'jax' && matrix.nnx_enabled == false }}
|
|
run: |
|
|
python integration_tests/jax_custom_fit_test.py
|
|
|
|
- name: Test basic flow with NNX
|
|
if: ${{ matrix.nnx_enabled == true }}
|
|
env:
|
|
KERAS_NNX_ENABLED: true
|
|
run: |
|
|
python integration_tests/import_test.py
|
|
python integration_tests/basic_full_flow.py
|
|
|
|
- name: Test TF-specific integrations
|
|
if: ${{ matrix.backend == 'tensorflow'}}
|
|
run: |
|
|
python integration_tests/tf_distribute_training_test.py
|
|
python integration_tests/tf_custom_fit_test.py
|
|
|
|
- name: Test Torch-specific integrations
|
|
if: ${{ matrix.backend == 'torch'}}
|
|
run: |
|
|
pytest integration_tests/torch_workflow_test.py
|
|
python integration_tests/torch_custom_fit_test.py
|
|
|
|
- name: Run Tests
|
|
if: ${{ matrix.nnx_enabled == false }}
|
|
run: pytest keras -n auto --dist loadfile --ignore keras/src/applications --ignore keras/src/wrappers --cov=keras --cov-config=pyproject.toml
|
|
|
|
- name: Run Multi-Device Tests
|
|
if: ${{ matrix.backend == 'jax' }}
|
|
run: JAX_NUM_CPU_DEVICES=4 pytest keras -m multi_device --cov=keras --cov-config=pyproject.toml --cov-append
|
|
|
|
- name: Convert Coverage
|
|
if: ${{ matrix.nnx_enabled == false }}
|
|
run: coverage xml --omit='keras/src/applications/*,keras/src/wrappers/*,keras/api' -o core-coverage.xml
|
|
|
|
- name: Upload Coverage
|
|
if: ${{ matrix.nnx_enabled == false }}
|
|
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v5
|
|
with:
|
|
env_vars: PYTHON,KERAS_HOME,KERAS_NNX_ENABLED
|
|
flags: keras,keras-cpu,keras-${{ matrix.backend }}${{ matrix.nnx_enabled == 'true' && '-nnx' || '' }}
|
|
files: core-coverage.xml
|
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
fail_ci_if_error: false
|
|
|
|
format:
|
|
name: Check the code format
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout ${{ github.ref }}
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up Python 3.11
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Get pip cache dir
|
|
id: pip-cache
|
|
run: |
|
|
python -m pip install --upgrade pip setuptools
|
|
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
|
|
|
|
- name: pip cache
|
|
uses: actions/cache@v5
|
|
with:
|
|
path: ${{ steps.pip-cache.outputs.dir }}
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('requirements.txt') }}
|
|
|
|
- name: Install dependencies
|
|
run: pip install -r requirements.txt --upgrade
|
|
|
|
- name: Run pre-commit
|
|
run: pre-commit run --all-files --hook-stage manual
|