Support building CPU conda packages for macOS and Ubuntu.

This commit is contained in:
Fangjun Kuang 2022-06-02 09:10:05 +08:00
parent 469a108b5d
commit 62da7cc93d
11 changed files with 429 additions and 14 deletions

View File

@ -0,0 +1,111 @@
# Copyright 2021 Xiaomi Corp. (author: Fangjun Kuang)
# See ../../LICENSE for clarification regarding multiple 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.
# refer to https://github.com/actions/starter-workflows/pull/47/files
name: build_conda_macos_cpu
on:
push:
branches:
- nightly-test
tags:
- '*'
env:
KALDIFEAT_BUILD_TYPE: Release
jobs:
generate_build_matrix:
# see https://github.com/pytorch/pytorch/pull/50633
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Generating build matrix
id: set-matrix
run: |
# outputting for debugging purposes
python scripts/github_actions/generate_build_matrix.py
MATRIX=$(python scripts/github_actions/generate_build_matrix.py)
echo "::set-output name=matrix::${MATRIX}"
build_conda_macos_cpu:
needs: generate_build_matrix
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
${{ fromJson(needs.generate_build_matrix.outputs.matrix) }}
steps:
# refer to https://github.com/actions/checkout
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
activate-environment: kaldifeat
- name: Display Python version
shell: bash -l {0}
run: |
python3 -c "import sys; print(sys.version)"
which python3
- name: Install conda dependencies
shell: bash -l {0}
run: |
conda install -y -q anaconda-client
conda install -y -q conda-build
conda install -y -q -c pytorch pytorch=${{ matrix.torch }} cpuonly numpy
find /usr/local/miniconda -name "*mkl_intel_ilp64*"
- name: Display conda info
shell: bash -l {0}
run: |
which conda
conda env list
conda info
- name: Build kaldifeat
shell: bash -l {0}
env:
KALDIFEAT_PYTHON_VERSION: ${{ matrix.python-version}}
KALDIFEAT_TORCH_VERSION: ${{ matrix.torch }}
# KALDIFEAT_CONDA_TOKEN: ${{ secrets.KALDIFEAT_CONDA_TOKEN}}
KALDIFEAT_IS_GITHUB_ACTIONS: 1
KALDIFEAT_IS_FOR_CONDA: 1
run: |
export KALDIFEAT_BUILD_TYPE=$KALDIFEAT_BUILD_TYPE
./scripts/build_conda_cpu.sh
- name: Display generated files
run: |
ls -lh /usr/local/miniconda/envs/kaldifeat/conda-bld/osx-64
- name: Upload generated files
uses: actions/upload-artifact@v2
with:
name: cpu-torch-${{ matrix.torch }}-python-${{ matrix.python-version }}-${{ matrix.os }}
path: /usr/local/miniconda/envs/kaldifeat/conda-bld/osx-64/*.tar.bz2

View File

@ -0,0 +1,110 @@
# Copyright 2021 Xiaomi Corp. (author: Fangjun Kuang)
# See ../../LICENSE for clarification regarding multiple 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.
# refer to https://github.com/actions/starter-workflows/pull/47/files
name: build_conda_ubuntu_cpu
on:
push:
branches:
- nightly-test
tags:
- '*'
env:
KALDIFEAT_BUILD_TYPE: Release
jobs:
generate_build_matrix:
# see https://github.com/pytorch/pytorch/pull/50633
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Generating build matrix
id: set-matrix
run: |
# outputting for debugging purposes
python scripts/github_actions/generate_build_matrix.py
MATRIX=$(python scripts/github_actions/generate_build_matrix.py)
echo "::set-output name=matrix::${MATRIX}"
build_conda_ubuntu_cpu:
needs: generate_build_matrix
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
${{ fromJson(needs.generate_build_matrix.outputs.matrix) }}
steps:
# refer to https://github.com/actions/checkout
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
activate-environment: kaldifeat
- name: Display Python version
shell: bash -l {0}
run: |
python3 -c "import sys; print(sys.version)"
which python3
- name: Install conda dependencies
shell: bash -l {0}
run: |
conda install -y -q anaconda-client
conda install -y -q conda-build
conda install -y -q -c pytorch pytorch=${{ matrix.torch }} cpuonly
- name: Display conda info
shell: bash -l {0}
run: |
which conda
conda env list
conda info
nproc
- name: Build kaldifeat
shell: bash -l {0}
env:
KALDIFEAT_PYTHON_VERSION: ${{ matrix.python-version}}
KALDIFEAT_TORCH_VERSION: ${{ matrix.torch }}
# KALDIFEAT_CONDA_TOKEN: ${{ secrets.KALDIFEAT_CONDA_TOKEN}}
KALDIFEAT_IS_GITHUB_ACTIONS: 1
KALDIFEAT_IS_FOR_CONDA: 1
run: |
export KALDIFEAT_BUILD_TYPE=$KALDIFEAT_BUILD_TYPE
./scripts/build_conda_cpu.sh
- name: Display generated files
run: |
ls -lh /usr/share/miniconda/envs/kaldifeat/conda-bld/linux-64
- name: Upload generated files
uses: actions/upload-artifact@v2
with:
name: cpu-torch-${{ matrix.torch }}-python-${{ matrix.python-version }}-${{ matrix.os }}
path: /usr/share/miniconda/envs/kaldifeat/conda-bld/linux-64/*.tar.bz2

View File

@ -16,10 +16,12 @@
# refer to https://github.com/actions/starter-workflows/pull/47/files
name: build_conda_cuda
name: build_conda_ubuntu_cuda
on:
push:
branches:
- nightly-test
tags:
- '*'
@ -44,11 +46,11 @@ jobs:
MATRIX=$(python scripts/github_actions/generate_build_matrix.py --enable-cuda)
echo "::set-output name=matrix::${MATRIX}"
build_conda_cuda:
build_conda_ubuntu_cuda:
needs: generate_build_matrix
runs-on: ubuntu-18.04
strategy:
fail-fast: false
fail-fast: true
matrix:
${{ fromJson(needs.generate_build_matrix.outputs.matrix) }}
@ -91,7 +93,6 @@ jobs:
run: |
conda install -y -q anaconda-client
conda install -y -q conda-build
conda install -y -q bs4 requests tqdm
conda install -y -q -c pytorch -c conda-forge pytorch=${{ matrix.torch }} cudatoolkit=${{ matrix.cuda }}
- name: Display conda info
@ -115,9 +116,19 @@ jobs:
KALDIFEAT_CUDA_VERSION: ${{ matrix.cuda }}
KALDIFEAT_PYTHON_VERSION: ${{ matrix.python-version}}
KALDIFEAT_TORCH_VERSION: ${{ matrix.torch }}
KALDIFEAT_CONDA_TOKEN: ${{ secrets.KALDIFEAT_CONDA_TOKEN}}
# KALDIFEAT_CONDA_TOKEN: ${{ secrets.KALDIFEAT_CONDA_TOKEN}}
KALDIFEAT_IS_GITHUB_ACTIONS: 1
KALDIFEAT_IS_FOR_CONDA: 1
run: |
export KALDIFEAT_BUILD_TYPE=$KALDIFEAT_BUILD_TYPE
./scripts/build_conda.sh
- name: Display generated files
run: |
ls -lh /usr/share/miniconda/envs/kaldifeat/conda-bld/linux-64
- name: Upload generated files
uses: actions/upload-artifact@v2
with:
name: cuda-${{ matrix.cuda }}-torch-${{ matrix.torch }}-python-${{ matrix.python-version }}-${{ matrix.os }}
path: /usr/share/miniconda/envs/kaldifeat/conda-bld/linux-64/*.tar.bz2

View File

@ -19,7 +19,16 @@ name: Nightly tests macos cpu
on:
push:
branches:
- nightly-test
- nightly-test-2
schedule:
# minute (0-59)
# hour (0-23)
# day of the month (1-31)
# month (1-12)
# day of the week (0-6)
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"
jobs:
generate_build_matrix:

View File

@ -12,13 +12,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
if(NOT APPLE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
set(CMAKE_BUILD_RPATH "$ORIGIN")
endif9)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
set(CMAKE_BUILD_RPATH "$ORIGIN")
set(BUILD_SHARED_LIBS ON)
if(WIN32)

View File

@ -15,6 +15,14 @@ set(kaldifeat_srcs
add_library(kaldifeat_core ${kaldifeat_srcs})
target_link_libraries(kaldifeat_core PUBLIC ${TORCH_LIBRARIES})
if(EXISTS /usr/local/miniconda/envs/kaldifeat/lib/libmkl_intel_ilp64.dylib)
message(STATUS "Linking kaldifeat_core with /usr/local/miniconda/envs/kaldifeat/lib/libmkl_intel_ilp64.dylib")
target_link_libraries(kaldifeat_core PUBLIC "/usr/local/miniconda/envs/kaldifeat/lib/libmkl_intel_ilp64.dylib")
target_link_libraries(kaldifeat_core PUBLIC "-L/usr/local/miniconda/envs/kaldifeat/lib")
else()
message(STATUS "Not linking kaldifeat_core with /usr/local/miniconda/envs/kaldifeat/lib/libmkl_intel_ilp64.dylib")
endif()
target_compile_definitions(kaldifeat_core PUBLIC KALDIFEAT_TORCH_VERSION_MAJOR=${KALDIFEAT_TORCH_VERSION_MAJOR})
target_compile_definitions(kaldifeat_core PUBLIC KALDIFEAT_TORCH_VERSION_MINOR=${KALDIFEAT_TORCH_VERSION_MINOR})

81
scripts/build_conda_cpu.sh Executable file
View File

@ -0,0 +1,81 @@
#!/usr/bin/env bash
#
# Copyright 2021 Xiaomi Corp. (author: Fangjun Kuang)
#
# 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.
# The following environment variables are supposed to be set by users
#
# - KALDIFEAT_TORCH_VERSION
# The PyTorch version. Example:
#
# export KALDIFEAT_TORCH_VERSION=1.7.1
#
# Defaults to 1.7.1 if not set.
#
# - KALDIFEAT_CONDA_TOKEN
# If not set, auto upload to anaconda.org is disabled.
#
# Its value is from https://anaconda.org/kaldifeat/settings/access
# (You need to login as user kaldifeat to see its value)
#
# - KALDIFEAT_BUILD_TYPE
# If not set, defaults to Release.
set -e
export CONDA_BUILD=1
cur_dir=$(cd $(dirname $BASH_SOURCE) && pwd)
kaldifeat_dir=$(cd $cur_dir/.. && pwd)
cd $kaldifeat_dir
export KALDIFEAT_ROOT_DIR=$kaldifeat_dir
echo "KALDIFEAT_ROOT_DIR: $KALDIFEAT_ROOT_DIR"
KALDIFEAT_PYTHON_VERSION=$(python3 -c "import sys; print(sys.version[:3])")
if [ -z $KALDIFEAT_TORCH_VERSION ]; then
echo "env var KALDIFEAT_TORCH_VERSION is not set, defaults to 1.7.1"
KALDIFEAT_TORCH_VERSION=1.7.1
fi
if [ -z $KALDIFEAT_BUILD_TYPE ]; then
echo "env var KALDIFEAT_BUILD_TYPE is not set, defaults to Release"
KALDIFEAT_BUILD_TYPE=Release
fi
export KALDIFEAT_IS_FOR_CONDA=1
# Example value: 3.8
export KALDIFEAT_PYTHON_VERSION
# Example value: 1.7.1
export KALDIFEAT_TORCH_VERSION
export KALDIFEAT_BUILD_TYPE
if [ ! -z $KALDIFEAT_IS_GITHUB_ACTIONS ]; then
export KALDIFEAT_IS_GITHUB_ACTIONS
conda remove -q pytorch
conda clean -q -a
else
export KALDIFEAT_IS_GITHUB_ACTIONS=0
fi
if [ -z $KALDIFEAT_CONDA_TOKEN ]; then
echo "Auto upload to anaconda.org is disabled since KALDIFEAT_CONDA_TOKEN is not set"
conda build --no-test --no-anaconda-upload -c pytorch -c conda-forge ./scripts/conda-cpu/kaldifeat
else
conda build --no-test -c pytorch -c conda-forge --token $KALDIFEAT_CONDA_TOKEN ./scripts/conda-cpu/kaldifeat
fi

View File

@ -0,0 +1,10 @@
# this file is copied from
# https://github.com/pytorch/builder/tree/master/conda/cpuonly
package:
name: cpuonly
version: 1.0
build:
track_features:
- cpuonly
noarch: generic

View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
#
# Copyright 2021 Xiaomi Corp. (author: Fangjun Kuang)
#
# 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.
set -ex
CONDA_ENV_DIR=$CONDA_PREFIX
echo "KALDIFEAT_PYTHON_VERSION: $KALDIFEAT_PYTHON_VERSION"
echo "KALDIFEAT_TORCH_VERSION: $KALDIFEAT_TORCH_VERSION"
echo "KALDIFEAT_BUILD_TYPE: $KALDIFEAT_BUILD_TYPE"
echo "KALDIFEAT_BUILD_VERSION: $KALDIFEAT_BUILD_VERSION"
export KALDIFEAT_CMAKE_ARGS="-DCMAKE_BUILD_TYPE=${KALDIFEAT_BUILD_TYPE}"
export KALDIFEAT_MAKE_ARGS="-j1 VERBOSE=1"
export LIBRARY_PATH="/usr/local/miniconda/envs/kaldifeat/lib":$LIBRARY_PATH
export LD_LIBRARY_PATH="/usr/local/miniconda/envs/kaldifeat/lib":$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH="/usr/local/miniconda/envs/kaldifeat/lib":$DYLD_LIBRARY_PATH
python3 setup.py install --single-version-externally-managed --record=record.txt

View File

@ -0,0 +1,44 @@
package:
name: kaldifeat
version: "1.15.4"
source:
path: "{{ environ.get('KALDIFEAT_ROOT_DIR') }}"
build:
number: 0
string: cpu_py{{ environ.get('KALDIFEAT_PYTHON_VERSION') }}_torch{{ environ.get('KALDIFEAT_TORCH_VERSION') }}
script_env:
- KALDIFEAT_IS_GITHUB_ACTIONS
- KALDIFEAT_TORCH_VERSION
- KALDIFEAT_PYTHON_VERSION
- KALDIFEAT_BUILD_TYPE
- KALDIFEAT_BUILD_VERSION
- KALDIFEAT_IS_FOR_CONDA
requirements:
build:
- {{ compiler('c') }} # [win]
- {{ compiler('cxx') }} # [win]
host:
- cmake=3.18
- python
- pytorch={{ environ.get('KALDIFEAT_TORCH_VERSION') }}
- gcc_linux-64=7 # [linux]
- cpuonly
- numpy
run:
- python
- pytorch={{ environ.get('KALDIFEAT_TORCH_VERSION') }}
- numpy
about:
home: https://github.com/csukuangfj/kaldifeat
license: Apache V2
license_file: LICENSE
summary: Kaldi-compatible feature extraction with PyTorch
description: |
Kaldi-compatible feature extraction with PyTorch,
supporting CUDA, batch processing, chunk processing, and autograd

View File

@ -32,6 +32,6 @@ echo "gcc version: $($CC --version)"
echo "nvcc version: $(nvcc --version)"
export KALDIFEAT_CMAKE_ARGS="-DCMAKE_BUILD_TYPE=${KALDIFEAT_BUILD_TYPE}"
export KALDIFEAT_MAKE_ARGS="-j2"
export KALDIFEAT_MAKE_ARGS="-j3"
python3 setup.py install --single-version-externally-managed --record=record.txt