Upgrading Python on MacOS for Local LLM Training

Upgrading your local Python to the latest version on macOS in preparation for LLM training. Also adding the latest build of Apple's MLX framework optimized for Apple Silicon. This is the first in a series of posts on my journey of localized model training for analytics and software support.

Upgrading Python on MacOS for Local LLM Training

I'm working on training local LLMs for purpose-driven use in some of the software I'm developing. The two immediate examples I'm working on include:

  1. It would be a great help to have a trained model to discuss theoretical and applied population genetics that has been trained on all my research and my textbook, Applied Population Genetics, and integrated into my GeneticStudio application. The next release of macOS will enable local models to be integrated using the MLX, allowing students to query the bot and ask questions that can be answered with R code or GeneticStudio workflows.
  2. My BackflowStudio application is designed to help professors and teachers develop more learning-objective-oriented lesson plans. This integrated model facilitates the design of properly defined learning objectives and the development of properly aligned syllabi and assessment tools.

There are a few components that need to be installed, and I'll guide you through them here.

Upgrade to the Latest Python

For this, I am assuming you have a basic install of macOS and your current version of Python is:

rodney@Rodneys-Mac-Studio ~ % python3 --version
Python 3.9.6

I'll be using Homebrew to install some components. It can be installed using the following script (you'll have to give your password a couple of times to get it all installed). It's the 'missing package manager' for macOS that makes my Linux instincts feel right.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Add Homebrew to your path via:

eval "$(/opt/homebrew/bin/brew shellenv)"

And then get everything up-to-date in Homebrew, do a

brew update

And then check to see what the latest version of Python is by:

rodney@Rodneys-Mac-Studio ~ % brew info python3
==> python@3.13: stable 3.13.5 (bottled)

Then install it as:

brew install python@3.13

Now, you should have the updated version shown as:

rodney@Rodneys-Mac-Studio ~ % python3 --version
Python 3.13.5

Finally, let's make sure that the things we install in Homebrew are also available by adding their bin location to our path. In the file ~/.zshrc, I added the following lines (I used the alias because I only use Python3).

export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/opt/python@3.13/libexec/bin:$PATH"
alias python=python3
alias pip=pip3

Perfect.

Installing MLX

MLX is an open-source machine learning framework developed by Apple, specifically designed for the Apple silicon architecture and optimized for efficient machine learning on the latest hardware. It utilizes both the unified memory architecture of Apple silicon and the Metal framework for accelerated performance, opening up real possibilities for the research and development of machine learning models on Mac hardware. The open-source documents for MLX are here.

Fortunately for us, installing MLX is a pretty straightforward job.

brew install mlx

There are a couple of additional components that will be installed along with this (and please ensure you have Xcode and its command-line build tools already available as well). These include cmake, fmt, nanobind, nlohmann-json, python-setuptools, and robin-map. Please review these before installation to familiarize yourself with them.

So, let's test to see if it works properly.

>>> import mlx.core as mx
>>> a = mx.array([4,3,2,1])
>>> a.shape
(4,)
>>> a.dtype
mlx.core.int32
>>> b = mx.array([1.0,2.0,3.0,4.0])
>>> b.dtype
mlx.core.float32
>>> c = a + b # not evaluated yet
>>> mx.eval( c ) 
>>> print( c ) 
array([5, 5, 5, 5], dtype=float32)

Everything works, including lazy evaluation. Cool.


Next, I delve into setting up a development environment on the Mac.