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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: llama3.2
|
| 5 |
+
base_model: meta-llama/Llama-3.2-1B
|
| 6 |
+
tags:
|
| 7 |
+
- llama
|
| 8 |
+
- continued-pretraining
|
| 9 |
+
- sft
|
| 10 |
+
- lora
|
| 11 |
+
- 1b
|
| 12 |
+
- math
|
| 13 |
+
- code
|
| 14 |
+
- education
|
| 15 |
+
datasets:
|
| 16 |
+
- HuggingFaceFW/fineweb-edu
|
| 17 |
+
- open-web-math/open-web-math
|
| 18 |
+
- bigcode/starcoderdata
|
| 19 |
+
- HuggingFaceTB/cosmopedia
|
| 20 |
+
- teknium/OpenHermes-2.5
|
| 21 |
+
- meta-math/MetaMathQA
|
| 22 |
+
- sahil2801/CodeAlpaca-20k
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# Kybalion-1B
|
| 26 |
+
|
| 27 |
+
**Kybalion-1B** is a 1B-parameter language model built on top of [Llama 3.2 1B](https://huggingface.co/meta-llama/Llama-3.2-1B) through a full **Continued Pre-Training (CPT) β Supervised Fine-Tuning (SFT)** pipeline, trained entirely on Google Colab A100.
|
| 28 |
+
|
| 29 |
+
> **Why "Kybalion"?**
|
| 30 |
+
> The model was originally developed under the internal codename *Prometheus-1B*, but was renamed to *Kybalion-1B* before public release to avoid confusion with an existing model of the same name on HuggingFace. *Kybalion* refers to the ancient hermetic text symbolizing hidden knowledge β fitting for a model focused on education, mathematics, science, and code.
|
| 31 |
+
|
| 32 |
+
---
|
| 33 |
+
|
| 34 |
+
## π Key Highlights
|
| 35 |
+
|
| 36 |
+
- **Beats Llama-3.2-1B-Instruct** on HellaSwag (63.8% vs 61.1%) and ties on WinoGrande (62.4%)
|
| 37 |
+
- **4.5Γ GSM8K improvement** over TinyLlama-1.1B (10.8% vs 2.4%) β math pretraining works
|
| 38 |
+
- Outperforms TinyLlama-1.1B on **all 6 benchmarks**
|
| 39 |
+
- Trained by a single undergraduate student on consumer cloud hardware
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## π Benchmark Results
|
| 44 |
+
|
| 45 |
+
All scores measured with [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) under **identical conditions** (same prompts, same few-shot settings, same hardware).
|
| 46 |
+
|
| 47 |
+
| Benchmark | TinyLlama-1.1B | Llama-3.2-1B-Instruct | **Kybalion-1B** |
|
| 48 |
+
|-----------|:--------------:|:---------------------:|:---------------:|
|
| 49 |
+
| MMLU | 25.0% | 46.1% | **32.0%** |
|
| 50 |
+
| ARC-C | 37.2% | 41.5% | **37.6%** |
|
| 51 |
+
| GSM8K | 2.4% | 33.5% | **10.8%** |
|
| 52 |
+
| HellaSwag | 61.2% | 61.1% | **63.8%** π |
|
| 53 |
+
| WinoGrande | 61.8% | 62.4% | **62.4%** π |
|
| 54 |
+
| TruthfulQA | 37.4% | 43.3% | **40.0%** |
|
| 55 |
+
|
| 56 |
+
> π = outperforms Llama-3.2-1B-Instruct
|
| 57 |
+
> All evaluations run with `lm_eval.simple_evaluate()`, bfloat16, batch_size=8, A100 GPU.
|
| 58 |
+
|
| 59 |
+
---
|
| 60 |
+
|
| 61 |
+
## π§ Training Pipeline
|
| 62 |
+
|
| 63 |
+
### Phase 1: Continued Pre-Training (CPT)
|
| 64 |
+
|
| 65 |
+
Fine-tuned the base weights of `meta-llama/Llama-3.2-1B` on ~3.5B tokens of curated multi-domain data.
|
| 66 |
+
|
| 67 |
+
| Domain | Dataset | Ratio | Purpose |
|
| 68 |
+
|--------|---------|-------|---------|
|
| 69 |
+
| Education | FineWeb-Edu (score β₯ 3.0) | 35% | General knowledge & reasoning |
|
| 70 |
+
| Mathematics | OpenWebMath | 20% | Mathematical reasoning |
|
| 71 |
+
| Code | StarCoderData (Python) | 15% | Code generation |
|
| 72 |
+
| Textbook | Cosmopedia web_samples_v2 | 15% | Structured knowledge |
|
| 73 |
+
| Science | Cosmopedia stanford | 10% | Scientific reasoning |
|
| 74 |
+
| Story | Cosmopedia stories | 5% | Language fluency |
|
| 75 |
+
|
| 76 |
+
**Training config:**
|
| 77 |
+
- Hardware: Google Colab A100 80GB
|
| 78 |
+
- Optimizer: AdamW, LR = 2e-5, Cosine decay, Warmup = 1000 steps
|
| 79 |
+
- Precision: BF16
|
| 80 |
+
- Effective batch size: 32 (4 Γ 8 grad accum)
|
| 81 |
+
- Sequence length: 2048 (packed)
|
| 82 |
+
- Framework: HuggingFace `transformers.Trainer` (no Unsloth)
|
| 83 |
+
|
| 84 |
+
### Phase 2: Supervised Fine-Tuning (SFT)
|
| 85 |
+
|
| 86 |
+
Applied LoRA adapters to teach instruction-following, then merged into base weights.
|
| 87 |
+
|
| 88 |
+
| Dataset | Size | Purpose |
|
| 89 |
+
|---------|------|---------|
|
| 90 |
+
| OpenHermes 2.5 | 100K | General instruction following |
|
| 91 |
+
| MetaMathQA | 50K | Mathematical reasoning (GSM8K boost) |
|
| 92 |
+
| CodeAlpaca | 20K | Code generation |
|
| 93 |
+
|
| 94 |
+
**SFT config:**
|
| 95 |
+
- Method: LoRA (r=64, Ξ±=128, dropout=0.05)
|
| 96 |
+
- Target modules: q/k/v/o/gate/up/down proj (all linear layers)
|
| 97 |
+
- LR = 1e-4, Epochs = 3, Cosine decay
|
| 98 |
+
- Merged with `PeftModel.merge_and_unload()` for standalone deployment
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
## π» Usage
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 106 |
+
import torch
|
| 107 |
+
|
| 108 |
+
tokenizer = AutoTokenizer.from_pretrained("devwoo/Kybalion-1B")
|
| 109 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 110 |
+
"devwoo/Kybalion-1B",
|
| 111 |
+
torch_dtype=torch.bfloat16,
|
| 112 |
+
device_map="auto",
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
def chat(user_message, system="You are a helpful and knowledgeable AI assistant."):
|
| 116 |
+
prompt = (
|
| 117 |
+
f"<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n"
|
| 118 |
+
f"{system}<|eot_id|>"
|
| 119 |
+
f"<|start_header_id|>user<|end_header_id|>\n\n"
|
| 120 |
+
f"{user_message}<|eot_id|>"
|
| 121 |
+
f"<|start_header_id|>assistant<|end_header_id|>\n\n"
|
| 122 |
+
)
|
| 123 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 124 |
+
with torch.no_grad():
|
| 125 |
+
outputs = model.generate(
|
| 126 |
+
**inputs,
|
| 127 |
+
max_new_tokens=512,
|
| 128 |
+
temperature=0.7,
|
| 129 |
+
top_p=0.9,
|
| 130 |
+
do_sample=True,
|
| 131 |
+
eos_token_id=tokenizer.convert_tokens_to_ids("<|eot_id|>"),
|
| 132 |
+
)
|
| 133 |
+
return tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 134 |
+
|
| 135 |
+
print(chat("Explain the Pythagorean theorem and give an example."))
|
| 136 |
+
print(chat("Write a Python function to check if a number is prime."))
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
---
|
| 140 |
+
|
| 141 |
+
## π¦ GGUF Version
|
| 142 |
+
|
| 143 |
+
A quantized **GGUF q4_k_m** version is available at [devwoo/Kybalion-1B-GGUF](https://huggingface.co/devwoo/Kybalion-1B-GGUF) for CPU/mobile inference with [llama.cpp](https://github.com/ggerganov/llama.cpp) or [Ollama](https://ollama.com).
|
| 144 |
+
|
| 145 |
+
```bash
|
| 146 |
+
# With llama.cpp
|
| 147 |
+
./llama-cli -m Kybalion-1B-q4_k_m.gguf -p "Explain quantum computing." -n 256
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
---
|
| 151 |
+
|
| 152 |
+
## β οΈ Limitations
|
| 153 |
+
|
| 154 |
+
- 1B parameters β smaller than most production models; may struggle with complex multi-step reasoning
|
| 155 |
+
- Not RLHF-aligned; may occasionally produce unhelpful or inconsistent responses
|
| 156 |
+
- English-only training data
|
| 157 |
+
- GSM8K score (10.8%) reflects room for improvement in math reasoning compared to larger models
|
| 158 |
+
|
| 159 |
+
---
|
| 160 |
+
|
| 161 |
+
## π License
|
| 162 |
+
|
| 163 |
+
This model is derived from `meta-llama/Llama-3.2-1B` and follows the [Llama 3.2 Community License](https://ai.meta.com/llama/license/).
|
| 164 |
+
Training datasets are used under their respective open licenses.
|