rootxhacker commited on
Commit
2e37e51
·
verified ·
1 Parent(s): c7c5492

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +101 -21
README.md CHANGED
@@ -8,46 +8,126 @@ tags: [hobbylm, mixture-of-experts, moe, sparse-moe]
8
 
9
  # HobbyLM-Base (500M sparse-MoE foundation LM)
10
 
11
- A 500M-parameter sparse Mixture-of-Experts base language model pretrained on FineWeb.
12
 
13
- Part of the **HobbyLM** family — a from-scratch 500M sparse-MoE model trained on consumer-scale budgets.
 
 
 
 
 
 
14
 
15
  ## Architecture
16
 
17
- HobbyLM is a **sparse Mixture-of-Experts (MoE)** transformer (DeepSeek-V3 / Ling-style):
 
 
18
 
19
  | Component | Value |
20
  |---|---|
21
- | Total parameters | ~500M (≈ a fraction active per token) |
22
- | Hidden size / layers | 768 / 16 (1 dense FFN layer, 15 MoE) |
23
  | Routed experts / active | 36 / top-6 (+ 1 always-on shared expert) |
24
- | Attention | GQA, 12 query / 3 KV heads, head-dim 128, per-head QK-norm |
25
- | Router | sigmoid gating, aux-loss-free balancing bias, no top-k renorm |
26
- | Positional | RoPE |
27
  | Tokenizer | GPT-2 byte-level BPE (50,304 vocab, sentinel-padded) |
 
 
 
 
 
 
 
 
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- ## Files
 
 
31
 
