# Repository Briefing: Tencent-Hunyuan/RiRoPE
> Source: https://repoforai.com/repo/Tencent-Hunyuan/RiRoPE (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/Tencent-Hunyuan/RiRoPE
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: See repository
- **Engineering Health**: B (53/100 · Maintenance 35/35 · Adoption 1/25 · Releases 11/20 · License 6/20)
- **Review Snapshot**: 2026-12-01
- **Deployment / Stack Signals**: GPU, CLI
- **Momentum**: 21 ★ total (+18 24h / +21 7d) · 0 forks
- **When to Use**: Best for: Research teams with SM90 access that need controlled OLMo-3-7B comparisons of sparse positional encodings, long-context extrapolation tests, or a local checkpoint-to-evaluation workflow. Skip if: You need a production inference server with padded multi-request batching, verified support beyond SM90, a predictable VRAM and throughput budget without profiling, or clear commercial licensing out of the box.

## Overview
```text
### Architecture & Core Mechanics
RiRoPE changes the coordinates used by sparse global attention, not the order of selected tokens. For each query, selected keys receive consecutive indices in their original order, with unselected gaps removed. Relative distances therefore stay in [0, B−1] for attention budget B rather than growing with the full sequence. Training and inference use the same rule. The OLMo-3-7B sparse backbone combines 24 sliding-window RoPE layers (4,096 tokens) with eight global layers that select the top 16 historical blocks plus the current block, at 128 tokens per block. These layers use block-count-corrected LogGate and softmax1; the RiRoPE indexer uses NoPE.

Fused SM90 sparse-attention kernels live in `focus/`. The `model` package registers two custom model types with Transformers, while `configs/` carries stage and variant configurations and `third_party/olmes/` freezes the evaluation harness. The locked Python 3.11 environment couples PyTorch 2.9.1 with CUDA 12.9 and Transformers 5.2.0; the stack also includes VeOmni, FlashAttention, Triton, NVIDIA CuTe DSL and Quack. Configured model variants and Transformers registration are the documented integration points.

### Key Capabilities & Differentiators
The workflow spans dense Stage-1 checkpoint conversion, 8K and 64K continued pretraining, DCP-to-HF export, and standalone Hugging Face generation. Sparse initialization derives indexer weights through grouped FP32 head averaging. The two stages budget roughly 50B tokens each; moving to Stage 3 transfers model weights but starts a fresh optimizer and LR schedule. Resuming within a stage can restore optimizer, dataloader and SkipStep state. Six training variants cover dense RoPE, sparse positional baselines, RiRoPE, and an `index_nope` control that can switch to RiRoPE at inference without changing weights.

After matched 64K continued pretraining, RiRoPE scored 80.24 versus sparse RoPE+YaRN's 74.10 on 64K RULER, and 72.17 versus 15.21 at 512K without further training or retuning. On HELMET it scored 47.37 at 64K and 51.13 on the 256K extension; the latter averages five categories and is not a like-for-like comparison across lengths. The CLI also covers 12 general-capability benchmarks. Evaluation uses batch size 1 and 4,096-token prefill chunks above 32,768 tokens, with options for parallel workers or layer sharding across GPUs.

### Trade-offs & Limitations
The strongest evidence is the comparison with sparse RoPE+YaRN on the same backbone, which isolates the positional choice more directly than the dense RoPE+YaRN baseline does. The improvement is not uniform across alternatives: sparse NoPE scores 49.20 versus RiRoPE's 47.37 on 64K HELMET, and 70.63 versus 72.17 on 512K RULER. Reindexing preserves order but discards the original distances across skipped tokens in global layers. It changes how selected keys are positioned; it cannot recover a historical block the indexer did not select.

Operationally, native training and paper-matched evaluation come at the cost of a specialized runtime. Sparse inference requires SM90, batch size 1 and unpadded inputs. The benchmark scores establish neither latency nor throughput, and the two 50B-token stages make full replication a different undertaking from checkpoint evaluation. Measure peak VRAM and prefill time on the target context before choosing a GPU layout. The repository license is unspecified, so verify rights before commercial deployment or redistribution.

### Hardware & Deployment Guide
Plan for Linux x86_64, an NVIDIA SM90 GPU (tested on H20), CUDA 12.9 with `nvcc`, and a C++ compiler. `scripts/setup.sh` runs `pixi install --locked` and checks the stack; FlashAttention builds from source on first install. A build or login node can use `--skip-gpu-check`, then run `pixi run --locked check` on a compute node. The documented full recipes show eight GPUs and support multi-node FSDP2 with shared access to data and outputs. A generated fixture provides a two-GPU smoke path without external data.

Model and dataset access default to offline, so stage checkpoints, training Parquet shards and evaluation assets locally; the long-length RULER and HELMET extensions have separate data layouts. Full HELMET adds a judge for LongQA and summarization and local T5 NLI for citation, whereas the documented judge-free subset runs through 128K. This is a local CLI and Transformers workflow, not a turnkey serving deployment. The manifest version is 0.1.0, and there is no GitHub release milestone to anchor an upgrade plan.
```

## Key Capabilities
```text
- Position encoding: Query-dependent reindexing bounds relative distances to [0, B−1] during both training and inference.
- Attention layout: 24 local RoPE layers use a 4,096-token window; eight sparse global layers select 16 historical 128-token blocks plus the current block.
- Training recipe: Continue OLMo-3-7B at 8K and then 64K for roughly 50B tokens per stage, using FSDP2/BF16 and a fresh optimizer and LR schedule at the stage transition.
- Extrapolation: RiRoPE scored 80.24 at 64K and 72.17 at 512K on RULER without further training or positional retuning.
- Evaluation: Frozen OLMES harness covers general tasks, RULER through 512K and a five-category HELMET extension at 256K.
- Verification: Locked Pixi environment, a generated two-GPU smoke fixture, and regression tests for model, kernels, conversion, recovery and evaluation.
```

## Quick Start / Clone
```bash
curl -fsSL https://pixi.sh/install.sh | bash   # skip if Pixi is already installed
bash scripts/setup.sh
```
