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.55.tar.gz (101.6 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.55-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hermes_train-1.8.55.tar.gz
  • Upload date:
  • Size: 101.6 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.55.tar.gz
Algorithm Hash digest
SHA256 cedb4ce84a2dc2c73e174212a38f79cf8213a2c66f67517bfdd0e2d84724eda0
MD5 4de1a64fc0fb0ad1cf9a54b267db94dc
BLAKE2b-256 8ed6d29cf82fcf70f5651684696b7637babf7bf2876d02d399f087a83cd0085b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hermes_train-1.8.55-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.55-py3-none-any.whl
Algorithm Hash digest
SHA256 4f0e2b7826d7c239495de6e7bde08e079ff0ab58ba2cd47a43ebf496b095047e
MD5 d2984776f4e37c308daa2da5a7df0498
BLAKE2b-256 114ec71af90b8ad3461cec20c8b1e1af2ced98b5226a2f333da1c2fedd1eb2bc

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