--- license: apache-2.0 library_name: pytorch tags: - hrm - hrm-text - recurrent-transformer - looped-transformer - universal-transformer - reproduction datasets: - sapientinc/HRM-Text-data-io-cleaned-20260515 --- # HRM-Text L (0.6B) reproduction + recurrent baselines: raw training checkpoints **中文摘要**:本仓库是 [HRM-Text](https://github.com/sapientinc/HRM-Text)(Sapient, arXiv:2605.20613)L 尺寸(约 0.69B 参数)参考训练的独立复刻,以及在**完全相同数据顺序与超参数**下训练的若干同参数量基线(transformer / Universal Transformer / gated-loop / soft-CoT loop / HRM full-backprop 尾段)。每个 run 保存了每个 epoch 的完整 FSDP2 分布式 checkpoint(模型 fp32 权重 + AdamATan2 优化器状态 + EMA 权重)、训练配置快照、模型源码快照与评测结果。HRM 复刻在 epoch 4 与官方公布的 8 项 benchmark 平均相差约 0.5pp。`code/` 是训练/评测所用的代码(上游 HRM-Text commit `5802461` + 本地修改与新增基线),`tokenizer/` 是训练所用的 65k BPE tokenizer。加载方式、评测与续训命令见下文。 --- ## 1. What this is [HRM-Text](https://github.com/sapientinc/HRM-Text) is a ~1B-scale text model built on the Hierarchical Reasoning Model architecture (a slow "H" module and a fast "L" module that are iterated recurrently, PrefixLM packing, FlashAttention 3, FSDP2), trained on instruction-style QA data produced by [sapientinc/data_io](https://github.com/sapientinc/data_io). Paper: *HRM-Text: Efficient Pretraining Beyond Scaling* ([arXiv:2605.20613](https://arxiv.org/abs/2605.20613)). Official released model: [sapientinc/HRM-Text-1B](https://huggingface.co/sapientinc/HRM-Text-1B). This repository is **not** the official release. It contains the raw checkpoints of an independent reproduction of the upstream **L-size reference run** (`arch/size@arch=L lr=2.5e-4 global_batch_size=172032`, 4 epochs), plus parameter-matched ablations trained on the bit-identical data stream. All runs were trained in Aug 2026 on 4 nodes x 8 H100 80GB (world size 32) of a Slurm cluster. Contents: | Path | What | | --- | --- | | `checkpoints/HRM-Text//` | the 10 runs below (9 full/partial training runs + 1 config-only smoke stub) | | `checkpoints/HRM-Text-smoke/smoke-gated-loop/` | a 2-node smoke test on the 273 MB smoke dataset (not a useful model) | | `code/` | the training / evaluation code used for these runs (see §6) | | `tokenizer/` | the 65,536-token BPE tokenizer used by every run (`tokenizer.json`, from `sapientinc/data_io` `trained_tokenizers/bpe/`) | ## 2. Runs and results All runs: size **L** (24 layers, hidden 1280, 10 heads of 128, SwiGLU expansion 4, RMSNorm pre-norm, RoPE theta 1e4, `lecun_normal` init, untied 65,536-token input embedding and output head), max sequence length 4096, PrefixLM with loss on response tokens only (`target_only=true`). Optimizer AdamATan2 (betas 0.9/0.95, weight decay 0.1), peak LR **2.5e-4**, 2,000 linear warmup steps then **constant** LR (`lr_min_ratio=1.0`), EMA decay 0.9999, bf16 forward/backward with fp32 master weights, global batch **172,032 tokens/step**, seed 0, **4 epochs = 348,257 optimizer steps** (~87,064 steps and 14.98 B tokens per epoch; ~59.9 B tokens total). Every run used 4 nodes x 8 GPUs (world size 32; smoke: 2 nodes, world size 16). | Run (`checkpoints/HRM-Text/...`) | `ARCH_NET` | Model class (`code/models/...`) | Params (incl. 1,280-elt `zL_init` buffer where present) | Recurrence / backprop schedule | Trained | Checkpoints | | --- | --- | --- | ---: | --- | --- | --- | | `L-4n-repro` | `hrm` | `baselines.hrm_nocarry_bp_warmup@HierarchicalReasoningModel` | 694,682,880 | H 12 layers + L 12 layers, `H_cycles=2 x L_cycles=3`; truncated BP warmup `bp_steps` 2 -> 5 over the first 20 % of steps (`bp_max_steps=5`, `bp_warmup_ratio=0.2`) | 4/4 epochs | epoch 1-4 | | `hrm-fullbp-L-4n` | `hrm_fullbp` | same class as `hrm` | 694,682,880 | same model; `bp_schedule=[2,3,4,5,8]`: four 17,413-step partial phases inside the 20 % window, then **full backprop** (8 = 2 H + 6 L segments) from step ~69,652 to the end. Also ran in-training held-out eval every 1,000 steps (raw weights) | 4/4 | epoch 1-4 | | `transformer-L-4n` | `transformer` | `baselines.transformer_wrapper@TransformerWrapper` | 694,681,600 | plain 24-layer transformer, no recurrence | 4/4 | epoch 1-4 | | `ut-L-4n` | `ut` | `baselines.ut_nocarry@UniversalTransformer` | 694,682,880 | one shared 24-layer stack x 4 cycles, `z <- core(z + x)`; BP cycles warm up 2 -> 4 (full) over the first 20 % | 4/4 | epoch 1-4 | | `gated-loop-L-4n` | `gated_loop` | `baselines.gated_loop@GatedLoopTransformer` | 697,958,400 | shared 24-layer stack x 4 cycles; z0 = x (token embedding), `z_{i+1} = W1(h_i) * SiLU(W2(x))` with shared bias-free d x d W1/W2; output = last h; BP cycles 2 -> 4 over the first 20 % | 4/4 | epoch 1-4 | | `loop-cot-v2-L-4n` | `loop_cot_v2` | `baselines.loop_cot@LoopedCoTTransformer` | 694,686,723 | UT-style 4-cycle loop plus a soft-CoT channel `z <- core(z + a*decode(z) + x)`, `decode` = top-128 softmax read out through `lm_head`, written back through `scale * W_in`; per-cycle learned per-token gates, alpha fixed 0 on cycle 0 and gates enabled only after BP warmup | 4/4 | epoch 1-4 | | `loop-cot-b1-L-4n` | `loop_cot` + `arch.cot_beta_fixed=1.0` | `baselines.loop_cot@LoopedCoTTransformer` | 694,684,161 | v1 soft-CoT loop (**mis-wired readout**: decodes through the input embedding, `cot_decode_readout=embed`), beta fixed to 1 | 4/4 | epoch 1-4 | | `loop-cot-L-4n` | `loop_cot` | same | 694,685,442 | v1 soft-CoT loop (mis-wired readout), learned alpha and beta gates | **stopped** at step 195,000 (epoch 3, batch 20,873) | epoch 1, 2 + mid-epoch step 195,000 | | `loop-cot-a011-L-4n` | `loop_cot` + `arch.cot_alpha_fixed_per_cycle=[0,1,1,1]` | same | 694,682,880 | v1 soft-CoT loop (mis-wired), alpha forced to [0,1,1,1] (channel fully on, cycle 0 skips decode), beta fixed 1 | **stopped** at step 195,000 | epoch 1, 2 + mid-epoch step 195,000 | | `gated-loop-smoke` | `gated_loop` | — | — | config/metadata/source snapshot only, **no weights** | — | none | | `HRM-Text-smoke/smoke-gated-loop` | `gated_loop` | `GatedLoopTransformer` | 697,958,400 | smoke test: 2 nodes (world 16), smoke data (37.3 M tokens/epoch), 866 steps | 4/4 (smoke) | epoch 1-4 | The exact resolved config of every run is in `/all_config.yaml`; `/train_metadata.yaml` holds the dataset metadata (tokens per epoch, special tokens). The `.py` file in each run dir is the model source **as it was when the run started** (the trainer snapshots it). For `ut`, `transformer`, `gated_loop`, `hrm_fullbp` and `loop-cot-v2` it is identical to `code/models/baselines/`; for `L-4n-repro` and the three v1 `loop-cot` runs the current code is a backward-compatible superset (new options default to the old behaviour; e.g. `cot_decode_readout` defaults to `embed`, `bp_schedule` defaults to `None`). ### 2.1 Benchmarks and held-out loss (per epoch) Benchmarks were run with the upstream evaluation code on the EMA weights (`code/slurm/eval_bench_multi.py`, prompts sharded over 8 GPUs, greedy decoding): GSM8k and MATH zero-shot CoT (`condition="synth,cot"`), the rest few-shot `condition="direct"`; DROP is F1, everything else accuracy (%). BBH = official 3-shot CoT prompts, 27 tasks, macro-averaged; it was added late, so it is missing for early evaluations. Eval loss = mean cross-entropy per supervised (response) token on a held-out split of 20.8 M tokens sampled from the 77 % of the corpus that the 4 training epochs never reference (`code/slurm/make_eval_split.py`, `eval_seed=1000`), for EMA and raw weights. Raw numbers per epoch are in `/benchmark_results.json` and `/eval_loss.json` (keyed by epoch; `eval_loss.json` of loop-cot runs also has per-cycle channel statistics `cot_stats`). | Run | Ep | GSM8k | MATH | DROP | MMLU | ARC-C | HellaSwag | Winogrande | BoolQ | BBH | Eval loss EMA | Eval loss raw | | --- | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | --: | | *upstream reference L (published)* | 4 | 77.6 | 51.2 | 78.6 | 56.6 | 75.9 | 52.7 | 67.6 | 85.0 | — | — | — | | L-4n-repro | 1 | 59.7 | 36.0 | 59.2 | 43.6 | 50.8 | 34.5 | 56.2 | 72.2 | — | 1.3629 | 1.4666 | | L-4n-repro | 2 | 73.9 | 46.0 | 74.5 | 52.1 | 66.7 | 44.6 | 62.5 | 80.8 | — | 1.2569 | 1.3858 | | L-4n-repro | 3 | 76.4 | 48.7 | 77.7 | 55.4 | 72.2 | 49.0 | 65.2 | 83.9 | — | 1.2216 | 1.3580 | | L-4n-repro | 4 | 79.0 | 51.0 | 78.5 | 56.7 | 75.2 | 53.1 | 66.5 | 85.2 | 36.9 | 1.2033 | 1.3405 | | hrm-fullbp-L-4n | 1 | 63.5 | 37.7 | 63.8 | 45.4 | 55.0 | 36.6 | 56.9 | 72.6 | 31.4 | 1.3509 | 1.4543 | | hrm-fullbp-L-4n | 2 | 77.8 | 47.8 | 77.6 | 54.9 | 71.9 | 48.4 | 65.7 | 83.4 | 35.4 | 1.2431 | 1.3730 | | hrm-fullbp-L-4n | 3 | 80.4 | 51.0 | 80.2 | 57.8 | 75.9 | 54.3 | 66.2 | 85.7 | 34.9 | 1.2086 | 1.3458 | | hrm-fullbp-L-4n | 4 | 81.8 | 53.0 | 81.3 | 58.5 | 79.4 | 58.3 | 67.7 | 86.5 | 37.2 | 1.1925 | 1.3295 | | transformer-L-4n | 1 | 41.3 | 26.7 | 38.2 | 40.2 | 42.2 | 29.9 | 55.4 | 63.3 | — | 1.4145 | 1.5197 | | transformer-L-4n | 2 | 54.7 | 33.9 | 56.7 | 43.9 | 49.9 | 32.0 | 57.4 | 74.1 | — | 1.3305 | 1.4540 | | transformer-L-4n | 3 | 58.2 | 37.7 | 62.1 | 46.6 | 57.9 | 32.9 | 58.5 | 76.0 | — | 1.2963 | 1.4263 | | transformer-L-4n | 4 | 61.6 | 38.2 | 64.8 | 48.3 | 61.1 | 34.8 | 57.9 | 75.6 | 28.4 | 1.2781 | 1.4080 | | ut-L-4n | 1 | 58.8 | 36.2 | 62.2 | 46.4 | 54.4 | 35.2 | 56.2 | 72.6 | — | 1.3277 | 1.4380 | | ut-L-4n | 2 | 72.0 | 44.8 | 73.7 | 53.8 | 68.6 | 45.7 | 60.4 | 81.0 | — | 1.2394 | 1.3715 | | ut-L-4n | 3 | 76.6 | 47.5 | 76.2 | 55.6 | 72.4 | 50.4 | 65.0 | 83.8 | — | 1.2096 | 1.3437 | | ut-L-4n | 4 | 78.2 | 50.1 | 78.1 | 57.0 | 75.1 | 53.0 | 66.1 | 83.0 | 35.3 | 1.1931 | 1.3301 | | gated-loop-L-4n | 1 | 56.3 | 34.5 | 61.2 | 44.2 | 50.8 | 33.7 | 56.9 | 75.2 | 30.3 | 1.3481 | 1.4539 | | gated-loop-L-4n | 2 | 71.0 | 43.7 | 73.2 | 52.4 | 66.6 | 40.2 | 61.5 | 79.3 | 34.5 | 1.2575 | 1.3872 | | gated-loop-L-4n | 3 | 75.0 | 46.4 | 76.1 | 54.9 | 72.6 | 48.1 | 64.5 | 84.2 | 36.2 | 1.2251 | 1.3597 | | gated-loop-L-4n | 4 | 76.2 | 49.8 | 77.2 | 55.7 | 74.7 | 51.0 | 65.4 | 84.1 | 34.8 | 1.2078 | 1.3436 | | loop-cot-v2-L-4n | 1 | 60.3 | 36.9 | 62.8 | 45.6 | 54.9 | 35.8 | 58.5 | 74.6 | 3.5* | 1.3256 | 1.4363 | | loop-cot-v2-L-4n | 2 | 72.0 | 45.6 | 74.6 | 53.4 | 70.6 | 46.5 | 63.5 | 79.1 | 14.6* | 1.2316 | 1.3624 | | loop-cot-v2-L-4n | 3 | 75.1 | 48.7 | 77.2 | 56.6 | 75.5 | 51.7 | 65.1 | 81.2 | 34.6 | 1.1983 | 1.3350 | | loop-cot-v2-L-4n | 4 | 77.3 | 49.8 | 78.0 | 57.6 | 77.4 | 54.3 | 65.8 | 83.2 | 33.5 | 1.1807 | 1.3182 | | loop-cot-b1-L-4n | 1 | 58.0 | 34.3 | 58.2 | 43.8 | 51.0 | 34.3 | 55.4 | 73.4 | — | 1.3520 | 1.4678 | | loop-cot-b1-L-4n | 2 | 70.0 | 43.3 | 71.0 | 50.1 | 63.9 | 41.0 | 60.1 | 78.5 | — | 1.2680 | 1.3992 | | loop-cot-b1-L-4n | 3 | 74.7 | 46.2 | 74.3 | 53.1 | 70.0 | 48.0 | 62.7 | 81.7 | — | 1.2325 | 1.3695 | | loop-cot-b1-L-4n | 4 | 76.6 | 48.7 | 76.5 | 55.8 | 74.0 | 49.1 | 64.4 | 82.7 | — | 1.2140 | 1.3504 | | loop-cot-L-4n | 1 | 58.7 | 34.4 | 60.6 | 44.7 | 52.4 | 34.0 | 56.3 | 72.0 | — | 1.3440 | 1.4558 | | loop-cot-L-4n | 2 | 70.8 | 44.3 | 71.2 | 51.2 | 64.8 | 42.9 | 60.1 | 79.3 | — | 1.2588 | 1.3905 | | loop-cot-a011-L-4n | 1 | 44.1 | 27.8 | 36.4 | 37.5 | 34.9 | 31.0 | 52.3 | 66.5 | — | 1.4482 | 1.5513 | | loop-cot-a011-L-4n | 2 | 59.6 | 37.3 | 60.7 | 44.5 | 51.6 | 33.9 | 56.1 | 73.0 | — | 1.3386 | 1.4686 | \* The loop-cot-v2 epoch 1/2 BBH values are as stored in `benchmark_results.json`; they are far below every other BBH value and were not re-scored with the later BBH answer parser (`code/slurm/rescore_bbh.py` re-scored only L-4n-repro/ut/transformer ep4 and loop-cot-v2 ep3/ep4), so treat them as unreliable. The mid-epoch `fsdp2_step_195000` checkpoints were not evaluated. Short reading of the ablations (same params, same data order, same hyperparameters): every looped variant is far ahead of the plain transformer; the plain shared-weight loop (`ut`) matches HRM (EMA eval loss 1.1931 vs 1.2033, benchmarks within ~0.6 pp on average), so the H/L split shows no measurable independent benefit at this scale (caveat: `ut` warms up to full backprop, ~33 % more backward cost per step than `hrm`); continuing HRM's warmup into full backprop (`hrm-fullbp`) gives the best epoch-4 score on all 9 benchmarks (but not the lowest eval loss); the soft-CoT channel only helps once it reads out through `lm_head` (`loop-cot-v2`, best eval loss 1.1807). Generations: `L-4n-repro`, `ut-L-4n`, `transformer-L-4n` and `loop-cot-v2-L-4n` contain a `generations/` dir with per-prompt prompt/generation dumps (`_ep.jsonl`) of some benchmark evaluations. ## 3. File layout and checkpoint format ```text checkpoints/HRM-Text// ├── all_config.yaml # resolved PretrainConfig (arch, LR, batch, epochs, ...); paths are the original cluster paths ├── train_metadata.yaml # dataset metadata: tokens/epoch, max_seq_len, vocab, special tokens, tokenizer path (cluster path!) ├── .py # snapshot of the model source at run start ├── fsdp2_epoch_/ # torch.distributed.checkpoint (DCP) directory, one per finished epoch │ ├── .metadata # DCP index (written last; a dir without it is incomplete) │ └── ___0.distcp # one shard per training rank (32 x ~348 MB = 10.4 GiB) ├── carry_epoch_..pt # per-rank recurrent "carry" (tiny; the *_nocarry models keep no state, but the loader expects rank 0's file) ├── train_state_epoch_.json # {"step": global step at the end of epoch N, "world_size": 32} ├── fsdp2_step_195000/ , carry_step_195000..pt , train_state_step_195000.json # loop-cot-L-4n / loop-cot-a011-L-4n only: mid-epoch resume point ├── benchmark_results.json # {epoch: {benchmark: {...}}} ├── eval_loss.json # {epoch: {"ema/loss", "raw/loss", "ema/accuracy", ...}} └── generations/ # some runs only, see above ``` Each `fsdp2_epoch_` DCP checkpoint holds the full training state: * `model.` — fp32 raw (non-EMA) weights, plus the bf16 buffer `model.model.zL_init` for HRM-type models. `` is the key in `LMHead(model).state_dict()`, e.g. `model.H_level.core.layers.0.attn.gqkv_proj.weight`, `embed_tokens.embedding_weight`, `lm_head.weight`. * `optim.state..param_ema` — **EMA weights** (decay 0.9999), one per parameter. * `optim.state..{exp_avg,exp_avg_sq,step}` and `optim.param_groups` — AdamATan2 state, needed only to resume training. The EMA weights are what all benchmark numbers above use and what you normally want. The upstream tools (`simple_inference_engine.py`, `evaluation.main`, `conversion/convert_to_hf.py`) load EMA by default. Download (one run / one epoch is ~10.4 GiB): ```bash pip install -U "huggingface_hub[hf_transfer]" HF_HUB_ENABLE_HF_TRANSFER=1 hf download fhyfhy/HRM-Text-checkpoints \ --include "code/*" "tokenizer/*" \ "checkpoints/HRM-Text/L-4n-repro/*.yaml" "checkpoints/HRM-Text/L-4n-repro/*.json" \ "checkpoints/HRM-Text/L-4n-repro/carry_epoch_4.0.pt" \ "checkpoints/HRM-Text/L-4n-repro/fsdp2_epoch_4/*" \ --local-dir HRM-Text-checkpoints ``` (`fsdp2_epoch_4/*` includes the hidden `.metadata` file; check it is present.) ## 4. Loading a checkpoint ### 4.1 Plain PyTorch, CPU or GPU, weights only (verified) This needs only `torch` (>= 2.4), `pyyaml`, `pydantic`, `einops` and the `code/` dir. It reads only the model/EMA tensors out of the DCP checkpoint, without materializing the optimizer state. Model construction imports `flash_attn_interface` (FlashAttention 3); for CPU-only weight inspection you can stub that module, as below — the forward pass itself needs FA3 on a Hopper GPU. ```python import sys, types, yaml, torch import torch.distributed.checkpoint as dcp REPO = "HRM-Text-checkpoints" # local download dir sys.path.insert(0, f"{REPO}/code") try: import flash_attn_interface # real FA3 (needed to run the model) except ImportError: # CPU-only: stub it, weights still load stub = types.ModuleType("flash_attn_interface") for n in ["flash_attn_with_kvcache", "_flash_attn_backward", "_flash_attn_forward", "maybe_contiguous"]: setattr(stub, n, None) sys.modules["flash_attn_interface"] = stub from utils.functions import load_model_class run, epoch, use_ema = f"{REPO}/checkpoints/HRM-Text/L-4n-repro", 4, True cfg_all = yaml.safe_load(open(f"{run}/all_config.yaml")) meta = yaml.safe_load(open(f"{run}/train_metadata.yaml")) cfg = cfg_all["arch"] | meta | cfg_all["data"] # same merge as simple_inference_engine.py model = load_model_class(cfg["head"])(load_model_class(cfg["name"])(cfg), cfg) # LMHead() ckpt_dir = f"{run}/fsdp2_epoch_{epoch}" md = dcp.FileSystemReader(ckpt_dir).read_metadata().state_dict_metadata targets, mapping = {}, {} for k in model.state_dict(): ema_key = f"optim.state.{k}.param_ema" src = ema_key if (use_ema and ema_key in md) else f"model.{k}" # buffers (zL_init) have no EMA if src not in md: continue targets[src] = torch.empty(md[src].size, dtype=md[src].properties.dtype) mapping[k] = src dcp.load(targets, checkpoint_id=ckpt_dir, no_dist=True) missing, unexpected = model.load_state_dict({k: targets[s] for k, s in mapping.items()}, strict=False) assert not missing and not unexpected model = model.to(torch.bfloat16).eval() # training/eval forward dtype ``` Verified on `L-4n-repro` epoch 4 on CPU (torch 2.11, FA3 stubbed): 99 tensors loaded (98 from EMA + the `zL_init` buffer), no missing/unexpected keys, 694,681,600 parameters, EMA differs from raw weights as expected; ~5.5 min on a busy login node (most of it reading the 10.4 GiB shards). Use `use_ema=False` for the raw weights. For generation, wrap the model the way `code/simple_inference_engine.py` does (`InferenceCheckpoint` + `inference_generate`): prompts are `<|im_start|>` + condition tokens + question + `<|im_end|>` (condition tokens: `direct` = `<|object_ref_start|>`, `cot` = `<|object_ref_end|>`, `synth` = `<|quad_end|>`, `noisy` = `<|quad_start|>`), and the answer ends at `<|box_end|>`. Load the tokenizer with `AutoTokenizer.from_pretrained(f"{REPO}/tokenizer")`. ### 4.2 Upstream loader (GPU, full environment) `code/simple_inference_engine.py::inference_load_checkpoint(ckpt_path, ckpt_epoch, ckpt_use_ema=True)` builds the model on CUDA, loads model **and** optimizer state with DCP (`no_dist=True`), swaps in the EMA weights, casts to bf16 and loads the tokenizer from `train_metadata.yaml: tokenizer_info.tokenizer_path`. That path is the original cluster path, so first point it at the bundled tokenizer: ```bash cd HRM-Text-checkpoints sed -i "s#tokenizer_path: .*#tokenizer_path: $PWD/tokenizer/tokenizer.json#" checkpoints/HRM-Text/*/train_metadata.yaml ``` It also needs `carry_epoch_.0.pt` next to the DCP dir, and ~12 GB of host/GPU memory for the optimizer state it loads. Environment: the upstream Docker image `sapientai/hrm-text:latest` (PyTorch + CUDA 12.8 + FlashAttention 3, Hopper GPU), or `pip install -r code/requirements.txt` + FA3 as in `code/docker/Dockerfile`. ### 4.3 Export to a Transformers-style folder (HRM runs only) ```bash cd HRM-Text-checkpoints/code python -m conversion.convert_to_hf --ckpt_path ../checkpoints/HRM-Text/L-4n-repro --ckpt_epoch 4 \ --tokenizer_path ../tokenizer --out_dir /path/to/hrm-text-L-repro-hf ``` Writes `config.json` (`model_type: hrm_text`), `model.safetensors` (EMA) and the tokenizer. The key remapping only knows the HRM architecture (`L-4n-repro`, `hrm-fullbp-L-4n`); it does not apply to the baselines. Not tested as part of this upload. ## 5. Evaluation and training commands All commands run from `code/` (the trainer, evaluator and scripts expect the repo root as CWD). The `code/slurm/*.sbatch` / `*.sh` scripts are the exact wrappers used, but they hard-code the original cluster (Lustre paths under `/lustre/fsw/...`, a pyxis/enroot `.sqsh` image, partitions, `NVIDIA_VISIBLE_DEVICES`/`HF_HOME` workarounds); `code/slurm/README.md` documents them. Below are the cluster-independent equivalents. ### 5.1 Benchmarks ```bash # single GPU, upstream entrypoint (EMA weights, newest epoch unless ckpt_epoch is given) python -m evaluation.main ckpt_path=../checkpoints/HRM-Text/L-4n-repro ckpt_epoch=4 \ run_only=[GSM8k,MATH] # optional; add generation_config.batch_size=16 on OOM # 8 GPUs, prompts sharded across ranks (what produced the numbers above; merges into /benchmark_results.json) OMP_NUM_THREADS=1 torchrun --standalone --nproc_per_node=8 slurm/eval_bench_multi.py \ ckpt_path=../checkpoints/HRM-Text/L-4n-repro ckpt_epoch=4 ``` Benchmarks are pulled from the Hugging Face Hub via `datasets` on first use. ~15 min for the full suite on 8 H100. ### 5.2 Held-out eval loss ```bash OMP_NUM_THREADS=1 torchrun --nproc_per_node=8 slurm/eval_loss.py \ --ckpt_path ../checkpoints/HRM-Text/L-4n-repro --eval_data /path/to/eval_split ``` Scores every epoch checkpoint with raw and EMA weights and merges into `/eval_loss.json`. The held-out split itself is **not** included here; rebuild it with `slurm/make_eval_split.py tokenized_path= output_path= prefix_config_path=/prefix_config.yaml epochs=4 seed=0 eval_seed=1000` (needs the tokenized corpus, §5.4). ### 5.3 Training from scratch / resuming Reference L run, one 8-GPU node (the upstream recipe): ```bash OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 torchrun --nproc_per_node=8 pretrain.py \ arch/net@arch=hrm arch/size@arch=L lr=2.5e-4 global_batch_size=172032 epochs=4 \ data.path=/dev/shm/sampled +seed=0 +project_name=HRM-Text +run_name=my-run \ +checkpoint_path=checkpoints/HRM-Text/my-run ``` What these checkpoints used: the same command on **4 nodes** (`torchrun --nnodes=4 --nproc_per_node=8 --node_rank= --rdzv_backend=c10d --rdzv_endpoint=: ...`), with `arch/net@arch=` one of `hrm`, `hrm_fullbp`, `transformer`, `ut`, `gated_loop`, `loop_cot`, `loop_cot_v2`, plus `+checkpoint_step_interval=5000` (rolling mid-epoch checkpoints) and, for `hrm-fullbp-L-4n`, `+eval_data_path= +eval_interval=1000`. Variant overrides: `loop-cot-b1` = `arch.cot_beta_fixed=1.0`; `loop-cot-a011` = `arch.cot_alpha_fixed_per_cycle=[0.0,1.0,1.0,1.0] arch.cot_beta_fixed=1.0`. Hydra keys not in `config/cfg_pretrain.yaml` need a `+` prefix. Weights & Biases logging is used; set `WANDB_MODE=offline` if you do not want to log online. Node-count constraint: the multipack sampler needs `global_batch_size / world_size >= 4096` (max sequence length) and exact divisibility; with 172,032 tokens and 8 GPUs/node that allows 1, 2, 3 or 4 nodes. The data stream is bit-identical across node counts for a given world size; continuing a run (`resume_continue`) requires the **same world size** as the checkpoint (32 here). Resume / continue one of these runs (restores step counter, LR schedule, optimizer, EMA, carry and data position; the deterministic sampler skips already-seen batches): ```bash torchrun --nnodes=4 --nproc_per_node=8 ... pretrain.py \ arch/net@arch=hrm arch/size@arch=L lr=2.5e-4 global_batch_size=172032 epochs=4 data.path=/dev/shm/sampled \ +seed=0 +run_name=L-4n-repro +checkpoint_path=checkpoints/HRM-Text/L-4n-repro \ +resume_from=checkpoints/HRM-Text/L-4n-repro +resume_epoch=4 +resume_continue=true # mid-epoch: +resume_from= +resume_step=195000 +resume_continue=true ``` Fine-tuning from a checkpoint on a different world size / new data (fresh optimizer, EMA swapped into the model): `+resume_from= +resume_epoch=4 +weights_only_resume_from_ema=true` (drop the `+` if your config already has the key; see the upstream SFT section in `code/README.md`, `--config-name cfg_sft`). ### 5.4 Data Training data = the upstream recipe: the cleaned instruction-style corpus [`sapientinc/HRM-Text-data-io-cleaned-20260515`](https://huggingface.co/datasets/sapientinc/HRM-Text-data-io-cleaned-20260515) (178.6 B tokens after tokenization), tokenized with the bundled BPE tokenizer, then stratified-sampled with `data_io/sample_tokenized.py` / `prefix_config.yaml`, `epochs=4 seed=0` (data_io commit `c82cd5f`). Instead of the upstream `data_io` Rust tokenizer and per-node sampling we used the equivalent `code/slurm/py_tokenize.py` (element-wise identical output) and `code/slurm/sample_and_compact.py` (RNG call-for-call identical to `sample_tokenized.py`; keeps only the 22.7 % of tokens the 4 epochs reference, ~83 GB), so the training stream is bit-identical to upstream's sampler. The sampled data are not included here. Commands: `code/slurm/README.md` §5. ## 6. Code (`code/`) * Upstream: [sapientinc/HRM-Text](https://github.com/sapientinc/HRM-Text) at commit **`5802461cde4bafa8fefb5f43513880b46c119c7b`** ("Add experimental branch in README.md", 2026-06-17), all tracked files. * Local modifications to tracked files (working tree as used for these runs; the full diff against the commit is in `code/LOCAL_CHANGES.patch`): `pretrain.py` (step-level checkpoints and deterministic mid-epoch resume, `resume_continue`, in-training eval, W&B robustness), `dataset_new.py` (resume offsets, `fixed_epoch` eval iteration), `models/baselines/hrm_nocarry_bp_warmup.py` (`bp_schedule`), `models/baselines/ut_nocarry.py` + `config/arch/net/ut.yaml` (BP-cycle warmup), `models/lm_head.py` (passes the embedding / `lm_head` matrices to models with a decode channel, i.e. loop_cot), `simple_inference_engine.py` (tokenizer path), `evaluation/{benchmarks.py,engines.py,config/hrm_benchmarking.yaml}` (BBH, lazy vLLM import). * New files: `models/baselines/{gated_loop,loop_cot,looped_tf}.py`, `config/arch/net/{gated_loop,hrm_fullbp,loop_cot,loop_cot_v2,looped_tf}.yaml`, `slurm/` (cluster launch/eval scripts, data pipeline, eval-loss, plotting, README), `plots/` (trajectory figures of the runs above). * Not included: data, logs, W&B runs, outputs, container images, credentials. ## 7. License / provenance * **Code**: HRM-Text is © Sapient Intelligence, Apache License 2.0 (`code/LICENSE`); local modifications are released under the same license. The tokenizer comes from `sapientinc/data_io` (Apache 2.0). * **Weights**: trained from scratch by the uploader with the code above; released under Apache 2.0 like the upstream model ([sapientinc/HRM-Text-1B](https://huggingface.co/sapientinc/HRM-Text-1B) is Apache 2.0). They are not affiliated with or endorsed by Sapient. * **Training data**: [`sapientinc/HRM-Text-data-io-cleaned-20260515`](https://huggingface.co/datasets/sapientinc/HRM-Text-data-io-cleaned-20260515), licensed ODC-BY on the Hub. It is a mixture assembled by `sapientinc/data_io` from many public sources (e.g. Open-Orca/FLAN, PleIAs/SYNTH, the DeepMind mathematics dataset and other Hugging Face datasets listed in the data_io cleaning scripts); the licenses of the individual upstream sources vary and were not audited here (unknown per source). Benchmark prompts in `generations/` come from the public benchmark datasets used by the evaluation code. * Not an official Sapient release. No safety tuning or evaluation beyond the benchmarks above. ## Citation ```bibtex @misc{wang2026hrmtextefficientpretrainingscaling, title={HRM-Text: Efficient Pretraining Beyond Scaling}, author={Guan Wang and Changling Liu and Chenyu Wang and Cai Zhou and Yuhao Sun and Yifei Wu and Shuai Zhen and Luca Scimeca and Yasin Abbasi Yadkori}, year={2026}, eprint={2605.20613}, archivePrefix={arXiv}, primaryClass={cs.CL}, url={https://arxiv.org/abs/2605.20613} } ```