build.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. name: CI
  2. on:
  3. push:
  4. branches: [main, master]
  5. paths:
  6. - '**/*.cpp'
  7. - '**/*.h'
  8. - '**/*.hpp'
  9. - '**/CMakeLists.txt'
  10. - '.github/workflows/**'
  11. pull_request:
  12. types: [opened, synchronize, reopened]
  13. workflow_dispatch:
  14. concurrency:
  15. group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  16. cancel-in-progress: true
  17. env:
  18. # HuggingFace model info
  19. HF_MODEL_REPO: GaboxR67/MelBandRoformers
  20. HF_CHECKPOINT_PATH: melbandroformers/vocals/voc_fv6.ckpt
  21. HF_CONFIG_PATH: melbandroformers/vocals/voc_gabox.yaml
  22. # Music-Source-Separation-Training repo
  23. MSST_REPO: https://github.com/ZFTurbo/Music-Source-Separation-Training.git
  24. jobs:
  25. # ===========================================================================
  26. # Prepare: Generate test data (runs once, shared via artifacts)
  27. # ===========================================================================
  28. prepare-test-data:
  29. runs-on: ubuntu-latest
  30. steps:
  31. - name: Checkout
  32. uses: actions/checkout@v4
  33. - name: Setup Python
  34. uses: actions/setup-python@v5
  35. with:
  36. python-version: '3.11'
  37. - name: Clone MSST Repository
  38. run: git clone --depth 1 ${{ env.MSST_REPO }} msst
  39. - name: Install Dependencies
  40. run: |
  41. pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
  42. # Filter out wxPython and PyAudio from requirements
  43. sed -i '/wxPython/d' msst/requirements.txt
  44. sed -i '/PyAudio/d' msst/requirements.txt
  45. pip install -r msst/requirements.txt
  46. pip install huggingface_hub scipy soundfile gguf librosa ml_collections einops pyyaml
  47. - name: Download Model from HuggingFace
  48. env:
  49. HF_TOKEN: ${{ secrets.HF_TOKEN }}
  50. run: |
  51. python -c "
  52. from huggingface_hub import hf_hub_download
  53. import os
  54. token = os.environ.get('HF_TOKEN') or None
  55. hf_hub_download('${{ env.HF_MODEL_REPO }}', '${{ env.HF_CHECKPOINT_PATH }}',
  56. local_dir='./model', token=token)
  57. hf_hub_download('${{ env.HF_MODEL_REPO }}', '${{ env.HF_CONFIG_PATH }}',
  58. local_dir='./model', token=token)
  59. "
  60. - name: Generate Test Audio
  61. run: |
  62. python -c "
  63. import numpy as np
  64. import scipy.io.wavfile as wav
  65. sr = 44100
  66. duration = 5.0
  67. t = np.linspace(0, duration, int(sr * duration))
  68. # Create a more complex test signal
  69. left = (np.sin(2 * np.pi * 440 * t) + 0.5 * np.sin(2 * np.pi * 880 * t)) * 0.3
  70. right = (np.sin(2 * np.pi * 660 * t) + 0.5 * np.sin(2 * np.pi * 1320 * t)) * 0.3
  71. stereo = np.stack([left, right], axis=1).astype(np.float32)
  72. wav.write('test_audio.wav', sr, stereo)
  73. print(f'Generated test audio: {len(t)} samples, {duration}s')
  74. "
  75. - name: Generate Test Data
  76. run: |
  77. python scripts/generate_test_data.py \
  78. --model-repo msst \
  79. --audio test_audio.wav \
  80. --checkpoint model/${{ env.HF_CHECKPOINT_PATH }} \
  81. --config model/${{ env.HF_CONFIG_PATH }} \
  82. --output test_data
  83. - name: Convert Model to GGUF
  84. run: |
  85. python scripts/convert_to_gguf.py \
  86. --ckpt model/${{ env.HF_CHECKPOINT_PATH }} \
  87. --config model/${{ env.HF_CONFIG_PATH }} \
  88. --out model.gguf \
  89. --dtype fp16
  90. - name: Upload Test Data Artifact
  91. uses: actions/upload-artifact@v4
  92. with:
  93. name: test-data
  94. path: |
  95. test_data/
  96. model.gguf
  97. test_audio.wav
  98. retention-days: 1
  99. # ===========================================================================
  100. # Build Matrix: Core Platforms + Vulkan
  101. # ===========================================================================
  102. build:
  103. needs: prepare-test-data
  104. strategy:
  105. fail-fast: false
  106. matrix:
  107. include:
  108. # Tier 1: Core Platforms (CPU)
  109. - { name: linux-x64-cpu, os: ubuntu-22.04, backend: cpu, test: true }
  110. - { name: linux-arm64-cpu, os: ubuntu-22.04-arm, backend: cpu, test: true }
  111. - { name: macos-arm64, os: macos-latest, backend: cpu, test: true }
  112. - { name: macos-x64, os: macos-15-intel, backend: cpu, test: true }
  113. - { name: windows-x64-msvc, os: windows-2025, backend: cpu, test: true }
  114. # Tier 2: Vulkan Backend
  115. - { name: linux-vulkan, os: ubuntu-24.04, backend: vulkan, test: true }
  116. - { name: windows-vulkan, os: windows-2025, backend: vulkan, test: true }
  117. runs-on: ${{ matrix.os }}
  118. steps:
  119. - name: Checkout
  120. uses: actions/checkout@v4
  121. - name: Clone GGML
  122. run: git clone --depth 1 https://github.com/ggerganov/ggml.git ggml
  123. - name: Download Test Data
  124. uses: actions/download-artifact@v4
  125. with:
  126. name: test-data
  127. - name: Setup Python
  128. uses: actions/setup-python@v5
  129. with:
  130. python-version: '3.11'
  131. - name: Install Python Dependencies
  132. run: pip install numpy scipy
  133. # ----- Linux Dependencies -----
  134. - name: Install Dependencies (Linux)
  135. if: runner.os == 'Linux'
  136. run: |
  137. sudo apt-get update
  138. sudo apt-get install -y build-essential cmake
  139. - name: Install Vulkan SDK (Linux)
  140. if: matrix.backend == 'vulkan' && runner.os == 'Linux'
  141. run: |
  142. sudo apt-get install -y libvulkan-dev glslc mesa-vulkan-drivers
  143. # ----- macOS Dependencies -----
  144. - name: Install Dependencies (macOS)
  145. if: runner.os == 'macOS'
  146. run: brew install cmake
  147. # ----- Windows Dependencies -----
  148. - name: Install Dependencies (Windows)
  149. if: runner.os == 'Windows'
  150. run: choco install ninja -y
  151. - name: Install Vulkan SDK (Windows)
  152. if: matrix.backend == 'vulkan' && runner.os == 'Windows'
  153. run: |
  154. $VK_VERSION = "1.4.313.2"
  155. curl.exe -o VulkanSDK.exe -L "https://sdk.lunarg.com/sdk/download/${VK_VERSION}/windows/vulkansdk-windows-X64-${VK_VERSION}.exe"
  156. Start-Process -FilePath .\VulkanSDK.exe -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait
  157. Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${VK_VERSION}"
  158. Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${VK_VERSION}\bin"
  159. # ----- Configure -----
  160. - name: Configure (Unix)
  161. if: runner.os != 'Windows'
  162. run: |
  163. cmake -B build \
  164. -DCMAKE_BUILD_TYPE=Release \
  165. -DGGML_DIR=ggml \
  166. -DGGML_CUDA=OFF \
  167. -DGGML_VULKAN=${{ matrix.backend == 'vulkan' && 'ON' || 'OFF' }} \
  168. -DMBR_BUILD_TESTS=ON \
  169. -DMBR_BUILD_CLI=ON
  170. - name: Configure (Windows)
  171. if: runner.os == 'Windows'
  172. run: |
  173. cmake -B build -G "Ninja Multi-Config" `
  174. -DGGML_DIR=ggml `
  175. -DGGML_CUDA=OFF `
  176. -DGGML_VULKAN=${{ matrix.backend == 'vulkan' && 'ON' || 'OFF' }} `
  177. -DMBR_BUILD_TESTS=ON `
  178. -DMBR_BUILD_CLI=ON
  179. # ----- Build -----
  180. - name: Build (Unix)
  181. if: runner.os != 'Windows'
  182. run: cmake --build build --config Release -j $(nproc 2>/dev/null || sysctl -n hw.logicalcpu)
  183. - name: Build (Windows)
  184. if: runner.os == 'Windows'
  185. run: cmake --build build --config Release -j $env:NUMBER_OF_PROCESSORS
  186. # ----- Unit Tests -----
  187. - name: Run Unit Tests
  188. if: matrix.test
  189. env:
  190. MBR_MODEL_PATH: ${{ github.workspace }}/model.gguf
  191. MBR_TEST_DATA_DIR: ${{ github.workspace }}/test_data
  192. run: ctest --test-dir build -C Release --output-on-failure --timeout 300
  193. # ----- CLI Tests -----
  194. - name: Test CLI
  195. if: matrix.test
  196. shell: bash
  197. env:
  198. MBR_MODEL_PATH: ${{ github.workspace }}/model.gguf
  199. run: |
  200. echo "=== CLI Test Suite ==="
  201. # Determine CLI path based on OS
  202. if [[ "$RUNNER_OS" == "Windows" ]]; then
  203. CLI="./build/bin/Release/mel_band_roformer-cli.exe"
  204. else
  205. CLI="./build/mel_band_roformer-cli"
  206. fi
  207. # 1. Test --help
  208. echo "[1/4] Testing --help..."
  209. $CLI --help
  210. # 2. Test with missing arguments (should fail)
  211. echo "[2/4] Testing error handling..."
  212. if $CLI 2>/dev/null; then
  213. echo "ERROR: CLI should fail without arguments"
  214. exit 1
  215. fi
  216. # 3. Generate test audio (short 2-second clip)
  217. echo "[3/4] Generating test audio..."
  218. python3 -c "
  219. import numpy as np
  220. import scipy.io.wavfile as wav
  221. sr = 44100
  222. t = np.linspace(0, 2.0, sr * 2)
  223. stereo = np.stack([np.sin(2*np.pi*440*t), np.sin(2*np.pi*880*t)], axis=1).astype(np.float32) * 0.5
  224. wav.write('cli_test_input.wav', sr, stereo)
  225. "
  226. # 4. Run full inference
  227. echo "[4/4] Running inference..."
  228. $CLI "$MBR_MODEL_PATH" cli_test_input.wav cli_test_output.wav --chunk-size 88200 --overlap 2
  229. # Verify output exists and has reasonable size
  230. if [[ ! -f cli_test_output.wav ]]; then
  231. echo "ERROR: Output file not created"
  232. exit 1
  233. fi
  234. OUTPUT_SIZE=$(stat -c%s cli_test_output.wav 2>/dev/null || stat -f%z cli_test_output.wav)
  235. if [[ $OUTPUT_SIZE -lt 1000 ]]; then
  236. echo "ERROR: Output file too small: $OUTPUT_SIZE bytes"
  237. exit 1
  238. fi
  239. echo "=== CLI Tests Passed ==="
  240. # ----- Upload Artifacts -----
  241. - name: Upload Build Artifacts
  242. uses: actions/upload-artifact@v4
  243. with:
  244. name: build-${{ matrix.name }}
  245. path: |
  246. build/bin/
  247. build/lib*/
  248. build/*.dll
  249. build/*.so
  250. build/*.dylib
  251. build/mel_band_roformer-cli*
  252. build/Release/
  253. retention-days: 7
  254. # ===========================================================================
  255. # CUDA Build: Linux (Compile Only - No GPU for testing)
  256. # ===========================================================================
  257. build-cuda-linux:
  258. runs-on: ubuntu-latest
  259. container: nvidia/cuda:12.6.2-devel-ubuntu24.04
  260. steps:
  261. - name: Install Git
  262. run: |
  263. apt-get update
  264. apt-get install -y git
  265. - name: Checkout
  266. uses: actions/checkout@v4
  267. - name: Clone GGML
  268. run: git clone --depth 1 https://github.com/ggerganov/ggml.git ggml
  269. - name: Install Dependencies
  270. run: |
  271. apt-get install -y cmake build-essential ninja-build
  272. - name: Configure
  273. run: |
  274. ls -ld ggml
  275. cmake -B build -G Ninja \
  276. -DCMAKE_BUILD_TYPE=Release \
  277. -DGGML_DIR=ggml \
  278. -DGGML_CUDA=ON \
  279. -DCMAKE_CUDA_ARCHITECTURES="75;80;86;89" \
  280. -DMBR_BUILD_TESTS=OFF \
  281. -DMBR_BUILD_CLI=ON
  282. - name: Build
  283. run: cmake --build build --config Release -j $(nproc)
  284. - name: Upload Artifacts
  285. uses: actions/upload-artifact@v4
  286. with:
  287. name: build-linux-cuda
  288. path: |
  289. build/bin/
  290. build/lib*/
  291. build/*.so
  292. retention-days: 7
  293. # ===========================================================================
  294. # CUDA Build: Windows (Compile Only - No GPU for testing)
  295. # ===========================================================================
  296. build-cuda-windows:
  297. runs-on: windows-2022
  298. env:
  299. CUDA_VERSION: '12.4'
  300. steps:
  301. - name: Checkout
  302. uses: actions/checkout@v4
  303. - name: Clone GGML
  304. run: git clone --depth 1 https://github.com/ggerganov/ggml.git ggml
  305. - name: Install CUDA Toolkit
  306. run: |
  307. # For CI, use the official CUDA installer approach
  308. curl.exe -o cuda_installer.exe -L "https://developer.download.nvidia.com/compute/cuda/12.4.0/network_installers/cuda_12.4.0_windows_network.exe"
  309. Start-Process -FilePath .\cuda_installer.exe -ArgumentList "-s nvcc_12.4 cudart_12.4 cublas_12.4 cufft_12.4" -Wait -NoNewWindow
  310. Add-Content $env:GITHUB_ENV "CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4"
  311. Add-Content $env:GITHUB_PATH "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin"
  312. - name: Install Ninja
  313. run: choco install ninja -y
  314. - name: Configure
  315. shell: cmd
  316. run: |
  317. call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
  318. cmake -B build -G "Ninja Multi-Config" ^
  319. -DGGML_DIR=ggml ^
  320. -DGGML_CUDA=ON ^
  321. -DCMAKE_CUDA_ARCHITECTURES="75;80;86;89" ^
  322. -DMBR_BUILD_TESTS=OFF ^
  323. -DMBR_BUILD_CLI=ON
  324. - name: Build
  325. run: cmake --build build --config Release -j $env:NUMBER_OF_PROCESSORS
  326. - name: Upload Artifacts
  327. uses: actions/upload-artifact@v4
  328. with:
  329. name: build-windows-cuda
  330. path: |
  331. build/bin/
  332. build/Release/
  333. build/*.dll
  334. retention-days: 7