Buckets:
| Name | Size | Uploaded | Xet hash |
|---|---|---|---|
| assets | 1 items | ||
| config | 16 items | ||
| data | 17 items | ||
| .gitattributes | 214 Bytes xet | 2d065275 | |
| .gitignore | 792 Bytes xet | 25dfef92 | |
| LICENSE | 1.08 kB xet | 6e5c0d47 | |
| README.md | 7 kB xet | eb59de68 | |
| bench.py | 4.82 kB xet | bf55a912 | |
| complex_flash_attention.py | 30.2 kB xet | a37b96c2 | |
| configurator.py | 1.76 kB xet | 2117d39a | |
| freq_analysis.ipynb | 15.8 kB xet | 28c27a41 | |
| length_gen.py | 5.05 kB xet | 8f875d2d | |
| model.py | 25.4 kB xet | 2a017a95 | |
| plots.ipynb | 9.91 kB xet | 0546fedf | |
| position.py | 14.7 kB xet | 089376d8 | |
| requirements.txt | 137 Bytes xet | c6eb9f1a | |
| sample.py | 3.94 kB xet | f564c0df | |
| scaling_laws.ipynb | 269 kB xet | 6f552789 | |
| train.py | 24.6 kB xet | 7d19219d | |
| transformer_sizing.ipynb | 14.6 kB xet | b86ec850 |
Minimal PoPE code repository
This repository contains the minimal nanoGPT-based code used for the experiments in "Decoupling the What and Where With Polar Coordinate Positional Embeddings".
The training configs, dataset and preprocessing details are reported in the paper. This README is intended to make the code path easy to follow and to provide representative commands for reproducing the main results.
The code is adapted from Andrej Karpathy's nanoGPT. Thanks to the minimal and hackable nanoGPT repository by Andrej Karpathy, which this codebase reuses.
Setup
Create an environment with a recent PyTorch install appropriate for your hardware, then install the Python dependencies:
pip install -r requirements.txt
The optional custom complex FlashAttention path for PoPE uses Triton and is controlled
with --complex_flash=True.
Most scripts accept config-file and command-line overrides through configurator.py.
For example:
python train.py config/train_indirect_idx.py --pos_type=pope --wandb_log=True
Common overrides:
--pos_type=rope # RoPE baseline
--pos_type=pope # PoPE
--base_dir=/path/to/root # train.py reads datasets from $base_dir/data/<dataset>
--compile=False # useful for CPU/debug runs
--wandb_log=True # enable Weights & Biases logging
For multi-GPU training, use PyTorch DDP:
torchrun --standalone --nproc_per_node=8 train.py config/train_gpt124m.py --pos_type=pope
For multi-node training, use the usual torchrun --nnodes, --node_rank,
--master_addr, and --master_port arguments. If your cluster has no InfiniBand,
you may need to prepend NCCL_IB_DISABLE=1.
Main configs
The following configs correspond to the paper's main training/fine-tuning runs:
| Experiment | Config |
|---|---|
| Indirect indexing | config/train_indirect_idx.py |
| OpenWebText 124M | config/train_gpt124m.py |
| OpenWebText 253M | config/train_gpt253m.py |
| OpenWebText 774M | config/train_gpt774m.py |
| JSB Chorales | config/train_jsb.py |
| MAESTRO | config/train_maestro.py |
| Human Reference Genome | config/train_hrg205m.py |
| OpenWebText length fine-tuning | config/finetune_gpt124m.py, config/finetune_gpt253m.py |
Each training config can be run as RoPE or PoPE by overriding pos_type:
python train.py <config.py> --pos_type=rope
python train.py <config.py> --pos_type=pope
Some configs include machine-specific defaults such as base_dir. Override those on
the command line rather than editing the config when running on a new system.
Data preparation
Indirect indexing
Generate the synthetic dataset:
python data/indirect_idx/generate.py
This writes the dataset file to data/indirect_idx/ds_minl20_maxl40_shift_15.txt.
OpenWebText
Prepare GPT-2-tokenized OpenWebText:
python data/openwebtext/prepare.py
The training script expects train.bin and val.bin under
$base_dir/data/openwebtext. With the default --base_dir='', that is
data/openwebtext. The prep script writes there by default; set
POPE_DATA_DIR=/path/to/data if you want the generated files and Hugging Face cache
under a larger storage volume.
JSB Chorales
Place Jsb16thSeparated.json in data/jsb/. The loader expects the JSON format with
train, valid, and test splits. Download the dataset files from here
MAESTRO
Download MAESTRO v3.0.0 MIDI files and place/extract them under data/maestro/, or
set --base_dir so that the training path resolves to
$base_dir/data/maestro. The loader tokenizes MIDI files with REMI and creates local
chunk directories.
Human Reference Genome
The HRG loader uses the Hugging Face dataset
InstaDeepAI/human_reference_genome. It downloads through datasets; set your normal
Hugging Face cache variables or POPE_HF_CACHE_DIR if needed.
PG-19 length evaluation
length_gen.py uses the Hugging Face dataset emozilla/pg19-test for length
extrapolation evaluation. It loads a saved checkpoint and writes loss-vs-length output
under length_gen/.
Representative runs
Indirect indexing
python data/indirect_idx/generate.py
python train.py config/train_indirect_idx.py \
--pos_type=rope \
--wandb_run_name=indirect-rope
python train.py config/train_indirect_idx.py \
--pos_type=pope \
--wandb_run_name=indirect-pope
OpenWebText language modeling
Prepare the data, then launch RoPE and PoPE runs with the same config:
python data/openwebtext/prepare.py
torchrun --standalone --nproc_per_node=8 train.py config/train_gpt124m.py \
--pos_type=rope \
--wandb_run_name=owt-124m-rope
torchrun --standalone --nproc_per_node=8 train.py config/train_gpt124m.py \
--pos_type=pope \
--wandb_run_name=owt-124m-pope
Use config/train_gpt253m.py and config/train_gpt774m.py for the larger model
sizes.
JSB, MAESTRO, and HRG
After preparing the relevant dataset, run paired RoPE/PoPE jobs in the same pattern:
python train.py config/train_jsb.py --pos_type=rope --wandb_run_name=jsb-rope
python train.py config/train_jsb.py --pos_type=pope --wandb_run_name=jsb-pope
python train.py config/train_maestro.py --pos_type=rope --wandb_run_name=maestro-rope
python train.py config/train_maestro.py --pos_type=pope --wandb_run_name=maestro-pope
torchrun --standalone --nproc_per_node=8 train.py config/train_hrg205m.py \
--pos_type=rope \
--wandb_run_name=hrg-rope
torchrun --standalone --nproc_per_node=8 train.py config/train_hrg205m.py \
--pos_type=pope \
--wandb_run_name=hrg-pope
Length extrapolation
Fine-tuning configs are provided for OpenWebText context extension:
torchrun --standalone --nproc_per_node=4 train.py config/finetune_gpt124m.py \
--pos_type=rope \
--complex_flash=True
torchrun --standalone --nproc_per_node=4 train.py config/finetune_gpt124m.py \
--pos_type=pope \
--complex_flash=True
Evaluate saved checkpoints on PG-19 with length_gen.py:
python length_gen.py \
--base_dir=/path/to/root \
--ckpt_dir=final-owt-ckpts \
--ckpt_fname=gpt2-124M-pope-ckpt.pt \
--pos_type=pope \
--compile=False
The script evaluates sequence lengths from the training context length up to 10x that length.
Citation
If you use PoPE, the Indirect Indexing task, or build on the experimental results or what-where decoupling analysis, please cite:
@inproceedings{gopalakrishnan2026decoupling,
title={Decoupling The ''What'' and ''Where'' With Polar Coordinate Positional Embedding},
author={Gopalakrishnan, Anand and Csord{\'a}s, Robert and Schmidhuber, J{\"u}rgen and Mozer, Michael Curtis},
booktitle={Forty-third International Conference on Machine Learning},
year={2026},
url={https://openreview.net/forum?id=I3Z9za1EkO}
}
- Total size
- 988 MB
- Files
- 88
- Last updated
- Jul 16
- Pre-warmed CDN
- US EU US EU
