Repository: mcleish7/arithmetic Branch: main Commit: 86022a57d38c Files: 132 Total size: 479.5 KB Directory structure: gitextract_shohcgjg/ ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE ├── MANIFEST.in ├── README.md ├── abacus.py ├── arithmetic_eval_quicker.py ├── cramming/ │ ├── __init__.py │ ├── architectures/ │ │ ├── __init__.py │ │ ├── attention.py │ │ ├── components.py │ │ ├── construction.py │ │ ├── crammed_depthrecurrent.py │ │ ├── crammed_transformer.py │ │ ├── embeddings.py │ │ ├── huggingface_interface.py │ │ ├── losses.py │ │ └── sanity_check.py │ ├── backend/ │ │ ├── __init__.py │ │ ├── optimizers/ │ │ │ ├── __init__.py │ │ │ ├── optimizer_modifiers.py │ │ │ ├── progressive_batching.py │ │ │ └── schedulers.py │ │ ├── prepare_backend.py │ │ ├── torch_default.py │ │ └── utils.py │ ├── config/ │ │ ├── __init__.py │ │ ├── arch/ │ │ │ ├── __init__.py │ │ │ ├── albert.yaml │ │ │ ├── crammed-depthrecurrent.yaml │ │ │ ├── crammed-fakeRNN.yaml │ │ │ ├── crammed-janus.yaml │ │ │ ├── crammed-rnn.yaml │ │ │ ├── crammed-stack-janus.yaml │ │ │ ├── crammed-tiny.yaml │ │ │ ├── crammed-transformer.yaml │ │ │ ├── gpt2-base.yaml │ │ │ ├── hf-gpt2.yaml │ │ │ └── sanitycheck.yaml │ │ ├── cfg_eval.yaml │ │ ├── cfg_pretrain.yaml │ │ ├── data/ │ │ │ ├── __init__.py │ │ │ ├── arithmetic.yaml │ │ │ ├── c4-subset-processed.yaml │ │ │ ├── openweb.yaml │ │ │ ├── proofpile.yaml │ │ │ ├── sanity-check-1.yaml │ │ │ ├── sanity-check-2.yaml │ │ │ └── sources/ │ │ │ ├── ag_news.yaml │ │ │ ├── arithmetic.yaml │ │ │ ├── bookcorpus.yaml │ │ │ ├── c4.yaml │ │ │ ├── dash_books.yaml │ │ │ ├── fake.yaml │ │ │ ├── iwslt.yaml │ │ │ ├── local.yaml │ │ │ ├── no_code_stackexchange.yaml │ │ │ ├── openwebtext.yaml │ │ │ ├── oscar.yaml │ │ │ ├── proofpiledata.yaml │ │ │ ├── the_pile.yaml │ │ │ ├── the_pileCC.yaml │ │ │ ├── the_pile_dedup.yaml │ │ │ ├── the_pile_natural.yaml │ │ │ ├── the_pile_stream.yaml │ │ │ ├── uncorpus.yaml │ │ │ ├── uspto.yaml │ │ │ ├── wikibooks.yaml │ │ │ ├── wikinews.yaml │ │ │ ├── wikipedia.yaml │ │ │ ├── wikiquote.yaml │ │ │ ├── wikiversity.yaml │ │ │ └── wikivoyage.yaml │ │ ├── eval/ │ │ │ ├── __init__.py │ │ │ ├── pythia.yaml │ │ │ └── tasks/ │ │ │ ├── lambada_openai.yaml │ │ │ └── winogrande.yaml │ │ ├── hydra/ │ │ │ ├── __init__.py │ │ │ └── job_logging/ │ │ │ └── custom.yaml │ │ ├── impl/ │ │ │ ├── __init__.py │ │ │ ├── _default.yaml │ │ │ └── torch-default.yaml │ │ ├── train/ │ │ │ ├── __init__.py │ │ │ ├── common.yaml │ │ │ ├── cramming.yaml │ │ │ ├── janus-regime.yaml │ │ │ ├── optim/ │ │ │ │ ├── adafactor.yaml │ │ │ │ ├── adahessian.yaml │ │ │ │ ├── adam.yaml │ │ │ │ ├── adam8bit.yaml │ │ │ │ ├── adam_classic.yaml │ │ │ │ ├── adamscale.yaml │ │ │ │ ├── agd.yaml │ │ │ │ ├── lion.yaml │ │ │ │ ├── radam.yaml │ │ │ │ ├── sgd.yaml │ │ │ │ └── shampoo.yaml │ │ │ └── optim_mod/ │ │ │ ├── disabled.yaml │ │ │ ├── larc.yaml │ │ │ ├── lars.yaml │ │ │ ├── progressive.yaml │ │ │ └── sam.yaml │ │ └── wandb/ │ │ ├── default.yaml │ │ └── none.yaml │ ├── data/ │ │ ├── __init__.py │ │ ├── arithmetic_tokenizers.py │ │ ├── curriculum_sorting.py │ │ ├── deduplicate.py │ │ ├── pretraining_preparation.py │ │ ├── tokenizer_preparation.py │ │ └── utils.py │ └── utils.py ├── create_data_split.py ├── create_pos_or_variants.py ├── dataset_analysis.py ├── gen_eval_script.py ├── load_local_model.py ├── pretrain.py ├── pretty_plotter.py ├── pretty_plotter_big.py ├── pretty_plotter_sort.py ├── pyproject.toml ├── setup.cfg ├── shells/ │ ├── addition_ff.sh │ ├── addition_lt.sh │ ├── bitwise_or.sh │ ├── evaluation.sh │ ├── generate_and_tokenize_data.sh │ ├── multiplication.sh │ └── sorting.sh ├── sort_eval.py └── upload_processed_dataset.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ outputs tables/*/*.csv tables/*/*.csv# tables/*.csv tables/*.csv# tables/*.ods *.png *.pdf # torchdynamo debug isolate repro.py checkpoints wandb-metadata.json torch_compile_debug/ dedup .vs/ *.pdf images *.temp.sh # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ *.csv *.txt *.pth cramming-data/ sanity.sh log/ del.sh del.py sort_plots/ ================================================ FILE: .pre-commit-config.yaml ================================================ # precommit hooks from https://github.com/ashleve/lightning-hydra-template repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.4.0 hooks: # list of supported hooks: https://pre-commit.com/hooks.html - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - id: debug-statements - id: detect-private-key # python code formatting - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black args: [--line-length, "140", "--fast"] # ;> # yaml formatting - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.3.0 hooks: - id: prettier types: [yaml] # python code analysis - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 hooks: - id: flake8 ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2024 Sean McLeish, Jonas Geiping Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: MANIFEST.in ================================================ # added by check-manifest include *.py include *.yaml recursive-include cramming *.md recursive-include cramming *.yaml global-exclude *.pyc global-exclude __pycache__ ================================================ FILE: README.md ================================================ # Transformers Can Do Arithmetic with the Right Embeddings! [Link to arXiv paper](https://arxiv.org/abs/2405.17399) A joint project by: Sean McLeish, Arpit Bansal, Alex Stein, Neel Jain, John Kirchenbauer, Brian R. Bartoldson, Bhavya Kailkhura, Abhinav Bhatele, Jonas Geiping, Avi Schwarzschild and Tom Goldstein This repository contains code to replicate our research. It is a fork of the language model training framework [cramming](https://github.com/JonasGeiping/cramming) edited to for a next token prediction objective. We provide a standalone implementation of Abacus Embeddings in [abacus.py](abacus.py). ## Citing Our Work To cite our work, please use this bibtex. ``` @article{mcleish2024transformers, title={Transformers Can Do Arithmetic with the Right Embeddings}, author={Sean McLeish and Arpit Bansal and Alex Stein and Neel Jain and John Kirchenbauer and Brian R. Bartoldson and Bhavya Kailkhura and Abhinav Bhatele and Jonas Geiping and Avi Schwarzschild and Tom Goldstein}, journal={arXiv preprint arXiv:2405.17399}, year={2024} } ``` # Getting Started We developed in Python 3.10.4, to install run: ``` git clone git@github.com:mcleish7/arithmetic.git cd arithmetic pip install . ``` On some machines you will need to run: 1. `pip install multiprocess -U` 2. `pip install dill -U` 3. `pip install apache-beam -U` # Arithmetic ## Datasets We release our datasets on [Google Drive](https://drive.google.com/drive/folders/1DqjCrUM1cNV7069Zl25_qBw2Px2xAw9j?usp=sharing) both in zipped format. We recommend you work with the zipped version until it is correctly placed in your file system. Alternatively, you can make your own datasets using [create_data_split.py](create_data_split.py) using the commands from [shells/generate_and_tokenize_data.sh](shells/generate_and_tokenize_data.sh). ## File Structure We recommend creating another directory `cramming-data` inside of arithmetic. This is where the models, logs and data will be stored. You can either export you cramming base directory path to your `.bashrc` or you can replace `$cramming_base_dir` manually in the provided shells. ``` cd arithmetic mkdir cramming-data echo 'export cramming_base_dir=MY_BASE_DIR' >> ~/.bashrc source ~/.bashrc ``` For example, this may look like: `echo 'export cramming_base_dir=~/arithmetic/cramming-data' >> ~/.bashrc` For example our file system looks like: ``` cramming-generative └── cramming-data ├── addition-train-one │ ├── pretrain//