Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,58 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
-
|
| 11 |
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
- **Layers:** 12 (Tied)
|
| 25 |
-
- **Precision:** 1.58-bit (Ternary) for internal weights
|
| 26 |
-
- **File Size:** 3.96 MB
|
| 27 |
-
- **Tokenizer:** `arnir0/Tiny-LLM` SentencePiece (32,000 vocab size)
|
| 28 |
-
- **Dataset:** `roneneldan/TinyStories`
|
| 29 |
-
- **Validation Perplexity:** 23.7
|
| 30 |
-
|
| 31 |
-
## Usage
|
| 32 |
-
|
| 33 |
-
Because this model uses a highly customized ternary architecture, it cannot be loaded using standard HuggingFace `AutoModel`. You must use the `BitGPT` class implementation.
|
| 34 |
-
|
| 35 |
-
```python
|
| 36 |
-
import torch
|
| 37 |
-
from transformers import AutoTokenizer
|
| 38 |
-
from bitnet_test import BitGPT
|
| 39 |
-
|
| 40 |
-
# 1. Load Tokenizer
|
| 41 |
-
tokenizer = AutoTokenizer.from_pretrained("arnir0/Tiny-LLM")
|
| 42 |
-
|
| 43 |
-
# 2. Initialize Model
|
| 44 |
-
model = BitGPT(vocab_size=len(tokenizer), embed_dim=256, num_layers=12, num_heads=4, tie_weights=True)
|
| 45 |
-
|
| 46 |
-
# 3. Load 1.58-bit Weights
|
| 47 |
-
model.load_state_dict(torch.load("bitnet_tied.pt", map_location="cpu"))
|
| 48 |
-
model.eval()
|
| 49 |
-
|
| 50 |
-
# 4. Generate Text
|
| 51 |
-
prompt = "Once upon a time, there was a tiny cat named"
|
| 52 |
-
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
| 53 |
-
|
| 54 |
-
# ... Run standard auto-regressive generation loop
|
| 55 |
```
|
| 56 |
|
| 57 |
-
##
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MiniLM
|
| 2 |
+
|
| 3 |
+
MiniLM is a fully-functional 1.58-bit (Ternary) Large Language Model engineered entirely from scratch, built explicitly for edge devices.
|
| 4 |
+
|
| 5 |
+
The base model is a 12-Layer Transformer that fits inside **6.00 MB**.
|
| 6 |
+
|
| 7 |
+
Because it is so small, it can be combined with "Side-Car" LoRAs (Low-Rank Adaptations) to perform complex logic (like parsing natural language into exact JSON structures) entirely offline.
|
| 8 |
+
|
| 9 |
+
## Repository Contents
|
| 10 |
+
- `app.py`: The interactive Streamlit Web UI. Run `streamlit run app.py` to start.
|
| 11 |
+
- `model.py`: The custom 1.58-bit PyTorch architecture.
|
| 12 |
+
- `lora.py`: The `BitLoraLinear` side-car architecture.
|
| 13 |
+
- `train_lora_dynamic.py`: A script to easily train 1MB LoRAs using your own JSON datasets.
|
| 14 |
+
- `ARCHITECTURE.md`: A deep-dive into how 1.58-bit quantization and weight-tying work.
|
| 15 |
+
- `LORA_GUIDE.md`: How to build and train side-car LoRAs.
|
| 16 |
+
- `API_USAGE.md`: Example code for loading the model and generating text.
|
| 17 |
+
|
| 18 |
+
## Installation
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
python3 -m venv .venv
|
| 22 |
+
source .venv/bin/activate
|
| 23 |
+
pip install -r requirements.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
```
|
| 25 |
|
| 26 |
+
## Running the Web UI
|
| 27 |
+
|
| 28 |
+
```bash
|
| 29 |
+
streamlit run app.py
|
| 30 |
+
```
|