Instructions to use mardakani/Bitnet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use mardakani/Bitnet with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf mardakani/Bitnet:F32 # Run inference directly in the terminal: llama cli -hf mardakani/Bitnet:F32
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf mardakani/Bitnet:F32 # Run inference directly in the terminal: llama cli -hf mardakani/Bitnet:F32
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf mardakani/Bitnet:F32 # Run inference directly in the terminal: ./build/bin/llama cli -hf mardakani/Bitnet:F32
Use Docker
docker model run hf.co/mardakani/Bitnet:F32
- Llama new
- LM Studio
- Jan
- Ollama
How to use mardakani/Bitnet with Ollama:
ollama run hf.co/mardakani/Bitnet:F32
- Unsloth Desktop
- Docker Model Runner
How to use mardakani/Bitnet with Docker Model Runner:
docker model run hf.co/mardakani/Bitnet:F32
- Lemonade
How to use mardakani/Bitnet with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull mardakani/Bitnet:F32
Run and chat with the model
lemonade run user.Bitnet-F32
List all available models
lemonade list
- Atomic Chat
File size: 1,328 Bytes
576b73e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import math
import torch
from torch import nn
def weight_quant(weight, num_bits=1):
dtype = weight.dtype
weight = weight.float()
s = 1 / weight.abs().mean().clamp(min=1e-5)
result = (weight * s).round().clamp(-1, 1) / s
return result.type(dtype)
def activation_quant(x, num_bits=8):
dtype = x.dtype
x = x.float()
Qn = -2 ** (num_bits - 1)
Qp = 2 ** (num_bits - 1) - 1
s = Qp / x.abs().max(dim=-1, keepdim=True).values.clamp(min=1e-5)
result = (x * s).round().clamp(Qn, Qp) / s
return result.type(dtype)
class BitLinear(nn.Linear):
def __init__(self,
*kargs,
weight_bits=1,
input_bits=8,
**kwargs
):
super(BitLinear, self).__init__(*kargs, **kwargs)
"""
RMSNorm is placed outside BitLinear
"""
self.weight_bits = weight_bits
self.input_bits = input_bits
def forward(self, input):
quant_input = input + (activation_quant(input, self.input_bits) - input).detach()
quant_weight = self.weight + (weight_quant(self.weight, self.weight_bits) - self.weight).detach()
out = nn.functional.linear(quant_input, quant_weight)
if not self.bias is None:
out += self.bias.view(1, -1).expand_as(out)
return out |