Annif on Apple silicon

80 views
Skip to first unread message

Uldis Bojars

unread,
Nov 21, 2024, 11:58:04 AM11/21/24
to Annif Users
Hi!

If you are using Annif on Apple silicon Macs, could you share your experience on what works and what doesn't work?

While preparing for the SWIB24 Annif workshop I installed the Docker version of Annif (the existing Docker image worked OK, running Rosetta emulation under the hood). This works but is probably not ideal as emulation would have less performance than running it natively.

Another option - using the Annif tutorial VM under VirtualBox - did not work on Apple silicon.


Best regards,
Uldis Bojārs

Ali

unread,
Nov 22, 2024, 2:10:11 AM11/22/24
to Annif Users
Hi Uldis,

I'm using the docker version of Annif with a M2 Pro (16Gb RAM). I have tested the tfidf, mllm, fasttext and omikuji-bonsai backends without problems, omikuji parabel run out of memory. 

The parameters for the fasttext and omikuji-bonsai were the ones specified on the tutorial and the wiki.

For training I used a vocabulary of 34046 terms and 237574 documents (title + abstract -> 110MB gzip file)

Regarding training time tfidf and mllm took aproximately 5-10min, fasttex ~ 5h and omikuji bonsai ~ 3h

Regards,
   Ali

Osma Suominen

unread,
Nov 22, 2024, 2:20:17 AM11/22/24
to annif...@googlegroups.com
Hi Uldis!

This was a comment from a participant in the previous Annif tutorial
workshop. It seems like the install instructions for Linux in the top
level Annif README file will also work for Mac OS:

> macOS arm64 seems to work well with the basic installation instructions in https://github.com/NatLibFi/Annif/blob/main/README.md . I only had to add pdftotext manually (through brew install poppler).

You could try that too, and report on your findings. If there's anything
that can be done either in the Annif codebase or in the tutorial
materials to make it easier for Apple silicon users, we are very open to
contributions! We just don't have any such hardware in the Annif
development team, so can't easily do testing nor provide "official" support.

-Osa
> --
> You received this message because you are subscribed to the Google
> Groups "Annif Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to annif-users...@googlegroups.com
> <mailto:annif-users...@googlegroups.com>.
> To view this discussion visit
> https://groups.google.com/d/msgid/annif-users/CAJjMrEMqPWnU1x9F6RhdjWY7-n39ODPoGdnsR%3Du_Dc8WUaNmTw%40mail.gmail.com <https://groups.google.com/d/msgid/annif-users/CAJjMrEMqPWnU1x9F6RhdjWY7-n39ODPoGdnsR%3Du_Dc8WUaNmTw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
Osma Suominen
D.Sc. (Tech), Information Systems Specialist
National Library of Finland
P.O. Box 15 (Unioninkatu 36)
00014 HELSINGIN YLIOPISTO
Tel. +358 50 3199529
osma.s...@helsinki.fi
http://www.nationallibrary.fi

Kris De Winter

unread,
Nov 22, 2024, 8:35:45 AM11/22/24
to Annif Users
I can confirm that just installing the python-version in a venv (with or without Anaconda to manage environments) works fine on Apple Silicon.
I think there were a few (solvable) dependency issues you might run in to with some of the backends (it's a long time ago I installed it, don't remember exactly).

Kris

Op vrijdag 22 november 2024 om 08:20:17 UTC+1 schreef osma.s...@helsinki.fi:

Uldis Bojars

unread,
Nov 24, 2024, 3:05:53 PM11/24/24
to Kris De Winter, Annif Users
Hi!

Thanks, everyone, for sharing information on running Annif on Apple silicon.

For now, I am using a local installation of Annif in a virtual environment. Tested it with TF-IDF and it worked fine.

There was one thing that did not work - I could not install the "fasttext" backend because "pip install" was trying to build it from source and there was an error while building this package. Specifically, it was looking for an SDK in a wrong location, resulting in this error message:

