GBA Model Toolkit for MLX
Project description
GBA Model Toolkit for MLX
Introduction
Welcome to the GreenBitAI (GBA) Model Toolkit for MLX! This comprehensive Python package not only facilitates the conversion of GreenBitAI's Low-bit Language Models (LLMs) to MLX framework compatible format but also supports generation, model loading, and other essential scripts tailored for GBA quantized models. Designed to enhance the integration and deployment of GBA models within the MLX ecosystem, this toolkit enables the efficient execution of GBA models on a variety of platforms, with special optimizations for Apple devices to enable local inference and natural language content generation.
Installation
To get started with this package, simply run:
pip install gbx-lm
or clone the repository and install the required dependencies (for Python >= 3.9):
git clone https://github.com/GreenBitAI/gbx-lm.git
pip install -r requirements.txt
Alternatively you can also use the prepared conda environment configuration:
conda env create -f environment.yml
conda activate gbai_mlx_lm
Usage
Generating Content
To generate natural language content using a converted model:
python -m gbx_lm.generate --model <path to a converted model or a Hugging Face repo name>
# Example
python -m gbx_lm.generate --model GreenBitAI/Llama-3-8B-instruct-layer-mix-bpw-4.0-mlx --max-tokens 100 --prompt "calculate 4*8+1024=" --eos-token '<|im_end|>'
Managing Local Model
You can use the following scripts to explore and delete local models stored in the Hugging Face cache.
# List local models
python -m gbx_lm.manage --scan
# Specify a `--pattern`:
python -m gbx_lm.manage --scan --pattern GreenBitAI/Llama-3-8B-instruct-layer-mix-bpw-2.2-mlx
# To delete a model
python -m gbx_lm.manage --delete --pattern GreenBitAI/Llama-3-8B-instruct-layer-mix-bpw-2.2-mlx
FastAPI Model Server
A high-performance HTTP API for text generation with GreenBitAI's mlx models. Improvements over the original mlx-lm/server.py
:
- Concurrent Processing: Handles multiple requests simultaneously
- Enhanced Performance: Faster response times and better resource utilization
- Robust Validation: Automatic request validation and error handling
- Interactive Docs: Built-in Swagger UI for easy testing
Quick Start
- Run:
python -m gbx_lm.fastapi_server --model GreenBitAI/Llama-3-8B-instruct-layer-mix-bpw-4.0-mlx
- Use:
# Chat curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" \ -d '{"model": "default_model", "messages": [{"role": "user", "content": "Hello!"}]}' # Chat stream curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" \ -d '{"model": "default_model", "messages": [{"role": "user", "content": "Hello!"}], "stream": "True"}'
Features
- Chat and text completion endpoints
- Streaming responses
- Customizable generation parameters
- Support for custom models and adapters
For API details, visit http://localhost:8000/docs
after starting the server.
Note: Not recommended for production without additional security measures.
Converting Models
To convert a GreenBitAI's Low-bit LLM to the MLX format, run:
python -m gbx_lm.gba2mlx --hf-path <input file path or a Hugging Face repo> --mlx-path <output file path> --hf-token <your huggingface token> --upload-repo <a Hugging Face repo name>
# Example
python -m gbx_lm.gba2mlx --hf-path GreenBitAI/yi-6b-chat-w4a16g128 --mlx-path yi-6b-chat-w4a16g128-mlx/ --hf-token <your huggingface token> --upload-repo GreenBitAI/yi-6b-chat-w4a16g128-mlx
Requirements
- Python 3.x
- See
requirements.txt
orenvironment.yml
for a complete list of dependencies
Web Demo
We also prepared a demo for deploying chat applications by leveraging the capabilities of FastChat and Gradio. By following this instruction, you can quickly build a local chat demo page.
License
The original code was released under its respective license and copyrights, i.e.:
generate.py
,lora.py
,*utils.py
,tuner/*.py
andmodels/*.py
etc. released under the MIT License in ml-explore/mlx-examples.- We release our changes and additions to these files under the Apache 2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gbx-lm-0.3.4.tar.gz
.
File metadata
- Download URL: gbx-lm-0.3.4.tar.gz
- Upload date:
- Size: 80.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0569dbadb903a6aa8a8784f8035c18852a55fb16bef49c253bb263dca7fd2c28 |
|
MD5 | 64627e2b8e207a42549b1019869cd53b |
|
BLAKE2b-256 | 703770b2fbce2de2263e946cec9ae9263ca7638a13d99c214ad8bf97c1753ea2 |
File details
Details for the file gbx_lm-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: gbx_lm-0.3.4-py3-none-any.whl
- Upload date:
- Size: 89.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56aaebbbfcf63ee9259666154819724105a121a367653285bd2d9f25ac6d6244 |
|
MD5 | ded794b2fa10d80c6fb0e207b77a81b1 |
|
BLAKE2b-256 | 31c60c41e9d4b2ee238894325ab1486c8edaace1c0da6fed722cee3c9c993563 |