Merge pull request #275 from acon96/release/v0.3.9

Release/v0.3.9
This commit is contained in:
Alex O'Connell
2025-05-26 21:58:23 -04:00
committed by GitHub
9 changed files with 58 additions and 54 deletions

View File

@@ -13,43 +13,41 @@ permissions:
jobs:
build_wheels:
name: Build wheels on ${{ matrix.arch }}${{ matrix.suffix }} (HA ${{ matrix.home_assistant_version }})
name: Build wheels for ${{ matrix.arch }}${{ matrix.suffix }} (HA ${{ matrix.home_assistant_image }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
# ARM variants
- home_assistant_version: "2025.4.1"
- home_assistant_image: "aarch64-homeassistant:2025.4.1"
arch: "aarch64"
- home_assistant_version: "2025.4.1"
- home_assistant_image: "armhf-homeassistant:2025.4.1"
arch: "armhf"
# Base x86
- home_assistant_version: "2025.4.1"
suffix: "-noavx"
arch: "amd64"
extra_defines: "-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF"
- home_assistant_version: "2025.4.1"
arch: "i386"
suffix: "-noavx"
extra_defines: "-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF"
- 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_version: "2025.4.1"
arch: "amd64"
extra_defines: "-DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_FMA=ON -DGGML_F16C=ON"
- home_assistant_version: "2025.4.1"
arch: "amd64"
suffix: "-avx512"
extra_defines: "-DGGML_AVX512=ON -DGGML_FMA=ON -DGGML_F16C=ON"
- home_assistant_version: "2025.4.1"
- 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
- home_assistant_image: "i386-homeassistant:2025.4.1"
arch: "i386"
extra_defines: "-DGGML_AVX=ON -DGGML_AVX2=ON -DGGML_FMA=ON -DGGML_F16C=ON"
- home_assistant_version: "2025.4.1"
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"
suffix: "-avx512"
extra_defines: "-DGGML_AVX512=ON -DGGML_FMA=ON -DGGML_F16C=ON"
extra_defines: "-DGGML_SSE42=ON -DGGML_AVX=ON -DGGML_AVX2=OFF -DGGML_BMI2=OFF -DGGML_FMA=ON -DGGML_F16C=ON"
steps:
- name: Checkout code
@@ -83,7 +81,7 @@ jobs:
with:
arch: none
distro: none
base_image: homeassistant/${{ matrix.arch }}-homeassistant:${{ matrix.home_assistant_version }}
base_image: homeassistant/${{ matrix.home_assistant_image }}
# Create an artifacts directory
setup: |
@@ -106,23 +104,20 @@ 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 }}"
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 }}"
python3 -m build --wheel
ls -la ./dist/
for filename in ./dist/*.whl; do
output_file=$(basename $filename .whl)${{ matrix.suffix }}.whl
echo "$filename -> $output_file"
mv "$filename" "/artifacts/${output_file}";
done;
mv ./dist/*.whl /artifacts
ls -la /artifacts/
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
path: ./artifacts/*.whl
name: artifact_${{ matrix.arch }}${{ matrix.suffix }}_${{ matrix.home_assistant_version }}
name: artifact_${{ matrix.arch }}${{ matrix.suffix }}
release:
name: Create Release

View File

@@ -150,6 +150,7 @@ In order to facilitate running the project entirely on the system where Home Ass
## Version History
| Version | Description |
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| v0.3.9 | Update llama.cpp version, fix installation bugs, fix conversation history not working |
| v0.3.8 | Update llama.cpp, remove think blocks from "thinking" models, fix wheel detection for some Intel CPUs, Fixes for compatibility with latest Home Assistant version (2025.4), other small bug fixes |
| v0.3.7 | Update llama.cpp version to support newer models, Update minimum Home Assistant version to 2024.12.3, Add German In-Context Learning examples, Fix multi-turn use, Fix an issue with webcolors |
| v0.3.6 | Small llama.cpp backend fixes |

View File

@@ -403,5 +403,5 @@ OPTIONS_OVERRIDES = {
},
}
INTEGRATION_VERSION = "0.3.8"
EMBEDDED_LLAMA_CPP_PYTHON_VERSION = "0.3.5"
INTEGRATION_VERSION = "0.3.9"
EMBEDDED_LLAMA_CPP_PYTHON_VERSION = "0.3.9"

View File

@@ -25,7 +25,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady, ConfigEntryError, TemplateError, HomeAssistantError
from homeassistant.helpers import config_validation as cv, intent, template, entity_registry as er, llm, \
area_registry as ar, device_registry as dr, chat_session
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.event import async_track_state_change, async_call_later
from homeassistant.components.sensor import SensorEntity
@@ -148,7 +148,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry):
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback) -> bool:
"""Set up Local LLM Conversation from a config entry."""
# handle updates to the options
@@ -198,6 +198,7 @@ class LocalLLMAgent(ConversationEntity, AbstractConversationAgent):
in_context_examples: list[dict]
_attr_has_entity_name = True
_attr_supports_streaming = False # TODO: add support for backends that can stream
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Initialize the agent."""
@@ -423,7 +424,7 @@ class LocalLLMAgent(ConversationEntity, AbstractConversationAgent):
if remember_num_interactions and len(message_history) > (remember_num_interactions * 2) + 1:
for i in range(0,2):
message_history.pop(1)
# chat_log.content = [_convert_content_back(user_input.agent_id, message_history_entry) for message_history_entry in message_history ]
chat_log.content = [_convert_content_back(user_input.agent_id, message_history_entry) for message_history_entry in message_history ]
if llm_api is None:
# return the output without messing with it if there is no API exposed to the model

View File

@@ -1,7 +1,7 @@
{
"domain": "llama_conversation",
"name": "Local LLM Conversation",
"version": "0.3.8",
"version": "0.3.9",
"codeowners": ["@acon96"],
"config_flow": true,
"dependencies": ["conversation"],

View File

@@ -169,14 +169,14 @@ def install_llama_cpp_python(config_dir: str):
# remap other names for architectures to the names we use
if platform_suffix == "arm64":
platform_suffix = "aarch64"
if platform_suffix == "i386" or platform_suffix == "x86_64":
platform_suffix = "amd64"
if platform_suffix == "i386" or platform_suffix == "amd64":
platform_suffix = "x86_64"
runtime_version = f"cp{sys.version_info.major}{sys.version_info.minor}"
instruction_extensions_suffix = ""
if platform_suffix == "amd64":
instruction_extensions_suffix = "-noavx"
if platform_suffix == "x86_64":
instruction_extensions_suffix = "noavx"
try:
with open("/proc/cpuinfo") as f:
@@ -184,7 +184,7 @@ def install_llama_cpp_python(config_dir: str):
_LOGGER.debug(cpu_features)
if " avx512f " in cpu_features and " avx512bw " in cpu_features:
instruction_extensions_suffix = "-avx512"
instruction_extensions_suffix = "avx512"
elif " avx2 " in cpu_features and \
" avx " in cpu_features and \
" f16c " in cpu_features and \
@@ -194,11 +194,15 @@ def install_llama_cpp_python(config_dir: str):
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"
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}{instruction_extensions_suffix}.whl") ], reverse=True)
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 ]
_LOGGER.debug(f"{potential_wheels=}")
if len(potential_wheels) > 0:
latest_wheel = potential_wheels[0]
@@ -208,8 +212,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}-{runtime_version}-{runtime_version}-musllinux_1_2_{platform_suffix}{instruction_extensions_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}-{runtime_version}-{runtime_version}-linux_{platform_suffix}{instruction_extensions_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}-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"
if install_package(github_release_url, pip_kwargs(config_dir)):
_LOGGER.info("llama-cpp-python successfully installed from GitHub release")
return True

View File

@@ -232,18 +232,18 @@ python3 train.py \
#### Llama 3.2 3B Instruct
```
python3 generate_home_assistant_data.py --train --test --large --sharegpt --language english german french spanish
python3 generate_home_assistant_data.py --train --test --large --sharegpt --language english german french spanish polish
python3 train.py \
--run_name Home-Llama-3.2-3B-rev1 \
--run_name Home-Llama-3.2-3B-rev2 \
--base_model meta-llama/Llama-3.2-3B-Instruct \
--bf16 \
--train_dataset data/home_assistant_train.jsonl \
--train_dataset data/home_assistant_train_large.jsonl \
--test_dataset data/home_assistant_test.jsonl \
--learning_rate 1e-5 --learning_rate_warmup 0.03 --batch_size 64 --epochs 1 \
--micro_batch_size 2 \
--micro_batch_size 1 \
--ctx_size 2048 \
--save_steps 200 --save_total_limit 3 --eval_steps 100 --logging_steps 2
--save_steps 200 --save_total_limit 1 --eval_steps 100 --logging_steps 2
```
### Problems

View File

@@ -9,6 +9,9 @@ git clone --recurse-submodules https://github.com/abetlen/llama-cpp-python --bra
cd llama-cpp-python
pip3 install build
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=ON"
python3 -m build --wheel
cp -f ./dist/*.whl /tmp/dist/

View File

@@ -1,6 +1,6 @@
#!/bin/bash
VERSION_TO_BUILD="v0.3.5"
VERSION_TO_BUILD="v0.3.9"
# make python 11 wheels
# docker run -it --rm \
@@ -18,4 +18,4 @@ VERSION_TO_BUILD="v0.3.5"
docker run -it --rm \
--entrypoint bash \
-v $(pwd):/tmp/dist \
homeassistant/home-assistant:2024.12.3 /tmp/dist/make_wheel.sh $VERSION_TO_BUILD
homeassistant/home-assistant:2025.4.1 /tmp/dist/make_wheel.sh $VERSION_TO_BUILD