32
- - `model.safetensors` — the model weights (fp32).
33
- - `config.json` — architecture / hyperparameters.
34
- - GGUF builds (arch `hobbylm`) live in [`rootxhacker/HobbyLM-gguf`](https://huggingface.co/rootxhacker/HobbyLM-gguf).
35
 
36
- ## Loading (safetensors)
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  ```python
39
- import json, torch
 
 
 
 
 
 
40
  from safetensors.torch import load_file
41
- sd = load_file("model.safetensors")
42
- cfg = json.load(open("config.json"))
43
- # rebuild the HobbyLM nn.Module from `cfg` and `load_state_dict(sd)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  ```
45
 
46
- ## Notes & limitations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- - Research model at the ~500M scale: fluent but with the capability ceiling of a small model.
49
- - The GGUF uses a custom `hobbylm` architecture (see the GGUF repo) and needs `moe-rs` or a patched llama.cpp.
 
50
 
51
  ## License
52
 
53
- Apache-2.0.
 
 
8
 
9
  # HobbyLM-Base (500M sparse-MoE foundation LM)
10
 
11
+ HobbyLM-Base is the foundation the whole family is built on: a 500M-parameter sparse Mixture-of-Experts decoder trained **from scratch** on FineWeb — no distillation, no borrowed weights. It exists to answer a simple question: how far can you get at the ~500M scale if you sweat the architecture and the training recipe instead of throwing tokens at the problem?
12
 
13
+ It's part of the **HobbyLM** family — a 500M sparse-MoE model (and its variants) built from scratch on a
14
+ hobby budget: FineWeb, a handful of Modal H100 hours, a lot of ablations, and a from-scratch Rust engine
15
+ ([`hobby-rs`](https://github.com/harishsg993010/HobbyLM)) to run it on a laptop CPU.
16
+
17
+ ## Intended use
18
+
19
+ A pretrained base model for text completion, and the checkpoint you fine-tune for downstream tasks. It is **not** instruction-tuned — for chat, use [HobbyLM-Chat](https://huggingface.co/rootxhacker/HobbyLM-Chat).
20
 
21
  ## Architecture
22
 
23
+ Every HobbyLM variant shares one core: a **sparse Mixture-of-Experts (MoE)** decoder in the modern
24
+ small-MoE style (DeepSeek-V3 / OLMoE lineage), where each design choice was picked by ablation rather
25
+ than by guesswork.
26
 
27
  | Component | Value |
28
  |---|---|
29
+ | Total parameters | ~500M (only a fraction is active per token) |
30
+ | Hidden size / layers | 768 / 16 (first FFN dense, the rest MoE) |
31
  | Routed experts / active | 36 / top-6 (+ 1 always-on shared expert) |
32
+ | Attention | GQA, 12 query / 3 KV heads, decoupled head-dim 128, per-head QK-norm |
33
+ | Router | sigmoid gating, DeepSeek-V3 aux-loss-free load balancing, no top-k renorm |
34
+ | Positional | RoPE (θ up to 1e6 for the 8k-context checkpoints) |
35
  | Tokenizer | GPT-2 byte-level BPE (50,304 vocab, sentinel-padded) |
36
+ | Optimizer | Muon on the 2-D + per-expert matrices, AdamW on everything else |
37
+
38
+ The full ablation log (QK-norm is the single biggest lever; aux-loss-free beats classic aux-loss;
39
+ ≥32 experts and top-6 help; embedding-scaling hurt) lives in the project's architecture notes.
40
+
41
+ ## Benchmarks
42
+
43
+ 0-shot, 7-task average through our harness (see note below). HobbyLM was trained on **40B tokens** — a tiny
44
+ budget next to the comparison models — so the right way to read this table is *per training token*.
45
 
46
+ | Model | Params | Pretrain tokens | Avg (7-task) |
47
+ |---|---|---|---|
48
+ | SmolLM2-360M | 360M | ~4T | 56.29 |
49
+ | Qwen3-0.6B | 600M | ~36T | 54.78 |
50
+ | gemma-3-270m | 270M | — | 48.09 |
51
+ | pythia-410m | 410M | 300B | 45.34 |
52
+ | **HobbyLM-Base (500M)** | **500M** | **40B** | **44.05** |
53
+ | opt-350m | 350M | 180B | 43.61 |
54
+ | HobbyLM-130M (sibling) | 130M | 10B | 42.97 |
55
+ | MicroLlama-300M | 300M | 50B | 42.23 |
56
+ | gpt2 | 124M | — | 40.62 |
57
+ | pythia-160m | 160M | 300B | 38.60 |
58
 
59
+ Per-task (0-shot): HellaSwag 41.5 · LAMBADA 40.0 · SciQ 70.3 · PIQA 69.6 · ARC-easy 42.7
60
+ (ARC-challenge / WinoGrande sit near chance, as expected at this scale). Validation loss: **3.03** at 1k
61
+ context, **2.94** after the 8k context-extension.
62
 
63
+ The ranking tracks **pretraining tokens**, not parameters: the top models see 50–900× more data than we do.
64
+ In the classic ≤300B-token regime, HobbyLM leads per token — the 130M (10B tokens) beats MicroLlama-300M
65
+ (50B), opt-350m (180B) and pythia-160m (300B). Token budget, not architecture, is the gap.
66
 
67
+ > **How these were measured.** All language-model scores are **0-shot** through our own port of
68
+ > EleutherAI's `lm-evaluation-harness` (a custom `MoELMWrapper` that runs log-likelihood scoring over the
69
+ > HobbyLM MoE + GPT-2 tokenizer). Reference models in the comparison table were run through the **identical
70
+ > harness and task set**, so the numbers are apples-to-apples with ours — they are *not* copied from other
71
+ > model cards. We validated the harness against published cards (e.g. TinyLlama 52.75 vs card 52.99). These
72
+ > are small research models: read the numbers in context, not as leaderboard claims.
73
+
74
+ ## Usage
75
+
76
+ ### Python (PyTorch reference implementation)
77
+
78
+ HobbyLM is a custom sparse-MoE architecture — there's no `transformers` `AutoModel` for it, so load it with
79
+ the small reference implementation from the [GitHub repo](https://github.com/harishsg993010/HobbyLM):
80
 
81
  ```python
82
+ # HobbyLM is a CUSTOM sparse-MoE architecture, so load it with the reference implementation —
83
+ # NOT transformers.AutoModelForCausalLM (there is no AutoModel mapping for this arch).
84
+ # pip install torch safetensors tiktoken huggingface_hub
85
+ # git clone https://github.com/harishsg993010/HobbyLM && cd HobbyLM
86
+
87
+ import json, torch, tiktoken
88
+ from huggingface_hub import hf_hub_download
89
  from safetensors.torch import load_file
90
+ from hobbylm.config import ModelConfig
91
+ from hobbylm.model import MoETransformer
92
+ from hobbylm.generate import generate
93
+
94
+ repo = "rootxhacker/HobbyLM-Base"
95
+ cfg = ModelConfig(**{k: v for k, v in json.load(open(hf_hub_download(repo, "config.json"))).items() if k != "preset"})
96
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
97
+ cfg.expert_backend = "grouped" if device.type == "cuda" else "bmm"
98
+
99
+ model = MoETransformer(cfg).to(device).eval()
100
+ model.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))
101
+
102
+ enc = tiktoken.get_encoding("gpt2")
103
+ prompt = "The capital of France is"
104
+ ids = torch.tensor([enc.encode_ordinary(prompt)], device=device)
105
+ out = generate(model, ids, max_new_tokens=64, temperature=0.7, top_k=0, device=device,
106
+ repetition_penalty=1.3) # temperature=0.0 for greedy
107
+ print(enc.decode(out[0].tolist()))
108
  ```
109
 
110
+ ### GGUF + hobby-rs (CPU)
111
+
112
+ GGUF builds (architecture `hobbylm`) live in [`rootxhacker/HobbyLM-gguf`](https://huggingface.co/rootxhacker/HobbyLM-gguf). They load
113
+ directly in the from-scratch `hobby-rs` CPU engine — **stock llama.cpp won't load them** without registering
114
+ the `hobbylm` architecture first.
115
+
116
+ ```bash
117
+ hobby-rs --model HobbyLM-Base.gguf --prompt "..." --n 64
118
+ ```
119
+
120
+ ## Training
121
+
122
+ Pretrained on ~40B unique FineWeb tokens (8×H100), then context-extended 1k→8k (RoPE θ 1e4→1e6). Muon on the hidden + per-expert matrices, AdamW on the router/embeddings/norms; fp32 router; chunked-checkpointed cross-entropy to fit a larger batch.
123
+
124
+ ## Limitations
125
 
126
+ - It's a ~500M base model on a 40B-token budget: fluent and factually-okay on easy questions, but it hallucinates and can repeat without a repetition penalty at decode time.
127
+ - Trained on English FineWeb; other languages and code are out of distribution.
128
+ - Not aligned or safety-tuned.
129
 
130
  ## License
131
 
132
+ Apache-2.0. Weights aren't a substitute for judgement — this is a research / hobby model at the 500M scale,
133
+ not a production system.