Open 4np opened 4 months ago
I believe this is the same issue as #1254
Thank you for filing the feature request.
+1 on Toby's point.
For your comments about
having to install Anaconda / Miniconda as well as lots of Python dependencies isn't ideal as it will clutter up my machine.
Just want to mention that the conda will automatically install all dependencies as a turn-key solution, as well as removing all dependencies, and it won't pollute your existing environment.
Thanks for the feedback and good to know that Conda is quite contained as well. I don't really use Python, other than for now trying to get trained models transformed to CoreML so I can start using them in Xcode.
By the way, Core ML Tools does install when using --platform amd64
and the amd64
/ x86_64
sources, rather than arm64 / aarch64
:
docker build --platform linux/amd64 -t core-ml-tools .
ocker run --rm -it --platform linux/amd64 core-ml-tools
FROM ubuntu:22.04
# Update distribution
RUN apt -y update && apt -y upgrade
# Install essentials
RUN apt -y install git-lfs nano curl zsh make cmake g++ build-essential uuid-dev neofetch
# Change shell from bash to zsh as some of the tools expect zsh
RUN chsh -s /bin/zsh
# Install Git-LFS (large file systems, used by Huggingface)
RUN git lfs install
# Set workdir to /opt
WORKDIR /opt
# Install Oh-My-ZSH for a nicer shell experience
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
# Install Anaconda
#
# Anaconda is a distribution of the Python and R programming languages for scientific computing (data science, machine learning
# applications, large-scale data processing, predictive analytics, etc.), that aims to simplify package management and deployment.
RUN curl https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh -o anaconda.sh
RUN zsh anaconda.sh -b -f -p /opt/anaconda || true
RUN eval "$(/opt/anaconda/bin/conda shell.zsh hook)" && conda init zsh && conda init bash
# Clone CoreML Tools and build from source.
RUN git -C /opt clone https://github.com/apple/coremltools.git
RUN eval "$(/opt/anaconda/bin/conda shell.zsh hook)" && zsh -i coremltools/scripts/build.sh --python=3.11 --dist --debug
RUN eval "$(/opt/anaconda/bin/conda shell.zsh hook)" && pip install $(find /opt/coremltools/build/dist/* -type f -name '*.whl'|head -n 1)
# Setup profile.
RUN echo "neofetch" >> ~/.zshrc
RUN echo "conda info" >> ~/.zshrc
ENTRYPOINT ["/bin/zsh"]
Although Core ML Tools is unfortunately still spitting out errors:
(base) β /models cat test.py
import coremltools
(base) β /models python test.py
scikit-learn version 1.2.2 is not supported. Minimum required version: 0.17. Maximum required version: 1.1.2. Disabling scikit-learn conversion API.
Failed to load _MLModelProxy: No module named 'coremltools.libcoremlpython'
(base) β /models
π± Support an
aarch64
wheelAs an iOS engineer, my goal is to be able to transform trained models for use on device. As I, and probably most iOS engineers, don't use Python, having to install Anaconda / Miniconda as well as lots of Python dependencies isn't ideal as it will clutter up my machine. Even more so as I will only transform on demand, and then maybe for months won't use anything Python.
As such, I started work on a docker container that will set up the required Python tools in a more container fashion. However, there are several hurdles you run into as soon as you do:
Fail to import BlobReader from libmilstoragepython. No module named 'coremltools.libmilstoragepython'
)x86_64
wheel that you cannot use onaarch64
(Docker on Apple Silicon)How can this feature be used?
To run Core ML Tools inside an
aarch64
Docker container on Apple Silicon.Describe alternatives you've considered
The obvious alternative is to install everything directly on my machine, but I'd rather keep things separate so I can more easily clean up my machine.
Additional context
It would be great if Core ML Tools could reliably run inside a Docker container on Apple Silicon to better compartmentalize Python dependencies (a docker container is easily thrown away, whereas a Python dependency tree is harder to clean-up / maintain).
Dockerfile compiling source distribution
Build and run container:
It will fail on
RUN pip install $(ls coremltools/build/dist/*.whl|head -n1)
as there is noaarch64
wheel, onlyx86_64
. However if you run Docker on Apple Silicon, your container will beaarch64
:Dockerile using binary distribution
Build and run container:
Inside the container, try the
test.py
script:It will complain
BlobReader
andBlobWriter
are not available, which you need to actually transform models. However, searching for this issue 'they' say to build Core ML Tools from source which, as seen above, also doesn't work.