Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
mlc-chat - RedPajama-INCITE-Chat-3B on macOS#
MLC (Machine Learning Compilation) on May 22nd 2023: Bringing Open Large Language Models to Consumer Devices
RedPajama on Apple Silicon is achieved by compiling the LLM using Metal for M1/M2 GPUs
The instructions they provided didn’t quite give me all the information I needed to get this to work. Here’s what I did instead.
UPDATE: The official instructions now cover RedPajama-INCITE-Chat-3B as well.
Install Conda#
Their instructions require Conda. I installed miniconda using Homebrew like this:
1brew install --cask minicondaFollowing their initial instructions for Vicuna-7B#
These worked for getting the mlc-chat-vicuna-v1-7b model running on my laptop.
First I created mlc-chat/dist/prebuilt and pulled some models and files from their repos:
1mkdir mlc-chat2cd mlc-chat3mkdir -p dist/prebuilt4# git lfs install - not necessary, I already had Git LFS5cd dist/prebuilt6git clone https://huggingface.co/mlc-ai/mlc-chat-vicuna-v1-7b-q3f16_07git clone https://github.com/mlc-ai/binary-mlc-llm-libs.git lib8cd ../..Then I created a Conda environment and installed some packages into that:
1conda create -n mlc-chat2conda activate mlc-chat3conda install -c mlc-ai -c conda-forge mlc-chat-nightly4conda init zsh5# Quit and re-open terminal6cd mlc-chat7conda activate mlc-chatHaving done this, I could run the Vicuna model like so:
1mlc_chat_cli --local-id vicuna-v1-7b-q3f16_01Use MLC config: "/Users/simon/not-in-backups/mlc-chat/dist/prebuilt/mlc-chat-vicuna-v1-7b-q3f16_0/mlc-chat-config.json"2Use model weights: "/Users/simon/not-in-backups/mlc-chat/dist/prebuilt/mlc-chat-vicuna-v1-7b-q3f16_0/ndarray-cache.json"3Use model library: "/Users/simon/not-in-backups/mlc-chat/dist/prebuilt/lib/vicuna-v1-7b-q3f16_0-metal.so"4Loading model...5You can use the following special commands:6 /help print the special commands7 /exit quit the cli8 /stats print out the latest stats (token/sec)9 /reset restart a fresh chat10 /reload [local_id] reload model "local_id" from disk, or reload the current model if `local_id` is not specified11
12[11:59:01] /Users/catalyst/Workspace/mlc-chat-conda-build/tvm/src/runtime/metal/metal_device_api.mm:165: Intializing Metal device 0, name=Apple M2 Max13USER: Write a rap battle between a pelican and a cheesecake14ASSISTANT: (Verse 1)15I'm a pelican, I'm the king of the sea16I'm a big bird with a big appetite for cheesecake17I'll be taking that piece of cheesecake right off your plate18I'll be feasting on the creamy goodness that's sweet19
20(Chorus)21You'll never see me coming for that slice22I'll be the one taking it all in this lunch time23So beware my sharp beak and talons, I'm coming for that slice24I'll be the one with a big appetite for that cheesecake good25# ...Figuring out how to run RedPajama-INCITE-Chat-3B#
This wasn’t covered in their documentation, but I figured it out through trial and error.
1cd dist/prebuilt2git clone https://huggingface.co/mlc-ai/mlc-chat-RedPajama-INCITE-Chat-3B-v1-q4f16_03cd ../..Now I can run that model like so:
1mlc_chat_cli --local-id RedPajama-INCITE-Chat-3B-v1-q4f16_01Use MLC config: "/Users/simon/not-in-backups/mlc-chat/dist/prebuilt/mlc-chat-RedPajama-INCITE-Chat-3B-v1-q4f16_0/mlc-chat-config.json"2Use model weights: "/Users/simon/not-in-backups/mlc-chat/dist/prebuilt/mlc-chat-RedPajama-INCITE-Chat-3B-v1-q4f16_0/ndarray-cache.json"3Use model library: "/Users/simon/not-in-backups/mlc-chat/dist/prebuilt/lib/RedPajama-INCITE-Chat-3B-v1-q4f16_0-metal.so"4Loading model...5You can use the following special commands:6 /help print the special commands7 /exit quit the cli8 /stats print out the latest stats (token/sec)9 /reset restart a fresh chat10 /reload [local_id] reload model "local_id" from disk, or reload the current model if `local_id` is not specified11
12[12:01:41] /Users/catalyst/Workspace/mlc-chat-conda-build/tvm/src/runtime/metal/metal_device_api.mm:165: Intializing Metal device 0, name=Apple M2 Max13<human>: Write a rap battle between a pelican and a cheesecake14<bot>: Who's got more bounce?15The pelican's got a bounce like no other.16
17Pelicans are known for their unique style,18they're like a flying dunk in the truest form.19They're like a wall in the sky,20a wall that can't be broken.21
22But I'd argue that I've got more bounce23than you could ever imagine,24I'm like a cheesecake with a lot more flavor,25I'm like a cheesecake that'll never quit.26
27I'm like a cheesecake with a lot more flavor,28I'm like a cheesecake that'll never quit,29I'm like a cheesecake that'll never quit.30
31I'm like a cheesecake that'll never quit,32I'm like a cheesecake that'll never quit,33I'm like a cheesecake that'll never quit.