whatisgithub

What is ternary_qat?

electroglyph/ternary_qat — explained in plain English

Analysis updated 2026-05-18

10PythonAudience · researcherComplexity · 4/5Setup · moderate

In one sentence

A tool that shrinks an AI model's numbers to just three values so it is smaller and faster while still trainable.

Mindmap

mindmap
  root((repo))
    What it does
      Converts weights to 3 values
      Matches Bonsai format
      Keeps norms full precision
    Tech stack
      PyTorch
      Transformers
      PEFT LoRA
      Unsloth compatible
    Use cases
      Fine tune ternary models
      Train LoRA adapters
      Merge and re-ternarize
    Audience
      ML researchers
      Model quantization engineers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Shrink a Ternary Bonsai language model for faster training and smaller size.

USE CASE 2

Fine tune a ternary model fully or with a LoRA adapter approach.

USE CASE 3

Save and merge a LoRA-trained ternary model back into deployable form.

What is it built with?

PythonPyTorchTransformersPEFTUnsloth

How does it compare?

electroglyph/ternary_qataarav90-cpu/fetchitadammartinez271828/x4-analysis
Stars101010
LanguagePythonPythonPython
Setup difficultymoderateeasyeasy
Complexity4/52/52/5
Audienceresearcherdevelopergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 1h+

Requires installing a compatible PyTorch version first and understanding LoRA or full fine-tuning workflows.

So what is it?

ternary_QAT is a Python tool for shrinking the numbers inside an AI language model so it takes up less space and can run faster, while still letting you keep training it. Normally, the weights inside a language model are stored as regular decimal numbers. This project converts them into just three possible values: negative one, zero, or positive one, grouped in small batches along the model's structure. That conversion follows a format used by a specific family of models called Ternary Bonsai, and the project checks that its output matches that format exactly. It works with models loaded through the Transformers library, and it is specifically built to work alongside a training tool called Unsloth. Once installed, you load a model as usual, then call a function that swaps out the model's linear layers so that the ternary conversion happens automatically every time the model processes data during training. The project supports two main ways of training. You can fine tune the whole model directly, or you can use a technique called LoRA, where the main model is converted to the ternary format and frozen in place while small separate adapter pieces are trained normally in full precision. When you are ready to save a LoRA-trained model, the tool provides steps to properly combine the adapter back into the ternary model. One important detail the author calls out is that training with this ternary approach needs a much higher learning rate than normal fine tuning, roughly ten to fifty times higher. The suggested starting point is around seven ten-thousandths, with room to experiment upward depending on the size of the training data and the settings used. Example code for LoRA training, full fine tuning, and Unsloth usage is included in the project's examples folder. The tool is installed through pip, and users are advised to install their own version of PyTorch first so the wrong version is not installed automatically.

Copy-paste prompts

Prompt 1
Help me install ternary_QAT with the transformers and peft extras alongside my existing PyTorch setup.
Prompt 2
Show me how to use swap_linear and TernaryConfig to convert a Hugging Face model's linear layers to ternary weights.
Prompt 3
Walk me through setting up a LoRA training run on top of a ternary_QAT model, including the merge and re-ternarize steps.
Prompt 4
Explain why ternary QAT needs a much higher learning rate and suggest a starting value for my dataset.

Frequently asked questions

What is ternary_qat?

A tool that shrinks an AI model's numbers to just three values so it is smaller and faster while still trainable.

What language is ternary_qat written in?

Mainly Python. The stack also includes Python, PyTorch, Transformers.

How hard is ternary_qat to set up?

Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.

Who is ternary_qat for?

Mainly researcher.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.