Downloads · 30 days
32
9% of all-time downloads
akoumpa/Moonlight-V4-1B-h16d256-r8
Moonlight-V4-1B-h16d256-r8 is a text generation model from akoumpa. Use it when you need the model to write or continue text. The card lists the license as mit.
An untrained, ~1B-parameter DeepSeek-V4-architecture configuration (no weights): DeepSeek-V4-architecture 1B config with 16 x 256 attention heads and ratio-8 compressed attention (no indexer). It is the small end of a…
Downloads · 30 days
32
9% of all-time downloads
All-time downloads
353
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.json6.4 MB · 99%
From the Hugging Face model README
An untrained, ~1B-parameter DeepSeek-V4-architecture configuration (no weights): DeepSeek-V4-architecture 1B config with 16 x 256 attention heads and ratio-8 compressed attention (no indexer). It is the small end of a Moonlight-style down-scaling of DeepSeek-V4, sized to pre-train on two 48 GB GPUs, with attention dimensions chosen so that the TileLang sparse-attention kernel fits GPUs with 99 KB of shared memory (Ada / consumer class). This variant replaces DeepSeek-V4's ratio-4 Compressed Sparse Attention (CSA) layers by ratio-8 compressed attention without a lightning indexer: 7 compressed layers at ratio 8, 6 Heavily Compressed Attention (HCA) layers at ratio 128 and 2 pure sliding-window layers. Every query attends to all causal compressed entries, so no top-k selection is needed.
The sibling repo keeps DeepSeek-V4's ratio-4 CSA layers with the lightning indexer (the faithful architecture, loadable by transformers). Sibling: akoumpa/Moonlight-V4-1B-h16d256.
| total | non-embedding | activated / token | activated non-embedding | |
|---|---|---|---|---|
| parameters | 977,183,967 (977.2M) | 712.4M | 517.1M | 252.4M |
| model | architecture | size | status |
|---|---|---|---|
| Moonlight-16B-A3B (Moonshot) | DeepSeek-V3 | 16B / 3B active | released, trained with Muon |
| Moonlight-V4-16B-A3B | DeepSeek-V4 at Moonlight's width/depth/experts | 16.5B / 3.0B active | proposed config |
| Moonlight-V4-1B (8 heads x 512) | same, shrunk | 1.0B / 0.54B active | config; eager attention only |
| Moonlight-V4-1B-h16d256-r8 | same, attention re-shaped for the kernels | 977.2M / 517.1M active | this repo |
DeepSeek-V4 (Flash: 284B/13B, Pro: 1.6T/49B) keeps head_dim = 512 and 64 or 128 query heads; Moonlight's 16 heads
were kept for the 16B analogue, and here 16 heads x 256 dims give the same 4096-wide query space as the 8 x 512
1B config with half the shared-KV width.
| component | setting |
|---|---|
| hidden size / layers | 1024 / 15 |
attention schedule (compress_ratios) | [0, 0, 8, 128, 8, 128, 8, 128, 8, 128, 8, 128, 8, 128, 8]: 2 sliding-window, 7 compressed (ratio 8, no indexer), 6 HCA (ratio 128) |
| attention | shared-KV MQA (num_key_value_heads 1): 16 query heads x head_dim 256 (last 64 dims RoPE), the same 256-dim entry is key and value |
| query path | q_lora_rank 256 -> 16 x 256; per-head RMSNorm before RoPE |
| output projection | grouped low-rank: o_groups 2 (8 heads per group) x o_lora_rank 1024 -> hidden |
| sliding window / attention sinks | 128 tokens on every layer / one learnable sink logit per head |
| Lightning indexer | none (ratio-8 layers attend to all causal compressed entries) |
| MoE (every layer) | 32 routed experts x 384 (SwiGLU, clamp 10.0), top-6, 1 shared expert; sqrtsoftplus scoring, aux-loss-free bias (noaux_tc), routed_scaling_factor 2.436 |
| hash-routed layers | first 1 MoE layer(s) route by a fixed token-id table (tid2eid) |
| residual stream | manifold-constrained hyper-connections, hc_mult 4, 20 Sinkhorn iterations |
| positions | 4096 tokens, plain RoPE (theta 10000 on sliding layers, 160000 on compressed layers, no YaRN) |
| MTP | none (num_nextn_predict_layers 0) |
| vocabulary | 129280 (DeepSeek-V4 tokenizer, BOS 0, EOS 1) |
| norm eps / init | 1e-06 / 0.02 |
Per-layer parameters: attention 7.9M (sliding) / 8.4M (ratio 8) / 8.4M (HCA); MoE 39.0M
total, 8.3M activated (each expert 1.2M); mHC mixers 196,662. Embedding and
head are 132.4M each. KV cache per sequence at 4K / 32K tokens (FP8 non-RoPE dims, bf16 RoPE dims): 1.7 MiB / 9.8 MiB.
Core-attention FLOPs per generated token at 4K context: 0.09 GF, against 0.77 GF of linear layers.
python count_params.py config.json reproduces these numbers (the script also reproduces the published sizes of
Moonlight, DeepSeek-V3, V4-Flash and V4-Pro).
Design rules: head_dim and index_topk are powers of two and index_n_heads divides 128 (kernel requirements);
o_lora_rank 1024 keeps DeepSeek-V4's per-group output projection shape; routed_scaling_factor follows Moonlight's
recipe (expected 1/||p||_2 of renormalised top-k scores) applied to sqrt-softplus with 32 experts / top-6.
| file | purpose |
|---|---|
config.json | Hugging Face config (same key set as deepseek-ai/DeepSeek-V4-Flash) |
inference_config.json | the same model in the key format of DeepSeek's reference inference/model.py |
tokenizer.json, tokenizer_config.json | DeepSeek-V4 tokenizer (MIT), copied from deepseek-ai/DeepSeek-V4-Flash |
count_params.py | parameter / KV-cache / FLOP calculator for DeepSeek-V3- and V4-style configs |
training/pretrain.yaml, training/train.py | NeMo Automodel recipe (FSDP2, 2 GPUs) and launcher that seeds the hash table and mHC mixers |
training/prepare_data.py, training/finite_nanogpt.py, training/init_utils.py | data shards from parquet text, bounded validation dataset, from-scratch initialisers |
transformers' native DeepseekV4Config only maps compression ratios 0 / 4 / 128 to layer types and raises
KeyError: 8 on this config. Load it with NeMo Automodel's DeepseekV4Config (below) or with DeepSeek's reference
inference/model.py via inference_config.json. The sibling repo akoumpa/Moonlight-V4-1B-h16d256 is transformers-loadable.
The same applies to AutoTokenizer, which parses config.json first. Load the tokenizer directly:
from transformers import PreTrainedTokenizerFast
tok = PreTrainedTokenizerFast.from_pretrained("akoumpa/Moonlight-V4-1B-h16d256-r8") # 129,280 tokens, BOS 0, EOS 1
from nemo_automodel.components.models.common import BackendConfig
from nemo_automodel.components.models.deepseek_v4.config import DeepseekV4Config
from nemo_automodel.components.models.deepseek_v4.model import DeepseekV4ForCausalLM
cfg = DeepseekV4Config.from_pretrained("akoumpa/Moonlight-V4-1B-h16d256-r8")
backend = BackendConfig(attn="eager", linear="torch", rms_norm="torch_fp32", rope_fusion=False,
dispatcher="torch", experts="torch_mm", enable_hf_state_dict_adapter=False)
model = DeepseekV4ForCausalLM(cfg, backend=backend)
model.initialize_weights(dtype=torch.bfloat16)
Or in a recipe: NeMoAutoModelForCausalLM.from_config with config: DeepseekV4Config.from_pretrained("akoumpa/Moonlight-V4-1B-h16d256-r8")
(see training/pretrain.yaml).
inference_config.json drops into the inference/ folder of the DeepSeek-V4 release (ModelArgs keys, n_mtp_layers 0).
The released implementations only ever load checkpoints, so two things must be initialised by hand; training/init_utils.py
does both and training/train.py calls it after the recipe's own weight init on a fresh start:
tid2eid is created as zeros (every token to expert 0). fill_hash_tables writes a balanced
token-id hash: 32 experts, 6 distinct experts per token, equal load over the vocabulary.fn / base / scale tensors uninitialised; init_hyper_connections applies
transformers' rule (normal(0, 0.02) projection, zero bias, unit gates).Recipe notes that cost time to find (all encoded in training/):
lm_head) as their
own FSDP2 units whose forward returns the parameter; if they reshard after forward, attention reads a freed tensor.
train.py calls set_reshard_after_forward(False) on those units.MaskedCrossEntropy: the fused linear cross-entropy rejects the fp32 lm_head x bf16 hidden states.dataloader.batch_size explicitly.NanogptDataset is an infinite stream; validation uses FiniteNanogptDataset.rope_scaling: factor 16, original_max_position_embeddings 65536)
and raise max_position_embeddings.Measured on two RTX 5880 Ada (48 GB, sm_89) GPUs, bf16, torch_mm experts, chunked cross-entropy, single-GPU forward+backward
(TileLang sparse attention with Sinkhorn on torch; the eager path for the same model reaches 4.2k tok/s at
B=2 x 2048 and runs out of memory at B=4):
| micro-batch | fwd+bwd time, throughput, peak memory |
|---|---|
| 2 x 2048 | 597 ms, 6.9k tok/s, 20.0 GiB |
| 4 x 2048 | 992 ms, 8.3k tok/s, 30.6 GiB |
| 2 x 4096 | 1049 ms, 7.8k tok/s, 30.7 GiB |
Forward-time breakdown at B=2 x 2048: attention 49 ms, MoE 36 ms, mHC mixers 34 ms, compressor 10 ms (147 ms forward). With the recipe's FSDP2 data parallelism over 2 GPUs and
AdamW, a 32-sequence x 2048-token global batch is a reasonable starting point (training/pretrain.yaml).
Automodel's vendored Miles/TileLang kernels (sparse attention, indexer) and DeepSeek's TileKernels Sinkhorn were written for Hopper's 227 KB of shared memory. On a 99 KB-per-block GPU:
| kernel | shape rule | shared memory | Ada (99 KB) |
|---|---|---|---|
| sparse attention fwd/bwd | head_dim power of two; heads padded to 16, chunked by 16, multiples of 64 above 64 | 147 KB at head_dim 512, fits at 256 | runs with this config; parity with the torch reference verified |
| lightning indexer fwd | index_n_heads <= 64, multiple of 8, divides 128; index_topk power of two (bwd) | 224 KB (block_N 256 x 128 fp32) | does not fit; this variant has no indexer |
| Sinkhorn (mHC) | needs the tile_kernels package | small | needs TileKernels installed or the torch fallback |
Automodel currently switches all three together (backend.attn: tilelang); the measurements above used per-kernel
selection (only sparse attention on TileLang). On Hopper GPUs the default head_dim 512 kernels fit and the 16 x 256
choice is optional.
deepseek-ai/DeepSeek-V4-Flash).