Skip to main content

PyTorch training for Hermes LLMs (MAL-defined models, safetensors checkpoints served by hermes-llm)

Project description

hermes-train

PyTorch training for Hermes LLMs. Architectures are defined in MAL (the Rust-side DSL in hermes-llm); this package trains them and emits safetensors checkpoints that hermes-llm serves directly — the tensor naming contract is shared (embedding.*, layers.{i}.attention.*, layers.{i}.feed_forward.*, final_norm.*, lm_head.*).

Pipeline

# 1. Export the architecture from MAL (Rust side owns the parser)
hermes-llm export --model tiny --output config.json          # preset
hermes-llm export --model my_model.mal --output config.json  # or MAL file

# 2. Train a BPE tokenizer (optional — any HF tokenizer.json works)
hermes-train train-tokenizer --input data.jsonl --output tokenizer.json --vocab-size 32000

# 3. Train (bf16, Muon+AdamW, grad accumulation, resumable)
hermes-train train --config config.json --tokenizer tokenizer.json \
    --data data.jsonl.zst --output checkpoints --batch-size 32 --epochs 1

# multi-GPU: same command under torchrun
torchrun --nproc-per-node 8 -m hermes_train.cli train --config config.json ...

# 4. DPO fine-tuning
hermes-train dpo --config config.json --tokenizer tokenizer.json \
    --data prefs.jsonl --checkpoint checkpoints/weights.safetensors --output checkpoints-dpo

# 5. Serve with the Rust side
hermes-llm generate --checkpoint checkpoints/weights.safetensors \
    --config config.json --tokenizer tokenizer.json --prompt "hello"

Training stack

  • Precision: bf16 autocast with fp32 master weights (fp32 fallback on CPU/MPS)
  • Optimizer: Muon (Newton–Schulz orthogonalized momentum) for 2D weight matrices, AdamW for embeddings/norms/head — the hybrid scheme used by Kimi K2 / GLM-scale runs
  • Schedule: WSD (warmup–stable–decay, the 2026 default) or cosine via --schedule; the flat plateau makes run extension and curricula sane
  • Data: JSONL with a text field; .gz / .zst supported; documents are tokenized, EOS-joined and packed into fixed windows
  • Document masking (default on): attention is block-diagonal across packed-document boundaries, SSM recurrent state resets at doc starts, and the reference path uses a segment-aware causal conv — doc 2 is provably independent of doc 1 (tested). The fused CUDA kernel (Mamba-1) has no seq_idx, so under the fused path SSM state crosses boundaries (warned once); attention layers still mask correctly. --no-doc-masking disables.
  • Curriculum stages: repeat -d — each file trains sequentially under one LR schedule, so with WSD the decay lands on your final (highest-quality / task-specific) stage
  • QK-Norm: qk_norm: true in a MAL attention def adds per-head RMSNorm on Q/K before RoPE (OLMo2/Gemma-style stabilizer); tensors layers.{i}.attention.{q,k}_norm.weight in both engines
  • Checkpoints: weights.safetensors (Candle-compatible names) + training_state.json; Ctrl+C saves and exits, --resume continues
  • Distributed: DDP via torchrun (gradient sync); FSDP is a planned upgrade

Hybrid Transformer + Mamba

MAL expresses heterogeneous layer stacks: blocks whose mixer is a Mamba-1 selective SSM instead of attention, cycled via pattern::

ssm my_ssm { state_dim: 16, conv_kernel: 4, expand: 2 }
block mamba_block { ssm: my_ssm, ffn: my_ffn, norm: rmsnorm { eps: 1e-5 } }
model hybrid { ..., pattern: [mamba_block, mamba_block, attn_block] }

The Mamba state is a compact persistent memory (fixed size, O(1)/token); the attention layers provide exact retrieval. Training uses a reference fp32 scan by default; install the mamba extra (uv sync --extra mamba, CUDA only) and the fused selective_scan_fn kernel is used automatically on CUDA. SSM tensors live under layers.{i}.ssm.* (mamba-ssm naming) and load directly into hermes-llm generate, which serves incrementally: prompt prefill once, then one step per token (Mamba recurrent state + attention KV cache — no full recompute).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hermes_train-1.8.57.tar.gz (103.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hermes_train-1.8.57-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file hermes_train-1.8.57.tar.gz.

File metadata

  • Download URL: hermes_train-1.8.57.tar.gz
  • Upload date:
  • Size: 103.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hermes_train-1.8.57.tar.gz
Algorithm Hash digest
SHA256 5986a53d4cd927b807a947770dc8bfe738ac7f8e1afd4da17d42dcbd1249e857
MD5 27e8dedfaee690775c1958fc1abb5df6
BLAKE2b-256 c1f7afeb5cc750d887c69d9dd793fd15530e24408b78376d5ace1e136eea59bd

See more details on using hashes here.

File details

Details for the file hermes_train-1.8.57-py3-none-any.whl.

File metadata

  • Download URL: hermes_train-1.8.57-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for hermes_train-1.8.57-py3-none-any.whl
Algorithm Hash digest
SHA256 99afb82f76ad338cc955185d923e95595a07fb073e5864cbb8033e8cdf2cd8c3
MD5 f438daedc9bf360197c7c549a98d3fc2
BLAKE2b-256 59489bef1d01248823325bf52a4c2be25aaf0481dd3c87f92b4ff2999b404f4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page