CoolFace
Modelpublic

IamPradeep/Ternary-Bonsai-2-27B-GGUF-Colab-Prebuilt-GPU

sourceHugging Faceupdated 8d agoView on Hugging Face
0likes722downloads
Model Card

Ternary-Bonsai-2-27B (GGUF) โ€“ Fast Colab Inference ๐Ÿš€

This repository provides prebuilt binaries and GGUF configurations to run Ternary-Bonsai-2-27B on Google Colab or similar GPU environments with minimal setup. The default PTQ1_0 variant is only ~5.95 GB and can be downloaded + launched in roughly 1โ€“2 minutes on Colab.


โšก Quick Start

๐Ÿ”ง Setup (run once)

python
!pip install -q huggingface_hub

import os
from huggingface_hub import hf_hub_download

# --- CONFIGURATION ---
repo_id = "IamPradeep/Ternary-Bonsai-2-27B-GGUF-Colab-Prebuilt-GPU"

# ------------------------------------------------------------------------------
# 1. Download + extract the pre-compiled llama.cpp binaries (PrismML fork)
# ------------------------------------------------------------------------------
print("๐Ÿ“ฅ 1. Downloading pre-compiled binary package...")
bin_tar_path = hf_hub_download(repo_id=repo_id, filename="llama_bin.tar.gz")

# Extract the binaries into a folder called 'llama_bin'
# Using tar preserves the executable bit, unlike zip.
!mkdir -p ./llama_bin
!tar -xzf {bin_tar_path} -C ./llama_bin

# Grant executable permissions to the main CLI
!chmod +x ./llama_bin/llama-cli

print("โœ… Binaries ready at ./llama_bin/")

# ------------------------------------------------------------------------------
# 2. Download the PTQ1_0 model (dense trits, ~5.95 GB)
# ------------------------------------------------------------------------------
print("\n\n๐Ÿ“ฅ 2. Downloading PTQ1_0 model (this takes ~1 minute for ~5.95 GB on Colab)...")
model_path = hf_hub_download(
    repo_id=repo_id,
    filename="Ternary-Bonsai-2-27B-PTQ1_0.gguf",
)

# ------------------------------------------------------------------------------
# 3. Environment setup โ€” put the extracted dir on LD_LIBRARY_PATH so the
#    loader can find the bundled CUDA / GGML shared libraries.
# ------------------------------------------------------------------------------
os.environ["LD_LIBRARY_PATH"] = f"./llama_bin:{os.environ.get('LD_LIBRARY_PATH', '')}"

๐Ÿค– Text Inference

python
system_prompt = "You are a helpful AI assistant."
prompt        = "Explain quantum computing in simple terms."

print("\n--- Running inference with Ternary-Bonsai-2-27B (PTQ1_0) ---\n")

!./llama_bin/llama-cli \
  -m "{model_path}" \
  -ngl 99 \
  -c 8192 \
  -sys "{system_prompt}" \
  -p "{prompt}" \
  --temp 0.7 \
  --top-p 0.95 \
  -n 2048 \
  --reasoning off  # Use "on" to enable reasoning/thinking

๐Ÿ‘๏ธ Vision / Multimodal Inference (Live Upload)

You can run vision tasks by downloading a vision projector (mmproj) and uploading an image directly inside Google Colab:

python
from PIL import Image
from google.colab import files
from huggingface_hub import hf_hub_download

# 1. Download Vision Projector (~629 MB)
print("Downloading Vision Projector...")
mmproj_path = hf_hub_download(
    repo_id=repo_id,
    filename="Ternary-Bonsai-2-27B-mmproj-Q8_0.gguf",
)

# 2. Live Image Upload
print("\n" + "="*50)
print("๐Ÿ“ธ PLEASE UPLOAD AN IMAGE FROM YOUR DEVICE:")
print("="*50)

uploaded = files.upload()

if not uploaded:
    print("\nโŒ No file was uploaded!")
else:
    # Save the uploaded file path
    image_filename = list(uploaded.keys())[0]
    image_path = f"./{image_filename}"

    print(f"\nโœ… Uploaded successfully: {image_filename}")
    display(Image.open(image_path))

    # 3. Run Multimodal Inference
    system_prompt = "You are an expert AI vision assistant."
    prompt = "Describe what you see in this image in detail."

    print(f"\n๐Ÿค– Running Vision Inference on {image_filename}...\n")

    !./llama_bin/llama-cli \
      -m "{model_path}" \
      --mmproj "{mmproj_path}" \
      --image "{image_path}" \
      -sys "{system_prompt}" \
      -p "{prompt}" \
      -ngl 99 \
      -c 8192 \
      --temp 0.2 \
      --top-p 0.95 \
      -n 2048 \
      --reasoning off   # Use "on" to enable reasoning/thinking

๐Ÿ’ก Notes

  • โ€”Default model: Ternary-Bonsai-2-27B-PTQ1_0.gguf is ~5.95 GB, using dense ternary trits for fast GPU inference with a small VRAM footprint.
  • โ€”Prebuilt binaries: llama_bin.tar.gz is ~35.2 MB and contains the PrismML fork of llama.cpp. No build or compile step is needed.
  • โ€”GPU acceleration: -ngl 99 offloads all layers to the GPU. Use a Colab GPU runtime for best results.
  • โ€”Reasoning mode: Change --reasoning off to --reasoning on to enable reasoning/thinking.
  • โ€”Vision projector (default): Ternary-Bonsai-2-27B-mmproj-Q8_0.gguf (~629 MB)
  • โ€”Vision projector (high fidelity): Ternary-Bonsai-2-27B-mmproj-BF16.gguf (~931 MB)
  • โ€”Other model variants: Simply change the filename parameter in hf_hub_download.

๐Ÿ“ฆ Available Files

FileSizeNotes
Ternary-Bonsai-2-27B-PTQ1_0.gguf5.95 GBDefault, dense trits, fastest/smallest
Ternary-Bonsai-2-27B-PQ2_0.gguf7.21 GBPQ2_0 quantization
Ternary-Bonsai-2-27B-F16.gguf53.8 GBFull F16 precision
Ternary-Bonsai-2-27B-mmproj-Q8_0.gguf629 MBVision projector, default
Ternary-Bonsai-2-27B-mmproj-BF16.gguf931 MBVision projector, BF16
llama_bin.tar.gz35.2 MBPrebuilt PrismML llama.cpp binaries

๐Ÿง  Architecture

Ternary-Bonsai-2-27B is part of the Bonsai-2 family, using 1.58-bit ternary quantization with weights represented as {-1, 0, +1}. This allows a 27B parameter model to run in a compact 5.95 GB footprint while retaining strong reasoning and multimodal capability when paired with an mmproj vision projector.

The PTQ1_0 variant uses dense trits and is the recommended default for Colab and low-VRAM GPU environments.


๐Ÿค Acknowledgments

Special thanks to [PrismML](https://prismml.com/news/bonsai-2-27b), the original architecture creators behind the Bonsai model families. Their ternary / 1.58-bit quantization methods make high-capability 27B local inference possible in a very small GPU footprint.