Skip to main content

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.

Features

This toolkit represents a significant step forward in the usability of GreenBitAI models, making it simpler for developers and researchers to incorporate these models into their MLX-based projects.

  • Conversion: Utilize gba2mlx.py to convert models from GBA format to a format compatible with the MLX framework, ensuring smooth integration and optimal performance.
  • Generation: Includes scripts for generating content using GBA quantized models within the MLX environment, empowering users to leverage the advanced capabilities of GBA models for natural language content creation.

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

Converting Models

To convert a GreenBitAI's Low-bit LLM to the MLX format, run:

python gbx_lm/gba2mlx.py --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>

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>

Requirements

  • Python 3.x
  • See requirements.txt or environment.yml for a complete list of dependencies

Examples

In this example, the pretrained 4-bit model "yi-6b-chat-w4a16g128" will be downloaded from GreenBitAI's Hugging Face repository and converted into mlx compatible format, and saved in the local directory "yi-6b-chat-w4a16g128-mlx". We can also use the "--upload-repo" parameter to provide a Hugging Face repo URL with valid write permissions. This will directly upload the model converted and saved locally to this Hugging Face repo.

python gbx_lm/gba2mlx.py --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

It will download and run the local model to generate natural language content through prompts given by users.

python -m gbx_lm.generate --model GreenBitAI/yi-6b-chat-w4a16g128-mlx  --max-tokens 100 --prompt "calculate 4*8+1024=" --eos-token '<|im_end|>'

License

The original code was released under its respective license and copyrights, i.e.:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gbx-lm-0.1.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gbx_lm-0.1.1-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file gbx-lm-0.1.1.tar.gz.

File metadata

  • Download URL: gbx-lm-0.1.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for gbx-lm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f4d70b306d82c395732dd2a0c26e27e6eb387b6f316742a203f178762a59b594
MD5 bafc1ac77b555358a3ac0601a33f2c2d
BLAKE2b-256 94c9af6eda2ac8e0edb20b91c60d8e4ed58c1278f4f070664b31237f9619164e

See more details on using hashes here.

File details

Details for the file gbx_lm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gbx_lm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for gbx_lm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96aaf8f87b474d0cbefabd86a6e0f9fc84f4f4feb95d87d2c53e675d08c527ad
MD5 9dd63f348d1d5395a7d8d7ec7f269d8d
BLAKE2b-256 90aa9a1bec4e6b91b01dcd14e062443f52fcf63a8293c73a5de55b3fc15a6be3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page