r/homeassistant • • 2d ago

❓ Support ML models

hello everyone. i want to implement 6 ml models in home assistant for a project in parallel systems.
I want the user to be able to chose what model to use for each room. Is it better to create a container for each model or should i load all 6 in one container and use threads and a state dictionary per room that holds that room's enabled models? The models are interconnected so the output of ml1 is needed as input in ml2 and so on.

0 Upvotes

4 comments sorted by

2

u/diptherial 2d ago

First, I wonder if this would be better posted elsewhere than r/homeassistant ? Seems like it's more about running models, which AFAIK isn't something Home Assistant does natively.

As for your question, I think we need more information about what these models are and what you mean by "containers"; if you mean Docker containers, they'll be isolated within their own process and won't be able to share anything, but if they're truly distinct models that won't matter much. As for the inputs/outputs, this again depends on what these models are, but if they're LLMs you'd typically be ferrying data between them anyway outside of the model runner, so whether there's one container or many of them doesn't matter much.

1

u/Frosty-Piccolo-7889 2d ago

Yes i mean docker containers. The models are ml models that receive data from sensors and then proceed to make a prediction about the room the sensors are in, such as the occupancy, anomalys etc. I am using mqtt to share the data. I asked because i don't know which architecture will be more resource efficient

1

u/diptherial 2d ago

So, threading is only going to help if they do indeed share memory; otherwise, in the era of virtual memory, the differences between running a thread and process are negligible, and if you're implementing this in something that doesn't do threading well (Python with the global interpreter lock, for example) you're likely sacrificing some performance. It sounds like these models are very simple, so I'd do some profiling in an easy-to-implement configuration before you dive into premature optimization.

Docker containers are just fancy processes, so there isn't going to be a huge hit there. Ideally you're running them on a platform where they're 1) not emulated (i.e., your images match your architecture), and 2) where you don't have to run a VM to run the images; both OS X and Windows will still spin up a small Linux VM to host containers in the vast majority of cases.

3

u/cmaxwe 2d ago

You could probably host all the models in a single container. Serve them up via http (FastAPI) and just have a different endpoint for each model/room.

Would hit something like POST http://model-server/model1 with a the data in json and return a json with the results.