rootxhacker commited on
Commit
fa4b465
Β·
verified Β·
1 Parent(s): 7555cfa

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +86 -22
README.md CHANGED
@@ -8,50 +8,114 @@ tags: [hobbylm, mixture-of-experts, moe, sparse-moe]
8
 
9
  # HobbyLM-Diffusion (500M MoE, text diffusion / LLaDA-style)
10
 
11
- Masked-diffusion (LLaDA-style) variant of HobbyLM for bidirectional / parallel decoding.
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
  ## Decoding
31
 
32
- This is a **masked-diffusion** checkpoint (LLaDA-style): generation is iterative bidirectional denoising of `[MASK]` tokens, not left-to-right AR. The GGUF carries `diffusion.*` metadata (mask token id, block size) for a diffusion-aware runtime.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- ## Files
35
 
36
- - `model.safetensors` β€” the model weights (fp32).
37
- - `config.json` β€” architecture / hyperparameters.
38
- - GGUF builds (arch `hobbylm`) live in [`rootxhacker/HobbyLM-gguf`](https://huggingface.co/rootxhacker/HobbyLM-gguf).
39
 
40
- ## Loading (safetensors)
 
41
 
42
  ```python
43
- import json, torch
 
 
 
 
 
 
44
  from safetensors.torch import load_file
45
- sd = load_file("model.safetensors")
46
- cfg = json.load(open("config.json"))
47
- # rebuild the HobbyLM nn.Module from `cfg` and `load_state_dict(sd)`.
 
 
 
 
 
 
 
 
 
 
 
 
48
  ```
49
 
50
- ## Notes & limitations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- - Research model at the ~500M scale: fluent but with the capability ceiling of a small model.
53
- - The GGUF uses a custom `hobbylm` architecture (see the GGUF repo) and needs `moe-rs` or a patched llama.cpp.
 
54
 
55
  ## License
56
 
57
- Apache-2.0.
 
 
8
 
9
  # HobbyLM-Diffusion (500M MoE, text diffusion / LLaDA-style)
10
 
11
+ HobbyLM-Diffusion is the family's experiment in a different decoding paradigm: a **masked-diffusion** language model (LLaDA-style). Instead of generating left-to-right, it attends bidirectionally and fills in `[MASK]` tokens over a few iterative denoising passes β€” so it can decode in parallel.
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
+ Research / generation via iterative denoising. The decode knobs (denoising steps, block size, remasking, confidence threshold) trade quality against speed; good defaults are temp 0–0.3, steps β‰ˆ 2Γ— the generation length, repetition penalty 1.4–1.5.
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
  ## Decoding
42
 
43
+ Generation is **iterative bidirectional denoising** of `[MASK]` tokens, not left-to-right AR. The GGUF carries `diffusion.*` metadata (mask-token id, block size) for a diffusion-aware runtime; `hobby-rs` implements the cached semi-autoregressive denoiser.
44
+
45
+ ## Benchmarks
46
+
47
+ A masked-diffusion model can't be scored by the standard log-likelihood lm-eval harness, so the meaningful
48
+ numbers are training loss and **decoding throughput** β€” where the diffusion paradigm actually shows up:
49
+
50
+ | Metric | Value |
51
+ |---|---|
52
+ | Validation loss (β‰ˆ21B tokens) | 3.52 |
53
+ | Throughput β€” H100, 128 tok, 32 steps | **117.7 tok/s** (~2.7Γ— the AR model) |
54
+ | Throughput β€” H100, AR baseline | ~44 tok/s |
55
+ | Throughput β€” laptop CPU (q8, cached) | ~6.5 tok/s |
56
+
57
+ The throughput result reproduces the **Fast-dLLM** literature's 2–3Γ— GPU range from a from-scratch
58
+ implementation: on memory-bound hardware (GPU) batching the whole canvas is nearly free, so fewer denoising
59
+ passes than tokens wins; on a compute-bound laptop the same code trails the AR engine. The knob is
60
+ steps-per-token (quality ↔ speed).
61
+
62
+ > A masked-diffusion LM at 500M trails an equal-scale autoregressive model on raw coherence β€” the method is
63
+ > fully validated end-to-end here; the limit is capacity and tokens, not the recipe.
64
 
65
+ ## Usage
66
 
67
+ ### Python (PyTorch reference implementation)
 
 
68
 
69
+ HobbyLM is a custom sparse-MoE architecture β€” there's no `transformers` `AutoModel` for it, so load it with
70
+ the small reference implementation from the [GitHub repo](https://github.com/harishsg993010/HobbyLM):
71
 
72
  ```python
73
+ # HobbyLM-Diffusion is a MASKED-DIFFUSION model: generation is iterative, bidirectional denoising
74
+ # β€” NOT autoregressive β€” so it uses the reference diffusion sampler (not transformers.generate).
75
+ # pip install torch safetensors tiktoken huggingface_hub
76
+ # git clone https://github.com/harishsg993010/HobbyLM && cd HobbyLM
77
+
78
+ import json, torch, tiktoken
79
+ from huggingface_hub import hf_hub_download
80
  from safetensors.torch import load_file
81
+ from hobbylm.config import ModelConfig
82
+ from hobbylm.model import MoETransformer
83
+ from hobbylm.diffusion import generate
84
+
85
+ repo = "rootxhacker/HobbyLM-Diffusion"
86
+ cfg = ModelConfig(**{k: v for k, v in json.load(open(hf_hub_download(repo, "config.json"))).items() if k != "preset"})
87
+ cfg.expert_backend = "bmm" # "grouped" on CUDA
88
+ model = MoETransformer(cfg).eval()
89
+ model.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))
90
+
91
+ enc = tiktoken.get_encoding("gpt2")
92
+ ids = torch.tensor([enc.encode_ordinary("The meaning of life is")])
93
+ # iterative denoising: gen_len tokens over `steps` bidirectional passes (more steps + lower temp = better)
94
+ out = generate(model, ids, gen_len=96, steps=128, temperature=0.2, rep_penalty=1.5, remask_steps=2)
95
+ print(enc.decode(out[0].tolist()))
96
  ```
97
 
98
+ ### GGUF + hobby-rs (CPU)
99
+
100
+ GGUF builds (architecture `hobbylm`) live in [`rootxhacker/HobbyLM-gguf`](https://huggingface.co/rootxhacker/HobbyLM-gguf). They load
101
+ directly in the from-scratch `hobby-rs` CPU engine β€” **stock llama.cpp won't load them** without registering
102
+ the `hobbylm` architecture first.
103
+
104
+ ```bash
105
+ hobby-rs --model HobbyLM-Diffusion.gguf --prompt "..." --n 64
106
+ ```
107
+
108
+ ## Training
109
+
110
+ Converted from the autoregressive 500M base (weights transfer; same architecture, attention switched to bidirectional) and adapted on ~21B tokens with a masked-token objective reweighted by 1/p_mask. No from-scratch pretrain needed β€” this is a DiffuGPT/DiffuLLaMA-style conversion.
111
+
112
+ ## Limitations
113
 
114
+ - Fluent but semantically loose β€” the expected ceiling for a 500M *pure-diffusion* model at ~21B tokens.
115
+ - Decoding quality is very sensitive to the sampler settings (see above).
116
+ - The CPU throughput win only materializes on memory-bound hardware; on a thermally-limited laptop the AR model is faster.
117
 
118
  ## License
119
 
120
+ Apache-2.0. Weights aren't a substitute for judgement β€” this is a research / hobby model at the 500M scale,
121
+ not a production system.