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
Download utils_quant.py from mardakani/Bitnet: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/mardakani/Bitnet/resolve/main/utils_quant.py
- Command line
-
hf download hf://mardakani/Bitnet/utils_quant.py
-
curl -L -o utils_quant.py https://huggingface.co/mardakani/Bitnet/resolve/main/utils_quant.py
1.33 kB
| 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 |