Tokenizer icon indicating copy to clipboard operation
Tokenizer copied to clipboard

Build ARM64 wheels for macOS

Open guillaumekln opened this issue 2 years ago • 19 comments

Similarly to the recent CTranslate2 work (https://github.com/OpenNMT/CTranslate2/pull/769), we should publish ARM64 wheels for macOS. I had a first look but did not immediately find the correct configuration to cross-compile ICU for ARM64.

Related to https://github.com/OpenNMT/OpenNMT-py/issues/2154.

guillaumekln avatar Apr 14 '22 07:04 guillaumekln

have you built a wheel for ARM64 on macOs? Can't get it to work...

lukasloetkolben avatar Jun 21 '22 07:06 lukasloetkolben

No, there are still no ARM64 wheels for macOS (the issue is still open).

Do you want to help?

guillaumekln avatar Jun 21 '22 07:06 guillaumekln

how could i help? Find a configuration to cross-compile ICU for ARM64 and create a script to build environment for macos arm64?

lukasloetkolben avatar Jun 21 '22 07:06 lukasloetkolben

Hello,

I had built the wheel successfully on a Mac M1 but with the ICU libs installed with brew. If I recall correctly, I had to define the ICU cppflags and ldflags in the command line. Even though they were already in my .zshrc, for some reason they couldn't be picked up from there. As far as I understand, the problem is with the GitHub workflow which builds the ICU libs from source code.

panosk avatar Jun 21 '22 08:06 panosk

Could you share the wheel you had built?

lukasloetkolben avatar Jun 21 '22 08:06 lukasloetkolben

I'll search for it later tonight and share it here.

panosk avatar Jun 21 '22 09:06 panosk

perfect, thank you!

lukasloetkolben avatar Jun 21 '22 11:06 lukasloetkolben

@lukasloetkolben , Here it is, hope it works. pyonmttok-1.31.0-cp39-cp39-macosx_11_0_arm64.whl.zip

panosk avatar Jun 21 '22 18:06 panosk

@lukasloetkolben , Here it is, hope it works. pyonmttok-1.31.0-cp39-cp39-macosx_11_0_arm64.whl.zip

'/Users/panos/miniforge3/lib/libOpenNMTTokenizer.dylib' (no such file)

it doesn't work.. Its referencing to your lib folder.

lukasloetkolben avatar Jun 21 '22 18:06 lukasloetkolben

Ah, right. Try this one then and let me know. pyonmttok-1.31.0-cp39-cp39-macosx_12_0_arm64.whl.zip

panosk avatar Jun 21 '22 18:06 panosk

When i try to import i get this error: Referenced from: /Users/loetkolben/PycharmProjects/inspector_venv/lib/python3.9/site-packages/pyonmttok/_ext.cpython-39-darwin.so Reason: tried: '/usr/local/lib/libOpenNMTTokenizer.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/libOpenNMTTokenizer.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libOpenNMTTokenizer.dylib' (no such file)

While compiling i also get this warning: building for macOS-x86_64 but attempting to link with file built for macOS-arm64

How can i compile it for arm64? Thanks for your help.

lukasloetkolben avatar Jun 21 '22 19:06 lukasloetkolben

My experience with building wheels is little to none. I just built it so I can install and use OpenNMT-tf on my Mac M1. Your error message confuses me though, as this wheel should be for arm64. Can you install it successfully with pip3 install? @guillaumekln should be able to help here.

panosk avatar Jun 21 '22 19:06 panosk

Thanks @panosk for you help. The wheel you shared does not seem to bundle the shared library libOpenNMTTokenizer.dylib. The library can be bundled with the delocate tool.

As far as I understand, the problem is with the GitHub workflow which builds the ICU libs from source code.

Yes. The issue I faced is to figure out how to cross-compile ICU for ARM64 macOS on the x86-64 macOS GitHub runner. It's probably a specific flag or configuration to use, but I did not found it in the 2-3 hours I worked on this issue. Any help or insights would be useful.

You can find what a tried here.

guillaumekln avatar Jun 22 '22 13:06 guillaumekln

I will work on that in the coming days and report back any findings.

panosk avatar Jun 27 '22 21:06 panosk

Hi @panosk, did you have some time to investigate this cross compilation?

guillaumekln avatar Jul 21 '22 11:07 guillaumekln

Hi @guillaumekln , sorry, I got stuck with a ton of other stuff. I will have some time to work on this during the weekend. Will let you know asap.

panosk avatar Jul 21 '22 13:07 panosk

I tried but I couldn't cross-compile ICU on a x86_64 Mac and produce arm64 binaries. It's also discouraging that I can't find related info in Google or SO. Maybe we should post a question is SO?

panosk avatar Aug 01 '22 09:08 panosk

Maybe there is another way. I found that brew can download packages for other architectures: https://github.com/Homebrew/discussions/discussions/2843. So I downloaded the icu4c binaries built for arm64_big_sur and compiled the Tokenizer against this version.

The compilation worked, but I don't know if the final wheel is working.

Can anyone help test the wheels on macOS ARM? Go to this build page, download the "python-wheels" artifact, unzip, and install the appropriate wheel.

guillaumekln avatar Aug 05 '22 10:08 guillaumekln

Hello @guillaumekln ,

I tested it on a Python 3.9 venv and it seems to be working fine!

panosk avatar Aug 06 '22 17:08 panosk