{"id":13429688,"url":"https://github.com/ezelikman/STaR","last_synced_at":"2025-03-16T04:30:19.756Z","repository":{"id":87497934,"uuid":"545147893","full_name":"ezelikman/STaR","owner":"ezelikman","description":"Code for STaR: Bootstrapping Reasoning With Reasoning (NeurIPS 2022)","archived":false,"fork":false,"pushed_at":"2023-02-21T18:19:34.000Z","size":2793,"stargazers_count":152,"open_issues_count":1,"forks_count":19,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-27T07:32:48.907Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ezelikman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.bib","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-03T21:39:30.000Z","updated_at":"2024-10-25T13:37:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"aa3157a9-6ec2-4158-b1da-c4f519a1fd0c","html_url":"https://github.com/ezelikman/STaR","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezelikman%2FSTaR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezelikman%2FSTaR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezelikman%2FSTaR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ezelikman%2FSTaR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ezelikman","download_url":"https://codeload.github.com/ezelikman/STaR/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826788,"owners_count":20354220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:00:43.742Z","updated_at":"2025-03-16T04:30:19.000Z","avatar_url":"https://github.com/ezelikman.png","language":"Python","funding_links":[],"categories":["2 Foundation Models"],"sub_categories":["2.4 Reasoning Applications"],"readme":"# Table of contents\n1. [STaR](#star)\n2. [Mesh Transformer JAX](#mesh-transformer-jax)\n    1. [Updates](#updates)\n3. [Pretrained Models](#pretrained-models)\n   1. [GPT-J-6B](#gpt-j-6b)\n      1. [Links](#links)\n      2. [Acknowledgments](#acknowledgments)\n      3. [License](#license)\n      4. [Model Details](#model-details)\n      5. [Zero-Shot Evaluations](#zero-shot-evaluations)\n4. [Architecture and Usage](#architecture-and-usage)\n   1. [Fine-tuning](#fine-tuning)\n   2. [JAX Dependency](#jax-dependency)\n5. [TODO](#todo)\n\n# STaR\nCode for [STaR: Bootstrapping Reasoning With Reasoning (NeurIPS 2022)](https://openreview.net/forum?id=_3ELRdg2sgI). This library is built on top of [mesh-transformer-jax](https://github.com/kingoflolz/mesh-transformer-jax) and incorporates masked training from [this repo](https://github.com/albertqjiang/mesh-transformer-jax). In order to run it, launch `iteration_train.py` with any desired arguments. The README is left mostly unchanged, as `iteration_train` largely wraps around `device_train.py`, `device_inference.py`, and `create_finetune_tfrecords.py`.\n\n# Mesh Transformer JAX\n\nA haiku library using the `xmap`/`pjit` operators in JAX for model parallelism of transformers.\n\nThe parallelism scheme is similar to the [original Megatron-LM](https://arxiv.org/abs/1909.08053), which is efficient\non TPUs due to the high speed 2d mesh network. There is also an experimental model version which implements [ZeRo style\nsharding](https://arxiv.org/abs/1910.02054).\n\nThis library is designed for scalability up to approximately 40B parameters on TPUv3s, beyond which different\nparallelism strategies should be used. See other implementations such as\n[GPT-NeoX](https://github.com/EleutherAI/gpt-neox) or [DeepSpeed](https://github.com/microsoft/DeepSpeed) for that.\n\nOne future direction for research is integrating this codebase with\n[swarm-jax](https://github.com/kingoflolz/swarm-jax), to achieve further scalability with pipeline parallelism.\n\n## Updates\n\n**12-07-21**: Added [guide to fine tuning](howto_finetune.md)\n\n# Pretrained Models\n\n## GPT-J-6B\n\nA 6 billion parameter, autoregressive text generation model trained on [The Pile](https://pile.eleuther.ai/).\n\n### Links\n\n[Slim weights (bf16 weights only, for inference, 9GB)](https://the-eye.eu/public/AI/GPT-J-6B/step_383500_slim.tar.zstd)\n\n[Full weights (including optimizer params, 61GB)](https://the-eye.eu/public/AI/GPT-J-6B/step_383500.tar.zstd)\n\n[Colab demo](http://colab.research.google.com/github/kingoflolz/mesh-transformer-jax/blob/master/colab_demo.ipynb)\n\n[Web demo](https://6b.eleuther.ai/)\n\n[Aran's blog post](https://arankomatsuzaki.wordpress.com/2021/06/04/gpt-j/)\n\n### Acknowledgments\n\nThis project would not have been possible without compute generously provided by the\n[TPU Research Cloud](https://sites.research.google/trc/) with assistance from [EleutherAI](https://eleuther.ai/).\n\nThanks to the Cloud TPU team at Google for providing early access to the Cloud TPU VM alpha\n([now publicly available!](https://cloud.google.com/blog/products/compute/introducing-cloud-tpu-vms))\n\nThanks to everyone who have helped out one way or another (listed alphabetically):\n- [Aran Komatsuzaki](https://twitter.com/arankomatsuzaki) for advice with experiment design and writing the blog posts.\n- [James Bradbury](https://twitter.com/jekbradbury) for valuable assistance with debugging JAX issues.\n- [Janko Prester](https://github.com/jprester) for creating the web demo frontend.\n- [Laurence Golding](https://github.com/researcher2) for adding some features to the web demo.\n- [Leo Gao](https://twitter.com/nabla_theta) for running zero shot evaluations for the baseline models for the table.\n\n### License\nThe weights of GPT-J-6B are licensed under version 2.0 of the Apache License.\n\n### Model Details\n\n| Hyperparameter    | Value  |\n|-------------------|--------|\n| n_parameters      | 6,053,381,344 |\n| n_layers          | 28*    |\n| d_model           | 4,096  |\n| d_ff              | 16,384 |\n| n_heads           | 16     |\n| d_head            | 256    |\n| n_ctx             | 2,048  |\n| n_vocab           | 50,257 (same tokenizer as GPT-2/3)  |\n| position encoding | [Rotary position encodings (RoPE)](https://arxiv.org/abs/2104.09864) |\n| RoPE dimensions   | [64](https://github.com/kingoflolz/mesh-transformer-jax/blob/f2aa66e0925de6593dcbb70e72399b97b4130482/mesh_transformer/layers.py#L223) |\n\n`*` each layer consists of one feedforward block and one self attention block\n\nThe model consists of 28 layers with a model dimension of 4096, and a feedforward dimension of 16384. The model\ndimension is split into 16 heads, each with a dimension of 256. Rotary position encodings (RoPE) was applied to 64\ndimensions of each head. The model is trained with a tokenization vocabulary of 50257, using the same set of BPEs as\nGPT-2/GPT-3.\n\n### Zero-Shot Evaluations\n\nModels roughly sorted by performance, or by FLOPs if not available.\n\n|  Model          | Weights | Training FLOPs | LAMBADA PPL ↓ | LAMBADA Acc ↑ | Winogrande ↑ | Hellaswag ↑ | PIQA ↑ | Dataset Size (GB) |\n|-----------------|---------|----------------|---            |---            |---           |---          |---     |-------------------|\n| Chance          | ✔       | 0              | ~a lot        | ~0%           | 50%          | 25%         | 25%    | 0                 |\n| GPT-3-Ada‡      | ✘       | -----          | 9.95          | 51.6%         | 52.9%        | 43.4%       | 70.5%  | -----             |\n| GPT-2-1.5B      | ✔       | -----          | 10.63         | 51.21%        | 59.4%        | 50.9%       | 70.8%  | 40                |\n| GPTNeo-1.3B‡    | ✔       | 3.0e21         | 7.50          | 57.2%         | 55.0%        | 48.9%       | 71.1%  | 825               |\n| Megatron-2.5B*  | ✘       | 2.4e21         | -----         | 61.7%         | -----        | -----       | -----  | 174               |\n| GPTNeo-2.7B‡    | ✔       | 6.8e21         | 5.63          | 62.2%         | 56.5%        | 55.8%       | 73.0%  | 825               |\n| GPT-3-1.3B*‡    | ✘       | 2.4e21         | 5.44          | 63.6%         | 58.7%        | 54.7%       | 75.1%  | ~800              |\n| GPT-3-Babbage‡  | ✘       | -----          | 5.58          | 62.4%         | 59.0%        | 54.5%       | 75.5%  | -----             |\n| Megatron-8.3B*  | ✘       | 7.8e21         | -----         | 66.5%         | -----        | -----       | -----  | 174               |\n| GPT-3-2.7B*‡    | ✘       | 4.8e21         | 4.60          | 67.1%         | 62.3%        | 62.8%       | 75.6%  | ~800              |\n| Megatron-11B†   | ✔       | 1.0e22         | -----         | -----         | -----        | -----       | -----  | 161               |\n| **GPT-J-6B**‡   | ✔       | 1.5e22         | 3.99          | 69.7%         | 65.3%        | 66.1%       | 76.5%  | 825               |\n| GPT-3-6.7B*‡    | ✘       | 1.2e22         | 4.00          | 70.3%         | 64.5%        | 67.4%       | 78.0%  | ~800              |\n| GPT-3-Curie‡    | ✘       | -----          | 4.00          | 69.3%         | 65.6%        | 68.5%       | 77.9%  | -----             |\n| GPT-3-13B*‡     | ✘       | 2.3e22         | 3.56          | 72.5%         | 67.9%        | 70.9%       | 78.5%  | ~800              |\n| GPT-3-175B*‡    | ✘       | 3.1e23         | 3.00          | 76.2%         | 70.2%        | 78.9%       | 81.0%  | ~800              |\n| GPT-3-Davinci‡  | ✘       | -----          | 3.0           | 75%           | 72%          | 78%         | 80%    | -----             |\n| Gopher 230B*\t  | ✘\t    | 6.31E+23\t     | -----    \t | 74.50%        | 70.10%   \t| 79.20%      | 81.80% | 1344              |\n| MT-NLG 530B*‡   | ✘       | -----          | -----         | 76.6%         | 73.0%        | 80.2%       | 82.0%  | -----             |\n\n`*` represents evaluation numbers reported by their respective authors, all other numbers are provided by\nrunning the [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness/) either with the released\nweights or with API access. Due to subtle implementation differences as well as different zero shot task framing, these\nmight not be directly comparable. See [this blog post](https://www.eleuther.ai/research-log/gpt3-model-sizes/) for more\ndetails.\n\n`†` The Megatron-11B model provides no comparable metrics, and several implementations using the released weights do not\nreproduce the generation quality and evaluations. (see [1](https://github.com/huggingface/transformers/pull/10301)\n[2](https://github.com/pytorch/fairseq/issues/2358) [3](https://github.com/pytorch/fairseq/issues/2719))\nThus, evaluation was not attempted.\n\n`‡` These models have been trained with data which contains possible test set contamination. The OpenAI GPT-3 models\nfailed to deduplicate training data for certain test sets, while the GPT-Neo models as well as this one is\ntrained on The Pile, which has not been deduplicated against any test sets.\n\n# Architecture and Usage\n\nMost scripts in this repository are designed to be run on TPUs, which under the\n[TPU-VM architecture](https://cloud.google.com/tpu/docs/system-architecture-tpu-vm) are virtual machines\nwhich can run arbitrary code. Most scripts are designed to spin up a TPU, SSH into it to set up the dependencies\nand copy code over from the local directory, and then start a [Ray](https://github.com/ray-project/ray.git) worker\nwhich can accept RPC calls.\n\nThe TPUVMs handles running model training steps and evaluation, checkpoint save and loading, while the driver python\nprogram handles data loading and general orchestration (such as when to save checkpoints etc).\n\nThis means that most scripts (`train.py`, `eval_harness.py` etc) expect to be running on a GCE virtual machine in the\nsame region as the TPUs, to minimize RPC latency and data transfer cost. Other scripts\n(usually ones which don't take a `--tpu` argument, such as `device_sample.py`, `device_serve.py` or `device_train.py`)\nexpect to be run directly on a TPUVM. The device_* scripts **only work on a v3-8** and not on larger pods.\n\nFurthermore, there is an example (`resharding_example.py`) of how to convert the provided checkpoints (which have 8\nshards in the case of GPT-J-6B) down to a smaller number, such as for when running on GPU(s).\n\n### Fine-tuning\n\nTo fine-tune the model, run `device_train.py` on a TPU VM.  Using a TPU v3-8, you can fine-tune at a rate of ~5000\ntokens/second, which should be sufficient for small-to-medium-size datasets.\n\nPlease read the [step by step guide](howto_finetune.md) for thorough fine-tuning instructions.\n\n### JAX Dependency\n\nNote this library has some specific requirements for JAX version. Specifically, to use the v1 models (including\n GPT-J 6B), `jax==0.2.12` is required. This in turn depends on `jaxlib==0.1.68`. **If this is not done, you will get\ncryptic xmap errors**\n\nHowever, to use the v2 model code (no publicly released weights), the newest JAX version can be used.\n# Citation\n\nTo cite this repository:\n```\n@inproceedings{\n  zelikman2022star,\n  title={{ST}aR: Bootstrapping Reasoning With Reasoning},\n  author={Eric Zelikman and Yuhuai Wu and Jesse Mu and Noah Goodman},\n  booktitle={Advances in Neural Information Processing Systems},\n  editor={Alice H. Oh and Alekh Agarwal and Danielle Belgrave and Kyunghyun Cho},\n  year={2022},\n  url={https://openreview.net/forum?id=_3ELRdg2sgI}\n}\n```\n\nTo cite the base repository:\n```\n@misc{mesh-transformer-jax,\n  author = {Wang, Ben},\n  title = {{Mesh-Transformer-JAX: Model-Parallel Implementation of Transformer Language Model with JAX}},\n  howpublished = {\\url{https://github.com/kingoflolz/mesh-transformer-jax}},\n  year = 2021,\n  month = May\n}\n```\n\nTo cite the weights of GPT-J-6B:\n```\n@misc{gpt-j,\n  author = {Wang, Ben and Komatsuzaki, Aran},\n  title = {{GPT-J-6B: A 6 Billion Parameter Autoregressive Language Model}},\n  howpublished = {\\url{https://github.com/kingoflolz/mesh-transformer-jax}},\n  year = 2021,\n  month = May\n}\n```\n\nIf you use this repository or any of the pretrained weights to do something cool, we would love to hear about it.\nFeel free to open a github issue or reach out over email (in profile).\n\n# TODO\n- [x] disentangle heads and shards\n- [x] test/benchmark on TPU\n- [x] implement gradient checkpointing\n- [x] fix initialization\n- [x] mixed precision\n- [x] deal with preemptible TPUs\n- [x] test and validate generation\n- [x] shard activations instead of replicating for memory efficiency (in v2)\n- [x] support ZeRO style sharding (in v2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezelikman%2FSTaR","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fezelikman%2FSTaR","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fezelikman%2FSTaR/lists"}