From 0d6a1562cbae17eb41778a4d38adbd37f24db8bf Mon Sep 17 00:00:00 2001 From: Catheriany Date: Mon, 9 Jun 2025 16:43:08 +0800 Subject: [PATCH 1/7] =?UTF-8?q?issue/252=20gguf=E6=B5=8B=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/gguf_test.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/gguf_test.py diff --git a/scripts/gguf_test.py b/scripts/gguf_test.py new file mode 100644 index 000000000..4909fe5aa --- /dev/null +++ b/scripts/gguf_test.py @@ -0,0 +1,56 @@ +import os +import sys +import subprocess +from set_env import set_env + +PROJECT_DIR = os.path.abspath( + os.path.join(os.path.dirname(__file__), "..") +) +os.chdir(PROJECT_DIR) + +def run_tests(test_names, device_type): + failed = [] + base_dir = os.path.join(PROJECT_DIR, "test", "infiniop-test") + + for test in test_names: + + # GGUF 生成阶段 + cmd_gguf = f"python -m test_generate.testcases.{test}" + res = subprocess.run( + cmd_gguf, + shell=True, + cwd=base_dir + ) + if res.returncode != 0: + print(f"[ FAIL ] GGUF generation failed for {test}") + failed.append(test) + continue + + # C++ 测试阶段 + exe = os.path.join(PROJECT_DIR, "build/linux/x86_64/release/infiniop-test") + gguf_path = os.path.join(base_dir, f"{test}.gguf") + cmd_cpp = f"{exe} {gguf_path} {device_type} --warmup 20 --run 1000" + res = subprocess.run( + cmd_cpp, + shell=True, + cwd=PROJECT_DIR + ) + if res.returncode != 0: + print(f"[ FAIL ] C++ test failed for {test}") + failed.append(test) + + return failed + +if __name__ == "__main__": + + set_env() + test_names = ["add", "gemm", "mul", "random_sample", "swiglu", "clip"] + failed = run_tests(test_names, " ".join(sys.argv[1:])) + + if len(failed) == 0: + print("\033[92mAll tests passed!\033[0m") + else: + print("\033[91mThe following tests failed:\033[0m") + for t in failed: + print(f" - {t}") + sys.exit(len(failed)) From c3763f623bb52ab189a597b43acb1cea49732e8f Mon Sep 17 00:00:00 2001 From: Catheriany Date: Mon, 9 Jun 2025 16:53:55 +0800 Subject: [PATCH 2/7] =?UTF-8?q?issue/252=20gguf=E6=B5=8B=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a122289c7..88af8642a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,6 +37,10 @@ jobs: run: | pip install numpy pip install torch + pip install gguf - name: Python Test run: python scripts/python_test.py --cpu + + - name: C++ Test + run: python scripts/gguf_test.py --cpu From 05366c6fd89c54b35a90bd67d88dcd60a64b76f5 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Mon, 9 Jun 2025 17:23:41 +0800 Subject: [PATCH 3/7] =?UTF-8?q?issue/252=20gguf=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 5 +++++ test/infiniop-test/test_generate/testcases/add.py | 2 -- test/infiniop-test/test_generate/testcases/gemm.py | 1 - test/infiniop-test/test_generate/testcases/random_sample.py | 3 --- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 88af8642a..6655cda91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,11 @@ jobs: - name: checkout code uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: Check Format run: | pip install black diff --git a/test/infiniop-test/test_generate/testcases/add.py b/test/infiniop-test/test_generate/testcases/add.py index 113343a4e..70d2c52b3 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 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 From 970d35446910d0aa016588417da4d131c571dab5 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Mon, 9 Jun 2025 17:33:27 +0800 Subject: [PATCH 4/7] =?UTF-8?q?issue/252=20gguf=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6655cda91..0d3c5110d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,6 +25,11 @@ jobs: 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 From 86f64e0e42a5616d62bd4eb7eedac1e47edb0906 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Mon, 9 Jun 2025 17:53:58 +0800 Subject: [PATCH 5/7] =?UTF-8?q?issue/252=20gguf=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/gguf_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/gguf_test.py b/scripts/gguf_test.py index 4909fe5aa..e760d4758 100644 --- a/scripts/gguf_test.py +++ b/scripts/gguf_test.py @@ -25,10 +25,14 @@ def run_tests(test_names, device_type): print(f"[ FAIL ] GGUF generation failed for {test}") failed.append(test) continue - + print("Files in build/linux/x86_64/release:") + print(os.listdir(os.path.join(PROJECT_DIR, "build/linux/x86_64/release"))) + # C++ 测试阶段 exe = os.path.join(PROJECT_DIR, "build/linux/x86_64/release/infiniop-test") gguf_path = os.path.join(base_dir, f"{test}.gguf") + print(f"exe: {exe}, exists: {os.path.isfile(exe)}") + print(f"gguf_path: {gguf_path}, exists: {os.path.isfile(gguf_path)}") cmd_cpp = f"{exe} {gguf_path} {device_type} --warmup 20 --run 1000" res = subprocess.run( cmd_cpp, From b33dcf5509f23a2bd7cbfe829f0bb42558709a31 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Fri, 13 Jun 2025 15:25:56 +0800 Subject: [PATCH 6/7] =?UTF-8?q?issue/252:=20C++=E6=B5=8B=E8=AF=95=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 27 ++++++++++++- scripts/gguf_test.py | 81 +++++++++++++++---------------------- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d3c5110d..aa4fa364b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,5 +52,28 @@ jobs: - name: Python Test run: python scripts/python_test.py --cpu - - name: C++ Test - run: python scripts/gguf_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" + } \ No newline at end of file diff --git a/scripts/gguf_test.py b/scripts/gguf_test.py index e760d4758..a17fa268c 100644 --- a/scripts/gguf_test.py +++ b/scripts/gguf_test.py @@ -2,59 +2,42 @@ 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_tests(test_names, device_type): - failed = [] - base_dir = os.path.join(PROJECT_DIR, "test", "infiniop-test") - for test in test_names: +PROJECT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +os.chdir(PROJECT_DIR) - # GGUF 生成阶段 - cmd_gguf = f"python -m test_generate.testcases.{test}" - res = subprocess.run( - cmd_gguf, - shell=True, - cwd=base_dir - ) - if res.returncode != 0: - print(f"[ FAIL ] GGUF generation failed for {test}") - failed.append(test) - continue - print("Files in build/linux/x86_64/release:") - print(os.listdir(os.path.join(PROJECT_DIR, "build/linux/x86_64/release"))) - - # C++ 测试阶段 +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_path = os.path.join(base_dir, f"{test}.gguf") - print(f"exe: {exe}, exists: {os.path.isfile(exe)}") - print(f"gguf_path: {gguf_path}, exists: {os.path.isfile(gguf_path)}") - cmd_cpp = f"{exe} {gguf_path} {device_type} --warmup 20 --run 1000" - res = subprocess.run( - cmd_cpp, - shell=True, - cwd=PROJECT_DIR - ) - if res.returncode != 0: - print(f"[ FAIL ] C++ test failed for {test}") - failed.append(test) - - return failed - -if __name__ == "__main__": + 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() - test_names = ["add", "gemm", "mul", "random_sample", "swiglu", "clip"] - failed = run_tests(test_names, " ".join(sys.argv[1:])) + 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 len(failed) == 0: - print("\033[92mAll tests passed!\033[0m") - else: - print("\033[91mThe following tests failed:\033[0m") - for t in failed: - print(f" - {t}") - sys.exit(len(failed)) +if __name__ == "__main__": + main() \ No newline at end of file From b7982c92f319a14493c7178b11e2a74ac2165798 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Fri, 4 Jul 2025 10:08:02 +0800 Subject: [PATCH 7/7] =?UTF-8?q?issue/252:=20=E6=A0=BC=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 4 ++-- scripts/gguf_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa4fa364b..e22c7015f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: - name: Python Test run: python scripts/python_test.py --cpu - - name: Gguf Generation Test + - name: GGUF Generation Test run: python scripts/gguf_test.py --mode gguf - name: C++ Test on Linux @@ -76,4 +76,4 @@ jobs: $tests = @("add","gemm","mul","random_sample","swiglu","clip") foreach ($t in $tests) { & $exe "$base\$t.gguf" "--cpu" "--warmup" "0" "--run" "0" - } \ No newline at end of file + } diff --git a/scripts/gguf_test.py b/scripts/gguf_test.py index a17fa268c..c882e492e 100644 --- a/scripts/gguf_test.py +++ b/scripts/gguf_test.py @@ -40,4 +40,4 @@ def main(): sys.exit(1) if __name__ == "__main__": - main() \ No newline at end of file + main()