From 286cf9a888f4981374cdae2b65b8fb77a80622dd Mon Sep 17 00:00:00 2001 From: Alex O'Connell Date: Sun, 5 Oct 2025 14:27:29 -0400 Subject: [PATCH] build all cpu backend variants for releases --- .github/workflows/create-release.yml | 32 +++++------------- custom_components/llama_conversation/utils.py | 33 +++---------------- 2 files changed, 14 insertions(+), 51 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 98e933d..a8cab75 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -13,41 +13,27 @@ permissions: jobs: build_wheels: - name: Build wheels for ${{ matrix.arch }}${{ matrix.suffix }} (HA ${{ matrix.home_assistant_image }}) + name: Build wheels for ${{ matrix.arch }} (HA ${{ matrix.home_assistant_image }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - # ARM variants + # ARM64 - home_assistant_image: "aarch64-homeassistant:2025.4.1" arch: "aarch64" + + # 32bit ARM (Raspberry pis) - home_assistant_image: "armhf-homeassistant:2025.4.1" arch: "armhf" - # Base x86 + # x64 - home_assistant_image: "amd64-homeassistant:2025.4.1" - suffix: "noavx" arch: "x86_64" - extra_defines: "-DGGML_SSE42=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_BMI2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF" - # AVX2 and AVX512 - - home_assistant_image: "amd64-homeassistant:2025.4.1" - arch: "x86_64" - extra_defines: "-DGGML_SSE42=ON -DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_BMI2=ON -DGGML_FMA=ON -DGGML_F16C=ON" - - home_assistant_image: "amd64-homeassistant:2025.4.1" - arch: "x86_64" - suffix: "avx512" - extra_defines: "-DGGML_SSE42=ON -DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_BMI2=ON -DGGML_AVX512=ON -DGGML_FMA=ON -DGGML_F16C=ON" - - # 32 bit for older processors, with and without AVX enabled + # 32 bit for older processors - home_assistant_image: "i386-homeassistant:2025.4.1" arch: "i386" - suffix: "noavx" - extra_defines: "-DGGML_SSE42=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_BMI2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF" - - home_assistant_image: "i386-homeassistant:2025.4.1" - arch: "i386" - extra_defines: "-DGGML_SSE42=ON -DGGML_AVX=ON -DGGML_AVX2=OFF -DGGML_BMI2=OFF -DGGML_FMA=ON -DGGML_F16C=ON" steps: - name: Checkout code @@ -104,10 +90,10 @@ jobs: git clone --quiet --recurse-submodules https://github.com/abetlen/llama-cpp-python --branch "v${{ env.EMBEDDED_LLAMA_CPP_PYTHON_VERSION }}" cd llama-cpp-python - tag="homellm${{ matrix.suffix }}" + tag="homellm" sed -i -E "s/^(__version__ *= *\"[0-9]+\.[0-9]+\.[0-9]+)\"/\1+${tag}\"/" llama_cpp/__init__.py - export CMAKE_ARGS="-DLLAVA_BUILD=OFF -DGGML_NATIVE=OFF ${{ matrix.extra_defines }}" + export CMAKE_ARGS="-DLLAVA_BUILD=OFF -DGGML_NATIVE=OFF -DGGML_CPU_ALL_VARIANTS=ON -DGGML_BACKEND_DL=ON" python3 -m build --wheel mv ./dist/*.whl /artifacts @@ -117,7 +103,7 @@ jobs: uses: actions/upload-artifact@v4 with: path: ./artifacts/*.whl - name: artifact_${{ matrix.arch }}${{ matrix.suffix }} + name: artifact_${{ matrix.arch }} release: name: Create Release diff --git a/custom_components/llama_conversation/utils.py b/custom_components/llama_conversation/utils.py index 06b1fe1..f9dd084 100644 --- a/custom_components/llama_conversation/utils.py +++ b/custom_components/llama_conversation/utils.py @@ -211,34 +211,11 @@ def install_llama_cpp_python(config_dir: str): platform_suffix = "x86_64" runtime_version = f"cp{sys.version_info.major}{sys.version_info.minor}" - - instruction_extensions_suffix = "" - if platform_suffix == "x86_64": - instruction_extensions_suffix = "noavx" - - try: - with open("/proc/cpuinfo") as f: - cpu_features = [ line for line in f.readlines() if line.startswith("Features") or line.startswith("flags")][0] - - _LOGGER.debug(cpu_features) - if " avx512f " in cpu_features and " avx512bw " in cpu_features: - instruction_extensions_suffix = "avx512" - elif " avx2 " in cpu_features and \ - " avx " in cpu_features and \ - " f16c " in cpu_features and \ - " fma " in cpu_features and \ - (" sse3 " in cpu_features or " ssse3 " in cpu_features): - instruction_extensions_suffix = "" - except Exception as ex: - _LOGGER.debug(f"Couldn't detect CPU features: {ex}") - # default to the noavx build to avoid crashing home assistant - instruction_extensions_suffix = "noavx" folder = os.path.dirname(__file__) potential_wheels = sorted([ path for path in os.listdir(folder) if path.endswith(f"{platform_suffix}.whl") ], reverse=True) potential_wheels = [ wheel for wheel in potential_wheels if runtime_version in wheel ] - if instruction_extensions_suffix: - potential_wheels = [ wheel for wheel in potential_wheels if f"+homellm{instruction_extensions_suffix}" in wheel ] + potential_wheels = [ wheel for wheel in potential_wheels if f"{EMBEDDED_LLAMA_CPP_PYTHON_VERSION}+homellm" in wheel ] _LOGGER.debug(f"{potential_wheels=}") if len(potential_wheels) > 0: @@ -250,8 +227,8 @@ def install_llama_cpp_python(config_dir: str): return install_package(os.path.join(folder, latest_wheel), **pip_kwargs(config_dir)) # scikit-build-core v0.9.7+ doesn't recognize these builds as musllinux, and just tags them as generic linux - # github_release_url = f"https://github.com/acon96/home-llm/releases/download/v{INTEGRATION_VERSION}/llama_cpp_python-{EMBEDDED_LLAMA_CPP_PYTHON_VERSION}+homellm{instruction_extensions_suffix}-{runtime_version}-{runtime_version}-musllinux_1_2_{platform_suffix}.whl" - github_release_url = f"https://github.com/acon96/home-llm/releases/download/v{INTEGRATION_VERSION}/llama_cpp_python-{EMBEDDED_LLAMA_CPP_PYTHON_VERSION}+homellm{instruction_extensions_suffix}-{runtime_version}-{runtime_version}-linux_{platform_suffix}.whl" + # github_release_url = f"https://github.com/acon96/home-llm/releases/download/v{INTEGRATION_VERSION}/llama_cpp_python-{EMBEDDED_LLAMA_CPP_PYTHON_VERSION}+homellm-{runtime_version}-{runtime_version}-musllinux_1_2_{platform_suffix}.whl" + github_release_url = f"https://github.com/acon96/home-llm/releases/download/v{INTEGRATION_VERSION}/llama_cpp_python-{EMBEDDED_LLAMA_CPP_PYTHON_VERSION}+homellm-{runtime_version}-{runtime_version}-linux_{platform_suffix}.whl" if install_package(github_release_url, **pip_kwargs(config_dir)): _LOGGER.info("llama-cpp-python successfully installed from GitHub release") return True @@ -260,7 +237,7 @@ def install_llama_cpp_python(config_dir: str): if not installed_wrong_version: _LOGGER.error( "Error installing llama-cpp-python. Could not install the binary wheels from GitHub for " + \ - f"platform: {platform_suffix}{instruction_extensions_suffix}, python version: {sys.version_info.major}.{sys.version_info.minor}. " + \ + f"platform: {platform_suffix}, python version: {sys.version_info.major}.{sys.version_info.minor}. " + \ "Please manually build or download the wheels and place them in the `/config/custom_components/llama_conversation` directory." + \ "Make sure that you download the correct .whl file for your platform and python version from the GitHub releases page." ) @@ -268,7 +245,7 @@ def install_llama_cpp_python(config_dir: str): else: _LOGGER.info( "Error installing llama-cpp-python. Could not install the binary wheels from GitHub for " + \ - f"platform: {platform_suffix}{instruction_extensions_suffix}, python version: {sys.version_info.major}.{sys.version_info.minor}. " + \ + f"platform: {platform_suffix}, python version: {sys.version_info.major}.{sys.version_info.minor}. " + \ f"You already have a version of llama-cpp-python ({version('llama-cpp-python')}) installed, however it may not be compatible!" ) time.sleep(0.5) # I still don't know why this is required