diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a122289c7..e22c7015f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,16 @@ jobs: - name: checkout code uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install colorama + - name: Check Format run: | pip install black @@ -37,6 +47,33 @@ jobs: run: | pip install numpy pip install torch + pip install gguf - name: Python Test run: python scripts/python_test.py --cpu + + - name: GGUF Generation Test + run: python scripts/gguf_test.py --mode gguf + + - name: C++ Test on Linux + if: matrix.os == 'ubuntu-latest' + run: | + export LD_LIBRARY_PATH="$PWD/build/linux/x86_64/release:$LD_LIBRARY_PATH" + tests=(add gemm mul random_sample swiglu clip) + for t in "${tests[@]}"; do + build/linux/x86_64/release/infiniop-test \ + test/infiniop-test/${t}.gguf \ + --cpu \ + --warmup 0 \ + --run 0 + done + + - name: C++ Test on Windows + if: matrix.os == 'windows-latest' + run: | + $exe = ".\build\windows\x64\release\infiniop-test.exe" + $base = "test\infiniop-test" + $tests = @("add","gemm","mul","random_sample","swiglu","clip") + foreach ($t in $tests) { + & $exe "$base\$t.gguf" "--cpu" "--warmup" "0" "--run" "0" + } diff --git a/scripts/gguf_test.py b/scripts/gguf_test.py new file mode 100644 index 000000000..c882e492e --- /dev/null +++ b/scripts/gguf_test.py @@ -0,0 +1,43 @@ +import os +import sys +import subprocess +from set_env import set_env +import argparse + + +PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +os.chdir(PROJECT_DIR) + +def run(test, device, mode): + base = os.path.join(PROJECT_DIR, "test", "infiniop-test") + if mode in ("gguf", "all"): + if subprocess.run(f"python -m test_generate.testcases.{test}", + shell=True, cwd=base).returncode: + return f"{test}: gguf failed" + if mode in ("cpp", "all"): + exe = os.path.join(PROJECT_DIR, "build/linux/x86_64/release/infiniop-test") + gguf = os.path.join(base, f"{test}.gguf") + if subprocess.run(f"{exe} {gguf} --{device} --warmup 20 --run 1000", + shell=True, cwd=PROJECT_DIR).returncode: + return f"{test}: cpp failed" + return None + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--device", nargs="?", default="cpu") + parser.add_argument("--mode", choices=["gguf", "cpp", "all"], default="all") + args = parser.parse_args() + + set_env() + tests = ["add", "gemm", "mul", "random_sample", "swiglu", "clip"] + fails = [r for t in tests if (r := run(t, args.device, args.mode))] + + if not fails: + print("\n\033[92mAll tests passed!\033[0m") + sys.exit(0) + print("\033[91mSome tests failed:\033[0m") + for f in fails: print(" -", f) + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/test/infiniop-test/test_generate/testcases/add.py b/test/infiniop-test/test_generate/testcases/add.py index b04ba2042..e94dc7b67 100644 --- a/test/infiniop-test/test_generate/testcases/add.py +++ b/test/infiniop-test/test_generate/testcases/add.py @@ -1,8 +1,6 @@ -from ast import List import numpy as np import gguf from typing import List -from numpy.lib.stride_tricks import as_strided from .. import InfiniopTestWriter, InfiniopTestCase, np_dtype_to_ggml, gguf_strides, contiguous_gguf_strides, process_zero_stride_tensor diff --git a/test/infiniop-test/test_generate/testcases/gemm.py b/test/infiniop-test/test_generate/testcases/gemm.py index fb81c5522..a62986837 100644 --- a/test/infiniop-test/test_generate/testcases/gemm.py +++ b/test/infiniop-test/test_generate/testcases/gemm.py @@ -1,4 +1,3 @@ -from ast import List import numpy as np import gguf from typing import List diff --git a/test/infiniop-test/test_generate/testcases/random_sample.py b/test/infiniop-test/test_generate/testcases/random_sample.py index 15c07f2cc..559428fdb 100644 --- a/test/infiniop-test/test_generate/testcases/random_sample.py +++ b/test/infiniop-test/test_generate/testcases/random_sample.py @@ -1,7 +1,4 @@ -from ast import List import numpy as np -import gguf -from typing import List from .. import InfiniopTestWriter, InfiniopTestCase, np_dtype_to_ggml, gguf_strides