Compiling with an SDK that doesn't seem to exist:
      /Applications/Xcode_15.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk

Was anyone able to install the "fasttext-wheel" optional dependency on Apple silicon?

P.S. As a workaround, I may use the option suggested by Ali - running Annif in a Docker container.

Best regards,
Uldis Bojārs


To unsubscribe from this group and stop receiving emails from it, send an email to annif-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/annif-users/a9ab86a2-8e30-41f6-a8a2-5fc6ef913166n%40googlegroups.com.

Alfonso Ali

unread,
Nov 25, 2024, 2:26:48 AM11/25/24
to Annif Users
I had the same experience that Kris mentioned about installing the python-version in a venv. My only problem was with the omikuji backend that even when it install without problems reports the following error:

OSError: cannot load library ....lib/python3.12/site-packages/omikuji/_libomikuji__lib.so....(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

due to the omikuji wheel having no support for the arm64 platform. I solved it by uninstalling the omikuji package and installing it again from source. I first tried with:

brew install rust

but i got the following error:

error[E0282]: type annotations needed for `Box<_>`
...
note: this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` by calling `cargo update`

so, I manually downloaded the package source, extracted it and:

cd omikuji-0.5.1/c-api
cargo update
cd ..
pip install -e .

and tested that it worked by opening a python shell and importing the omikuji package.

I can also confirm that using the python version of annif on macOS gives you a significant difference in performance compared to the docker version.

Regards,
  Alfonso

To unsubscribe from this group and stop receiving emails from it, send an email to annif-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/annif-users/a9ab86a2-8e30-41f6-a8a2-5fc6ef913166n%40googlegroups.com.

Alfonso Ali

unread,
Nov 25, 2024, 2:26:48 AM11/25/24
to Uldis Bojars, Kris De Winter, Annif Users
Hi Uldis,

I installed the fasttext backend using the command listed in the docs (https://github.com/NatLibFi/Annif/wiki/Optional-features-and-dependencies#fasttext-backend) and the fasttext-wheel was installed and worked without any issues:

> pip list | grep fast
fasttext-wheel            0.9.2

I don't recommend using the Docker container anymore, the difference in performance is huge, for example for the fasttext backend using the python version the training took ~12 minutes, using the Docker container it took +5 hours!!

Regards,
  Alfonso

Uldis Bojars

unread,
Nov 27, 2024, 4:11:10 PM11/27/24
to Alfonso Ali, Annif Users
Hi Alfonso,

Thank you for sharing your experience installing Omikuji.

I stumbled upon the same problem (Omikuji wheel having no support for the arm64 platform) and also was not able to just "pip install" it.

I opened a ticket related to this:

Manually building from source, as described in your message, helped.

Best regards,
Uldis


MJ Suhonos

unread,
Dec 11, 2024, 1:36:53 AM12/11/24
to Annif Users
Hi all,

I have been successful in getting Annif working under Apple Silicon (M2).  My configuration looks like so:

1) The UTM app, essentially a GUI for the native Apple Virtualization framework (including VIRTIO)
2) A "minimal" installation of Ubuntu Server for ARM running as a client VM within UTM
3) Annif installed on Ubuntu according to the Development install documentation

It may also be possible to do a basic install as well, but I haven't tested that approach.  Installing packages with pip works as expected, and no building from source required.

Essentially UTM+Ubuntu acts as a shim between MacOS and Linux on the same (aarch64) architecture.  VIRTIO also allows sharing folders from the host system to the guest VM, so I manage all of my Annif files in MacOS, including git operations.

When I want to use Annif, I SSH into the Ubuntu VM and it performs nearly identically to bare metal -- certainly much faster than Docker as discussed above.  Idle memory use is < 500MB, but Annif will happily use all CPU cores (only 4 on the M2) and use as much RAM as the VM is allocated (24GB in my case).  It's such low overhead that I often leave the VM running in the background even when I'm not using it.

Happy to share more information if/as helpful, and hope this is useful for someone.

Best,
MJ

Uldis Bojars

unread,
Feb 9, 2025, 6:38:24 PMFeb 9
to Annif Users
Hi all,

Continuing the discussion about installing Annif on Apple silicon:

When installing Annif (on Apple silicon - macOS 14.7 - Python 3.12) with the "nn" backend, the installation process downgrades Annif from version 1.2.1 to 1.1.0 (probably due to the requirements that cannot be met for 1.2.1):

> uv pip -v install "annif[nn]"
Uninstalled 11 packages in 172ms
Installed 12 packages in 63ms
 - annif==1.2.1
 + annif==1.1.0
 - connexion==3.1.0
 + connexion==3.0.6
 - gunicorn==23.0.0
 + gunicorn==22.0.0
 - huggingface-hub==0.25.2
 + huggingface-hub==0.22.2
 - jsonschema==4.23.0
 + jsonschema==4.21.1
 + lmdb==1.4.1
 - nltk==3.9.1
 + nltk==3.8.1
 - optuna==4.0.0
 + optuna==3.6.2
 - requests==2.32.3
 + requests==2.31.0
 - scikit-learn==1.5.2
 + scikit-learn==1.4.2
 - scipy==1.13.1
 + scipy==1.12.0
 - simplemma==1.1.2
 + simplemma==0.9.1

If the "nn" backend is not specified, Annif 1.2.1 gets installed.

What is the experience of other users of Annif on Apple silicon? Does installing the "nn" backend also downgrade Annif for you? (And how can it be resolved?)

It would be great to be able to use the most recent version of Annif.

P.S. I used "uv" for installing Annif here but the result is the same when installing using regular "pip" as well.

Best regards,
Uldis



Uldis Bojars

unread,
Feb 10, 2025, 5:19:45 AMFeb 10
to Annif Users
Hi,

Additional information about Annif getting downgraded on Apple silicon macOS:

It may be related to compatibility issues with the tensorflow-cpu package:

---
❯ uv pip -v install "annif[nn]"
[...]
DEBUG Searching for a compatible version of tensorflow-cpu (>=2.17.0, <2.18.0)
DEBUG Searching for a compatible version of tensorflow-cpu (>=2.17.0, <2.17.1 | >2.17.1, <2.18.0)
DEBUG Searching for a compatible version of tensorflow-cpu (>2.17.0, <2.17.1 | >2.17.1, <2.18.0)
DEBUG No compatible version found for: tensorflow-cpu
DEBUG Recording unit propagation conflict of tensorflow-cpu from incompatibility of (annif[nn])
DEBUG Searching for a compatible version of annif[nn] (<1.2.1 | >1.2.1, <1.3.0 | >1.3.0)
DEBUG Selecting: annif==1.2.0 [compatible] (annif-1.2.0-py3-none-any.whl)
DEBUG Adding transitive dependency for annif==1.2.0: annif==1.2.0
DEBUG Adding transitive dependency for annif==1.2.0: annif[nn]==1.2.0
DEBUG Searching for a compatible version of annif (==1.2.0)
[...]
DEBUG Adding transitive dependency for annif==1.2.0: tensorflow-cpu>=2.17.0, <2.18.0
DEBUG Recording unit propagation conflict of tensorflow-cpu from incompatibility of (annif[nn])
DEBUG Searching for a compatible version of annif[nn] (<1.2.0 | >1.2.0, <1.2.1 | >1.2.1, <1.3.0 | >1.3.0)
DEBUG Selecting: annif==1.1.0 [compatible] (annif-1.1.0-py3-none-any.whl)
DEBUG Adding transitive dependency for annif==1.1.0: annif==1.1.0
DEBUG Adding transitive dependency for annif==1.1.0: annif[nn]==1.1.0
DEBUG Searching for a compatible version of annif (==1.1.0)
DEBUG Selecting: annif==1.1.0 [compatible] (annif-1.1.0-py3-none-any.whl)
---

Best regards,
Uldis

Reply all
Reply to author
Forward
0 new messages