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 -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>

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 -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

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|>'

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.:

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.3.0.tar.gz (41.7 kB view details)

Uploaded Source

Built Distribution

gbx_lm-0.3.0-py3-none-any.whl (57.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gbx-lm-0.3.0.tar.gz
  • Upload date:
  • Size: 41.7 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.3.0.tar.gz
Algorithm Hash digest
SHA256 490fe03fcfe96ab2b7a2cbc44acc779b2c3aa091d0cbe87a2be7b306c8b69456
MD5 6d24181989451545c931fdc5eb04f6b7
BLAKE2b-256 41eeb709f78c7d5c93d80c022d3b703eb174ca42539ef03a7d73a3d2531c63ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gbx_lm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 57.2 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4589e87c3dd5ef647db17fed9fd6fe6a43f40b3ce24727c2417ee92c6e722ad8
MD5 7f9c57a7c3e37d14559c73ad9f89b175
BLAKE2b-256 cc5d4329d97903d3caaa25704467e4d65889b7b09b857162f2975b5df2ef91ef

See more details on using hashes here.

Supported by

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