• Stars
    star
    4,535
  • Rank 9,396 (Top 0.2 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 2 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Modeling, training, eval, and inference code for OLMo
OLMo Logo

OLMo: Open Language Model

GitHub License GitHub release Paper URL

OLMo is a repository for training and using AI2's state-of-the-art open language models. It is built by scientists, for scientists.

Installation

First install PyTorch according to the instructions specific to your operating system.

To install from source (recommended for training/fine-tuning) run:

git clone https://github.com/allenai/OLMo.git
cd OLMo
pip install -e .[all]

Otherwise you can install the model code by itself directly from PyPI with:

pip install ai2-olmo

Models

Overview

The core models in the OLMo family released so far are (all trained on the Dolma dataset):

Model Training Tokens Context Length Training Config W&B Logs Data Order File(s) ☨
OLMo 1B 3 Trillion 2048 configs/official/OLMo-1B.yaml wandb.ai/…/OLMo-1B epoch 1
OLMo 7B 2.5 Trillion 2048 configs/official/OLMo-7B.yaml wandb.ai/…/OLMo-7B epoch 1, epoch 2
OLMo 7B Twin 2T 2 Trillion 2048 configs/official/OLMo-7B.yaml wandb.ai/…/OLMo-7B-Twin-2T epoch 1

See Inspecting training data below for usage.

Checkpoints

URLs to checkpoints at intermediate steps of the models' trainings can be found in the csv files under checkpoints/official/. These 'directory' URLs cannot currently be directly accessed, but files within the directory are publicly accessible. These URLs can also be provided to the training script to resume training from the checkpoint (see Training). Each checkpoint directory consists of:

  • config.yaml: the config at that training step.
  • model.pt, optim.pt, train.pt: model, optimizer and training state at that training step.

Inference

You can utilize our Hugging Face integration to run inference on the olmo checkpoints:

from hf_olmo import * # registers the Auto* classes

from transformers import AutoModelForCausalLM, AutoTokenizer

olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B")
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-7B")

message = ["Language modeling is "]
inputs = tokenizer(message, return_tensors='pt', return_token_type_ids=False)
response = olmo.generate(**inputs, max_new_tokens=100, do_sample=True, top_k=50, top_p=0.95)
print(tokenizer.batch_decode(response, skip_special_tokens=True)[0])

Alternatively, with the Hugging Face pipeline abstraction:

from transformers import pipeline
olmo_pipe = pipeline("text-generation", model="allenai/OLMo-7B")
print(olmo_pipe("Language modeling is"))

Inference on finetuned checkpoints

If you finetune the model using the code above, you can use the conversion script to convert a native OLMo checkpoint to a Hugging Face-compatible checkpoint

python hf_olmo/convert_olmo_to_hf.py --checkpoint-dir /path/to/checkpoint

Quantization

olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-7B", torch_dtype=torch.float16, load_in_8bit=True)  # requires bitsandbytes

The quantized model is more sensitive to typing / cuda, so it is recommended to pass the inputs as inputs.input_ids.to('cuda') to avoid potential issues.

Reproducibility

Training

The configs used to train the official OLMo models are provided in the configs/official/ directory.

Note that while the training and validation data is public and free to download, the paths to the data within those configs are pointed at a CloudFlare R2 bucket, which requires an API key for programmatic access. So in order to use any of these configs to reproduce a training run you'll first have to download the corresponding data to a location of your choosing and then update the paths in the config accordingly.

You can derive the public HTTP URL from an R2 URL by replacing r2://olmo-data with https://olmo-data.org. For example, if the R2 data URL is:

r2://olmo-data/preprocessed/olmo-mix/v1_5/gpt-neox-20b-pii-special/part-000-00000.npy

then the corresponding public URL is:

https://olmo-data.org/preprocessed/olmo-mix/v1_5/gpt-neox-20b-pii-special/part-000-00000.npy

Once you've updated the data paths in the config you can launch a training run via torchrun. For example, to launch the 1B model training on a single 8x GPU node, you would run:

torchrun --nproc_per_node=8 scripts/train.py configs/official/OLMo-1B.yaml

You can use the same method to launch multi-node jobs as well. See the documentation for torchrun to understand the additional arguments you'll need to configure the rendezvous backend / endpoint.

To resume training from a checkpoint, you can pass its path (local or URL) to scripts/train.py with the --load_path arguments. For example, to resume training from step 1000 of the OLMo 1B run:

torchrun --nproc_per_node=8 scripts/train.py configs/official/OLMo-1B.yaml --load_path https://olmo-checkpoints.org/ai2-llm/olmo-small/w1r5xfzt/step1000-unsharded

Inspecting training data

You may be interesting in inspecting the exact tokens that composed a particular batch during the training of one of the OLMo models. We provide tools to do this, but first you'll need to download the data as above (unless you have an R2 API key) and update the corresponding config accordingly.

Then take note of the URL of the data order file you want, which can be found in the Models Overview table. For example, the data order file for the first epoch of the OLMo-7B model is https://olmo-checkpoints.org/ai2-llm/olmo-medium/wvc30anm/train_data/global_indices.npy.

Once you have that you can use this snippet to inspect the data within a particular batch:

import numpy as np
from cached_path import cached_path

from olmo.config import TrainConfig
from olmo.data import build_memmap_dataset

# Update these paths to what you want:
data_order_file_path = cached_path("https://olmo-checkpoints.org/ai2-llm/olmo-medium/wvc30anm/train_data/global_indices.npy")
train_config_path = "configs/official/OLMo-7B.yaml"


cfg = TrainConfig.load(train_config_path)
dataset = build_memmap_dataset(cfg, cfg.data)
batch_size = cfg.global_train_batch_size
global_indices = np.memmap(data_order_file_path, mode="r+", dtype=np.uint32)


def get_batch_instances(batch_idx: int) -> list[list[int]]:
    batch_start = batch_idx * batch_size
    batch_end = (batch_idx + 1) * batch_size
    batch_indices = global_indices[batch_start:batch_end]
    batch_instances = []
    for index in batch_indices:
        token_ids = dataset[index]["input_ids"].tolist()
        batch_instances.append(token_ids)
    return batch_instances


# Get all 2048 x 2048 token IDs in the first batch.
get_batch_instances(0)

Fine-tuning

To fine-tune an OLMo model using our trainer you'll first need to prepare your dataset by tokenizing it and saving the tokens IDs to a flat numpy memory-mapped array. See scripts/prepare_tulu_data.py for an example with the Tulu V2 dataset, which can be easily modified for other datasets.

Next, prepare your training config. There are many examples in the configs/ directory that you can use as a starting point. The most important thing is to make sure the model parameters (the model field in the config) match up with the checkpoint you're starting from. To be safe you can always start from the config that comes with the model checkpoint. At a minimum you'll need to make the following changes to the config or provide the corresponding overrides from the command line:

  • Update load_path to point to the checkpoint you want to start from.
  • Set reset_trainer_state to true.
  • Update data.paths to point to the token_ids.npy file you generated.
  • Optionally update data.label_mask_paths to point to the label_mask.npy file you generated, unless you don't need special masking for the loss.
  • Update evaluators to add/remove in-loop evaluations.

Once you're satisfied with your training config, you can launch the training job via torchrun. For example:

torchrun --nproc_per_node=8 scripts/train.py {path_to_train_config} \
    --data.paths=[{path_to_data}/input_ids.npy] \
    --data.label_mask_paths=[{path_to_data}/label_mask.npy] \
    --load_path={path_to_checkpoint} \
    --reset_trainer_state

Note: passing CLI overrides like --reset_trainer_state is only necessary if you didn't update those fields in your config.

Evaluation

Additional tools for evaluating OLMo models are available at the OLMo Eval repo.

Citing

@article{OLMo,
  title={OLMo: Accelerating the Science of Language Models},
  author={Dirk Groeneveld and Iz Beltagy and Pete Walsh and Akshita Bhagia and Rodney Kinney and Oyvind Tafjord and A. Jha and Hamish Ivison and Ian Magnusson and Yizhong Wang and Shane Arora and David Atkinson and Russell Authur and Khyathi Raghavi Chandu and Arman Cohan and Jennifer Dumas and Yanai Elazar and Yuling Gu and Jack Hessel and Tushar Khot and William Merrill and Jacob Daniel Morrison and Niklas Muennighoff and Aakanksha Naik and Crystal Nam and Matthew E. Peters and Valentina Pyatkin and Abhilasha Ravichander and Dustin Schwenk and Saurabh Shah and Will Smith and Emma Strubell and Nishant Subramani and Mitchell Wortsman and Pradeep Dasigi and Nathan Lambert and Kyle Richardson and Luke Zettlemoyer and Jesse Dodge and Kyle Lo and Luca Soldaini and Noah A. Smith and Hanna Hajishirzi},
  year={2024},
  url={https://api.semanticscholar.org/CorpusID:267365485},
  journal={arXiv preprint},
}

More Repositories

1

allennlp

An open-source NLP research library, built on PyTorch.
Python
11,751
star
2

RL4LMs

A modular RL library to fine-tune language models to human preferences
Python
2,101
star
3

longformer

Longformer: The Long-Document Transformer
Python
2,022
star
4

bilm-tf

Tensorflow implementation of contextualized word representations from bi-directional language models
Python
1,621
star
5

scispacy

A full spaCy pipeline and models for scientific/biomedical documents.
Python
1,618
star
6

bi-att-flow

Bi-directional Attention Flow (BiDAF) network is a multi-stage hierarchical process that represents context at different levels of granularity and uses a bi-directional attention flow mechanism to achieve a query-aware context representation without early summarization.
Python
1,533
star
7

scibert

A BERT model for scientific text.
Python
1,495
star
8

open-instruct

Python
1,185
star
9

ai2thor

An open-source platform for Visual AI.
C#
1,160
star
10

dolma

Data and tools for generating and inspecting OLMo pre-training data.
Python
961
star
11

XNOR-Net

ImageNet classification using binary Convolutional Neural Networks
Lua
839
star
12

s2orc

S2ORC: The Semantic Scholar Open Research Corpus: https://www.aclweb.org/anthology/2020.acl-main.447/
Python
817
star
13

mmc4

MultimodalC4 is a multimodal extension of c4 that interleaves millions of images with text.
Python
793
star
14

scitldr

Python
734
star
15

objaverse-xl

🪐 Objaverse-XL is a Universe of 10M+ 3D Objects. Contains API Scripts for Downloading and Processing!
Python
701
star
16

papermage

library supporting NLP and CV research on scientific papers
Python
692
star
17

natural-instructions

Expanding natural instructions
Python
690
star
18

visprog

Official code for VisProg (CVPR 2023 Best Paper!)
Python
686
star
19

science-parse

Science Parse parses scientific papers (in PDF form) and returns them in structured form.
Java
611
star
20

pdffigures2

Given a scholarly PDF, extract figures, tables, captions, and section titles.
Scala
593
star
21

writing-code-for-nlp-research-emnlp2018

A companion repository for the "Writing code for NLP Research" Tutorial at EMNLP 2018
Python
558
star
22

tango

Organize your experiments into discrete steps that can be cached and reused throughout the lifetime of your research project.
Python
528
star
23

allennlp-models

Officially supported AllenNLP models
Python
521
star
24

specter

SPECTER: Document-level Representation Learning using Citation-informed Transformers
Python
506
star
25

dont-stop-pretraining

Code associated with the Don't Stop Pretraining ACL 2020 paper
Python
488
star
26

unified-io-2

Python
471
star
27

macaw

Multi-angle c(q)uestion answering
Python
451
star
28

lumos

Code and data for "Lumos: Learning Agents with Unified Data, Modular Design, and Open-Source LLMs"
Python
433
star
29

document-qa

Python
420
star
30

scholarphi

An interactive PDF reader.
Python
418
star
31

deep_qa

A deep NLP library, based on Keras / tf, focused on question answering (but useful for other NLP too)
Python
404
star
32

acl2018-semantic-parsing-tutorial

Materials from the ACL 2018 tutorial on neural semantic parsing
402
star
33

unifiedqa

UnifiedQA: Crossing Format Boundaries With a Single QA System
Python
384
star
34

pawls

Software that makes labeling PDFs easy.
Python
380
star
35

OLMoE

OLMoE: Open Mixture-of-Experts Language Models
Jupyter Notebook
374
star
36

kb

KnowBert -- Knowledge Enhanced Contextual Word Representations
Python
359
star
37

PeerRead

Data and code for Kang et al., NAACL 2018's paper titled "A Dataset of Peer Reviews (PeerRead): Collection, Insights and NLP Applications"
Python
354
star
38

reward-bench

RewardBench: the first evaluation tool for reward models.
Python
346
star
39

naacl2021-longdoc-tutorial

Python
342
star
40

openie-standalone

Quality information extraction at web scale. Edit
Scala
327
star
41

Holodeck

CVPR 2024: Language Guided Generation of 3D Embodied AI Environments.
Python
319
star
42

python-package-template

A template repo for Python packages
Python
318
star
43

allenact

An open source framework for research in Embodied-AI from AI2.
Python
316
star
44

ir_datasets

Provides a common interface to many IR ranking datasets.
Python
314
star
45

s2orc-doc2json

Parsers for scientific papers (PDF2JSON, TEX2JSON, JATS2JSON)
Python
302
star
46

acl2022-zerofewshot-tutorial

291
star
47

OLMo-Eval

Evaluation suite for LLMs
Python
280
star
48

procthor

🏘️ Scaling Embodied AI by Procedurally Generating Interactive 3D Houses
Python
257
star
49

fm-cheatsheet

Website for hosting the Open Foundation Models Cheat Sheet.
JavaScript
255
star
50

FineGrainedRLHF

Python
243
star
51

beaker-cli

A collaborative platform for rapid and reproducible research.
Go
230
star
52

comet-atomic-2020

Python
228
star
53

spv2

Science-parse version 2
Python
225
star
54

scifact

Data and models for the SciFact verification task.
Python
217
star
55

objaverse-rendering

📷 Scripts for rendering Objaverse
Python
206
star
56

ScienceWorld

ScienceWorld is a text-based virtual environment centered around accomplishing tasks from the standardized elementary science curriculum.
Scala
197
star
57

unified-io-inference

Jupyter Notebook
196
star
58

allennlp-demo

Code for the AllenNLP demo.
TypeScript
191
star
59

citeomatic

A citation recommendation system that allows users to find relevant citations for their paper drafts. The tool is backed by Semantic Scholar's OpenCorpus dataset.
Jupyter Notebook
189
star
60

cartography

Dataset Cartography: Mapping and Diagnosing Datasets with Training Dynamics
Jupyter Notebook
188
star
61

savn

Learning to Learn how to Learn: Self-Adaptive Visual Navigation using Meta-Learning (https://arxiv.org/abs/1812.00971)
Python
175
star
62

vampire

Variational Methods for Pretraining in Resource-limited Environments
Python
173
star
63

vila

Incorporating VIsual LAyout Structures for Scientific Text Classification
Python
172
star
64

s2-folks

Public space for the user community of Semantic Scholar APIs to share scripts, report issues, and make suggestions.
171
star
65

hidden-networks

Python
164
star
66

cord19

Get started with CORD-19
161
star
67

mmda

multimodal document analysis
Jupyter Notebook
158
star
68

PRIMER

The official code for PRIMERA: Pyramid-based Masked Sentence Pre-training for Multi-document Summarization
Python
150
star
69

catwalk

This project studies the performance and robustness of language models and task-adaptation methods.
Python
141
star
70

dnw

Discovering Neural Wirings (https://arxiv.org/abs/1906.00586)
Python
139
star
71

deepfigures-open

Companion code to the paper "Extracting Scientific Figures with Distantly Supervised Neural Networks" 🤖
Python
133
star
72

tpu_pretrain

LM Pretraining with PyTorch/TPU
Python
132
star
73

allentune

Hyperparameter Search for AllenNLP
Python
128
star
74

SciREX

Data/Code Repository for https://api.semanticscholar.org/CorpusID:218470122
Python
128
star
75

scidocs

Dataset accompanying the SPECTER model
Python
127
star
76

lm-explorer

interactive explorer for language models
Python
127
star
77

pdffigures

Command line tool to extract figures, tables, and captions from scholarly documents in PDF form.
C++
125
star
78

OpenBookQA

Code for experiments on OpenBookQA from the EMNLP 2018 paper "Can a Suit of Armor Conduct Electricity? A New Dataset for Open Book Question Answering"
Python
121
star
79

peS2o

Pretraining Efficiently on S2ORC!
120
star
80

gooaq

Question-answers, collected from Google
Python
116
star
81

allennlp-as-a-library-example

A simple example for how to build your own model using AllenNLP as a dependency.
Python
113
star
82

embodied-clip

Official codebase for EmbCLIP
Python
111
star
83

multimodalqa

Python
109
star
84

alexafsm

With alexafsm, developers can model dialog agents with first-class concepts such as states, attributes, transition, and actions. alexafsm also provides visualization and other tools to help understand, test, debug, and maintain complex FSM conversations.
Python
108
star
85

allennlp-semparse

A framework for building semantic parsers (including neural module networks) with AllenNLP, built by the authors of AllenNLP
Python
107
star
86

scicite

Repository for NAACL 2019 paper on Citation Intent prediction
Python
106
star
87

ai2thor-rearrangement

🔀 Visual Room Rearrangement
Python
104
star
88

commonsense-kg-completion

Python
102
star
89

medicat

Dataset of medical images, captions, subfigure-subcaption annotations, and inline textual references
Python
102
star
90

real-toxicity-prompts

Jupyter Notebook
101
star
91

s2search

The Semantic Scholar Search Reranker
Python
99
star
92

aristo-mini

Aristo mini is a light-weight question answering system that can quickly evaluate Aristo science questions with an evaluation web server and the provided baseline solvers.
Python
96
star
93

gpv-1

A task-agnostic vision-language architecture as a step towards General Purpose Vision
Jupyter Notebook
92
star
94

flex

Few-shot NLP benchmark for unified, rigorous eval
Python
91
star
95

elastic

Python
91
star
96

manipulathor

ManipulaTHOR, a framework that facilitates visual manipulation of objects using a robotic arm
Jupyter Notebook
88
star
97

spoc-robot-training

SPOC: Imitating Shortest Paths in Simulation Enables Effective Navigation and Manipulation in the Real World
Python
85
star
98

S2AND

Semantic Scholar's Author Disambiguation Algorithm & Evaluation Suite
Python
85
star
99

propara

ProPara (Process Paragraph Comprehension) dataset and models
Python
82
star
100

ARC-Solvers

ARC Question Solvers
Python
82
star