Skip to content

Commit

Permalink
Add a Pip-based CI testing for inference code, with Colab dependencies.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627135153
  • Loading branch information
sdenton4 authored and copybara-github committed May 10, 2024
1 parent 11b849c commit 0ec38c8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
40 changes: 40 additions & 0 deletions .github/install_colab_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding=utf-8
# Copyright 2024 The Perch Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Installs Colab dependencies for CI testing."""

from typing import Sequence

from absl import app
import requests


REQS_FILE = 'https://raw.githubusercontent.com/googlecolab/backend-info/main/pip-freeze.txt'
COLAB_REQS_FILE = '/tmp/colab_reqs.txt'


def main(unused_argv: Sequence[str]) -> None:
got = requests.get(REQS_FILE)
requirements_str = str(got.content, 'utf8')
# Skip the file:// lines, which we do not have access to.
lines = [
ln + '\n' for ln in requirements_str.split('\n') if 'file://' not in ln
]
with open(COLAB_REQS_FILE, 'w') as f:
f.writelines(lines)


if __name__ == '__main__':
app.run(main)
40 changes: 40 additions & 0 deletions .github/workflows/ci_colab_no_jaxtrain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI_colab_no_jaxtrain

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows to run this workflow manually from the Actions tab on GitHub.
workflow_dispatch:

jobs:
test-ubuntu:
name: "test on ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version: ["3.10", "3.11"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Set up Poetry
run: |
pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install Chirp and its dependencies via pip.
run: |
sudo apt-get update
sudo apt-get install libsndfile1 ffmpeg
pip install absl-py
pip install requests
python3 .github/install_colab_deps.py
pip install -r /tmp/colab_reqs.txt
pip install git+https://github.com/google-research/perch.git
- name: Test with unittest
# TODO: Group together jaxtrain tests so they can be easily excluded.
run: poetry run python -m unittest discover -s chirp/inference/tests -p "*test.py"
8 changes: 7 additions & 1 deletion chirp/inference/tests/bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"""Tests for project state handling."""

import os
import tempfile

from absl import flags
from chirp import audio_utils
from chirp.inference import embed_lib
from chirp.inference import tf_examples
Expand All @@ -30,9 +30,15 @@

from absl.testing import absltest

FLAGS = flags.FLAGS


class BootstrapTest(absltest.TestCase):

def setUp(self):
super().setUp()
FLAGS.mark_as_parsed()

def make_wav_files(self, classes, filenames):
# Create a pile of files.
rng = np.random.default_rng(seed=42)
Expand Down

0 comments on commit 0ec38c8

Please sign in to comment.