Running LLMs on Haiku

Good day,

I was trying a different approach, but haven’t succeeded yet. All just Python stuff, and found, as others, the issues with PyPi packages installation through pip, where many related packages are not able to be installed. Some,like numpy, are available in HaikuDepot, but others not. Usually, what I get when I try to install some Python modules related to this is:

ERROR: Could not find a version that satisfies the requirement ‘put module name here’ (from versions: none)
ERROR: No matching distribution found for ‘put module name here’

I installed “GPT4All” through pip without issues. GPT4All is meant to be used to run LLMs locally, without internet connection, thus not sharing any info to anyone. Privacy first. They have a standalone soft available for Win, Mac and Ubuntu linux, that I can run on Arch without issues, also on Fedora. They offer a selection of LLMs to download directly from the app, or you can download another LLM from HuggingFace and check if it works.

There is also LMStudio, another standalone app to run LLMs locally without internet connection, but I haven’t tried it even in Linux.

Back to >python -m pip install gpt4all inside a virtual environment, installation worked:

It doesn’t work yet though. Actually, if fails to download the LLM, but this issue is related to libraries, which I haven’t solved yet. First issue was that the Operating System was not supported. This I solved adding Haiku to the pyllmodel.py file inside the virtual environment:

> def get_c_shared_lib_extension():
>         if system == "Darwin":
>             return "dylib"
>         elif system == "Linux":
>             return "so"
>         elif system == "Windows":
>             return "dll"
>         elif system =="Haiku":
>             return "so"
>         else:
>             raise Exception("Operating System not supported")

And this is the simple attempt I’m running:

> from gpt4all import GPT4All
> model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf")
> # downloads / loads a\4.66GB LLM
> with model.chat_session():
>     print(model.generate(
>        "How can I run LLMs efficiently on my laptop?",   max_tokens=1024))

The issue arises when trying to download the model. I haven’t had much time to deal with it yet. So I’ll let you know if I get any further with it.

I like the idea proposed by @Nexus-6 of having an assistant in Genio, though I must say I never got Genio to work yet to try it with Python and Nim.

The more options we have, the better.

Regards,
RR

Do you mean that you have issues running it?

Isn’t it a wrapper around llama.cpp?

Yeah, because upstream doesn’t provides .whl files as they do for other ( :smiley:) major platforms.

Second best thing, of course, would be if pip install numpy worked out of the box.

While upstreaming patches is ideal, doing so sometimes is way more involved than just adding a small patch to HaikuPorts, and we (or at least I) may lack the focus/will/motivation to do so.

For bigger patches, like the ones for our main Python packages (the ones providing cmd:python3.10, cmd:python3.12, etc.), I have been trying to “iron out” the .patchset files, in hopes to ease future upstreaming… but I doubt I’ll have the will (or skills) to interact with upstream myself.

So… if anyone wants to volunteer to upstream patches… thank you in advance :slight_smile:

In case of numpy, yes, the patch is quite small, but feels like it is not the most elegant solution, just what worked for me after a few tries (would be better to understand why those symbols where getting re-defined in the first place).

Also, on the numpy’s .recipe we do force AVX to be disabled (otherwise 32 bits builds fail). Ideally, that should also be considered when talking to upstream about Haiku support.

I’m not an expert with pip internals, but there must be something wrong with the way we provide the numpy package then.
Pip should recognise pip as already provided but sometimes it does not.
So the solution might be installing the dependencies one by one manually and use pip with the various options like —no-deps, —no-cache-dir and --upgrade-strategy only-if-needed.
Sometimes these don’t work and I don’t know why or the package depends on an older version of numpy we do not provide like with langchain-community which requires v1.26.4 or something like that.
Speaking of it, I gave up on langchain because of this issue. Too much headache…

I’m assuming you meant “pip should recognize that numpy is already provided”.

The issue in “Python world” is that all too frequently, python packages have very stringent (and conflicting with other packages) version requirements for its dependencies.

Say… package A wants numpy < 2.0, while other works with numpy >= 2.0, but not with 2.1, while 2.2.x is OK", and such and such. (I now notice that you indeed found such cases).

Thus why the whole “virtual-environment” thing exists, so each project can install its dependencies isolated from the needs of other projects.

Packages managed by “package managers” do usually not allow for such fine-grained “multiple version” support. Haiku’s PackageKit/pkgman certainly doesn’t.

We can’t install multiple version of say, numpy, side-by-side as a .hpkg file. Thus, you get whatever version we managed to package that works with the rest of the .hpkg files we provide. If that version doesn’t satisfies the requirements for whatever project you’re trying to pip install, then pip will try to do what it does… install from sources whatever version it needs (some might work, other not because they require patches on Haiku).


The “proper solution” to this whole issue is two fold:

  • use isolated installations, via virtual-envs, PEP-582, or whatever works these days in Python land… or by “vendoring” the packages you need for a project you write yourself.
  • get upstream projects to support Haiku, so pip install <project name> works out of the box (we can’t possibly package .hpkg for each thing out there, multiplied by whatever number of Python interpreters there are).

I feel your pain. Trying to maintain the Python related recipes over HaikuPorts has been on many occasion really frustrating.

yes, sorry.

I see Numpy is the major trouble-maker here.
Pandas for example, required by Streamlit, requires in turn Numpy<2.
As already reported, langchain-community requires 1.26.4
And so on…

I don’t think pkgman is the right tool for this job, maybe we could distribute the wheels inside a hpkg in a location where it can be seen by pip and installed from there?
Again I’m not a pip mastermind but could this work?
--find-links=local/dir --no-index

However, the best option would be sending the patches upstream to support Haiku directly.

In the end, yes. All other options require even more effort from the few people that work over HaikuPorts. Thus why I welcomed any help in trying to upstream the patches we already have.

We still will be packaging some “Python things”, so user can just, for example, pkgman install monsterz and enjoy a very nice casual game :slight_smile:, but as in any other OS… for “serious work”, one should not rely on “system-wide / package-manager administered” Python packages. That’s just not how the Python “ecosystem” expects people to work.

This is a bit off topic but worth mentioning, regardless.
I’ve been granted access to the Claude Code research preview and managed to install it on Haiku. In combination with an experimental feature in Genio which embeds a terminal session in a tab, we now have a coding assistant partially integrated in the IDE.

For those who want to experiment with it, here are the steps to get this working:

  1. Install nodejs and npm
  2. install Claude Code with npm install @anthropic-ai/claude-code
  3. Run it with /boot/home/node_modules/.bin/claude
  4. It will try to open a browser with a token in the URL but it will fail, copy the URL and paste into your browser
  5. You will send the request to access the program, just wait one or two days
  6. When you are accepted, follow the instructions in your email going to the Anthropic Console and paste the code in your Claude Code instance
  7. You need to buy some credit for it to work
  8. You are all set up now

7 Likes

How to start that terminal tab on genio? I cant find a way :3

You need to checkout the features/genio-with-terminal-consoleioTab.
You can do it all in Genio by cloning the repo

  1. Project → Open remote project
  2. Checkout the terminal branch
  3. Build and Run the new Genio instance

If you already cloned Genio before, make sure you do these steps:
4. from source control tab → Fetch
5. Git → Pull (optional)
6. Execute step 2 and 3

2 Likes

Getting Cosmopolitan libc working on Haiku should get llamafile working as well, which supports a few LLMs.