Skip to content

About

Convert on-device 3B Apple Intelligence foundation models into standard 16-bit GGUF files for native local inference through patched llama.cpp.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apple-AFM7

Apple-AFM7 is a toolkit designed to extract, convert, and run 3B Apple Foundation Models (afm7) in the GGUF format, enabling native local inference through llama.cpp on macOS 26.6.2 (25G83) and newer.

Apple-AFM7 Preview

Overview

macOS stores on-device 3B Apple Intelligence foundation models inside /System/Library/AssetsV2 across 2 Universal Asset Framework (UAF) families, which are GenerativeModels (com_apple_MobileAsset_UAF_FM_GenerativeModels) and CodeLM (com_apple_MobileAsset_UAF_FM_CodeLM), while artifacts/converter.py and artifacts/llama.patch reconstruct and execute both families under the unified 56-layer afm7 architecture in llama.cpp.

Requirements

  • macOS 26.6.2 (25G83) or newer with Apple Intelligence UAF assets present in /System/Library/AssetsV2.
  • A C++17 compiler, git, and cmake to patch and build llama.cpp (or an existing ~/.unsloth/llama.cpp installation from Unsloth Studio).
  • Python 3.10 or newer with numpy installed, where gguf is loaded automatically from ~/.unsloth/llama.cpp/gguf-py, LLAMA_CPP_PATH, or pip.

Usage

1. Clone the Repository

Clone this repository, then enter the project directory to prepare your workspace:

git clone https://github.com/NeaByteLab/Apple-AFM7.git
cd Apple-AFM7

2. Patch and Build llama.cpp

Apply artifacts/llama.patch either to the llama.cpp runtime bundled with Unsloth Studio (~/.unsloth/llama.cpp) or to a standalone llama.cpp checkout:

# Option A: Patch and rebuild Unsloth Studio's llama.cpp
cd ~/.unsloth/llama.cpp
patch -p1 < /path/to/Apple-AFM7/artifacts/llama.patch
cmake -B build
cmake --build build --config Release -j
cd -

# Option B: Clone, patch, and build a standalone llama.cpp
git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
git apply ../artifacts/llama.patch
cmake -B build
cmake --build build --config Release -j
cd ..

3. Convert Model Weights to GGUF

Install the required Python packages, then run artifacts/converter.py with --model {3b-instruct,3b-base,3b-codelm} to generate the desired 16-bit GGUF model (or pass --assets /path/to/purpose_auto when reading from a custom directory):

pip install numpy gguf

# Convert the 3B Instruct model (GenerativeModels with merged rank-32 LoRA)
python3 artifacts/converter.py --model 3b-instruct --out apple-fm-3b-instruct-f16.gguf

# Convert the 3B Base model (GenerativeModels without LoRA merging)
python3 artifacts/converter.py --model 3b-base --out apple-fm-3b-base-f16.gguf

# Convert the 3B CodeLM model (CodeLM MPSGraph with FIM support)
python3 artifacts/converter.py --model 3b-codelm --out apple-codelm-3b-base-f16.gguf

4. Quantize and Run Inference

Load the converted GGUF models into Unsloth Studio (~/.unsloth/studio), run chat or fill-in-the-middle (FIM) completion via llama-cli and llama-completion, or quantize the 16-bit models to 4-bit Q4_K_M:

# Run interactive chat inference with the 3B Instruct model
./llama.cpp/build/bin/llama-cli -m apple-fm-3b-instruct-f16.gguf -cnv -p "Explain how shared KV caching works in transformer models."

# Run Fill-In-the-Middle (FIM) code completion with the 3B CodeLM model
./llama.cpp/build/bin/llama-completion -m apple-codelm-3b-base-f16.gguf -no-cnv --temp 0 -n 64 \
  -p "<||pre||>def fibonacci(n: int) -> int:\n    if n <= 1:\n        return n\n    <||suf||><||mid||>"

# Optional: Quantize either FP16 model to 4-bit Q4_K_M
./llama.cpp/build/bin/llama-quantize apple-fm-3b-instruct-f16.gguf apple-fm-3b-instruct-q4_k_m.gguf Q4_K_M

Important Notes

Because macOS protects /System/Library/AssetsV2 under System Integrity Protection (SIP), you may need to boot into RecoveryOS and run csrutil disable if your user environment cannot read the UAF asset bundles directly, or copy the target purpose_auto directory to an accessible path and pass --assets /path/to/purpose_auto to artifacts/converter.py.

Prompts

The prompts/ directory contains all 374 system and task prompt templates extracted from the UAF metadata.json assets, organized 1 prompt per file for use with the converted GGUF models.

License

This project is distributed under the MIT license, and the full license text is available in the LICENSE file.

About

Convert on-device 3B Apple Intelligence foundation models into standard 16-bit GGUF files for native local inference through patched llama.cpp.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages

⌂ 换网址