Giter VIP home page Giter VIP logo

olmo's Introduction

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.

Details about the other types of OLMo checkpoints (including OLMo HF Transformers checkpoints) can be found in Checkpoints.md.

Inference

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

from transformers import AutoModelForCausalLM, AutoTokenizer

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

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-1.7-7B-hf")
print(olmo_pipe("Language modeling is"))

Inference on finetuned checkpoints

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

python scripts/convert_olmo_to_hf_new.py --input_dir /path/to/olmo/checkpoint --output_dir /path/to/hf/checkpoint/ --tokenizer_json_path tokenizers/allenai_gpt-neox-olmo-dolma-v1_5.json

Quantization

olmo = AutoModelForCausalLM.from_pretrained("allenai/OLMo-1.7-7B-hf", 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 interested 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},
}

olmo's People

Contributors

2015aroras avatar aakanksha19 avatar abhilasharavichander avatar akshitab avatar ananyahjha93 avatar davidbrandfonbrener avatar dependabot[bot] avatar dirkgr avatar djliden avatar drschwenk avatar dwadden avatar epwalsh avatar gahdritz avatar hamishivi avatar ianmagnusson avatar ibeltagy avatar jeqcho avatar kyleclo avatar leon-g-xu avatar lolipopshock avatar mewil avatar muennighoff avatar natolambert avatar nishantsubramani avatar oyvindtafjord avatar rauthur avatar rodneykinney avatar sarahwie avatar soldni avatar yulinggu-cs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

olmo's Issues

Investigate RMSNorm as an alternative to LayerNorm

There's a PyTorch implementation here: https://github.com/bzhangGo/rmsnorm/blob/master/rmsnorm_torch.py

The problem we have with LayerNorm (or at least PyTorch's built-in implementation of LayerNorm) is that torch's autocast behavior is hardcoded to upcast inputs to the function torch.layer_norm, and as a result using low precision LayerNorm requires some hacking that fails to work when using torch.compile(). Low precision LN gives a huge speedup with non-compiled models, so we're optimistic that getting this to work with compiled models would provide a similar speedup.

Switching to a different norm implementation could sidestep this issue, and RMSNorm is a simpler operation so we might get an even bigger speedup.

Add eval loop to training script

This should be pretty easy: just add a configuration field for eval batch size and what not, then initialize an eval dataloader in the same way that we initialize the train data loader and pass it to the Trainer.

Integrate latest throughput improvements from Mosaic

  • Abhi: "Using better FDSP configuration (BF16 all-gather, limiting all gathers, and a new non-reentrant version of activation checkpointing)."
    I think this means setting mixed_precision=PURE, limit_all_gathers=true, and activation_checkpointing_reentrant=false in the fsdp_config. Added in #61
  • Using Triton-based attention rather than HazyResearch Flash. We're sort of doing this already by using PyTorch's new built-in implementation.
  • Low precision LayerNorm. Implemented in #61
  • Use a fused version of CELoss. I think we're already doing this?
  • Increase microbatch size as high as possible.

Ensuring Data Order Tracking for Reproducibility

🚀 The feature, motivation and pitch

Yesterday we spoke about where responsibility for data order lives between the llm-model and llm-data workstreams. I thought it might be good to start an issue here where we can figure out who and how we should ensure that future work can reproduce our exact pretraining data order.

Use cases:

  • It should be clear exactly what tokens a given checkpoint has trained on, so we can ask if a model has seen a specific thing and how long ago it has seen that thing.
  • It should be possible to recreate the same order of documents using a different tokenizer to allow other research to compare to ours.

Proposed features:

  • Track which document IDs are in each concatenated example and which examples are in each batch
  • Have dataloaders that queue up data across devices and nodes such that sequence of document IDs is always the same, even if the boundaries between batches change

Proposed method:

  • When using j * k dataloaders, dl_i , across j nodes and k devices, each data loader should sample from n documents of the pretraining corpus, doc_i, with a stride of j*k
  • For example if j=1 and k=2 , dl_0[0] == doc_0 and dl_1[0] == doc_1 while dl_0[1] == doc_2 and dl_1[1] == doc_3
  • Finally during training, the model will log the doc ids and associated spans in each concatenated example, and examples will be logged per batch. A rough example might be, {batch_0 : [ [ (doc_0, (start_tok_idx, end_tok_idx)), ...], [(doc_42, (start_tok_idx, end_tok_idx)),...]]}

Let me know what I can do to help support this and coordinate responsibility between llm-model and llm-data.

Alternatives

A simple though reduced alternative is to just record the tokens that are trained on without any further changes.

While this supports the ability to see what a given checkpoint has seen and when it has seen it, this may make it difficult to recover batch and document boundaries or to reproduce this data order in a different tokenizer.

Also if we don’t ensure that data order is invariant to number of nodes and devices, it we may accidentally produce different training orders across different runs. Additionally it may be difficult for people using our codebase to reproduce our data order if they don’t have the same number of nodes and devices.

Additional context

No response

Try torch 2.0

It's supposed to be faster, and at this point, it's the only way we can get the fast interconnect working in LUMI.

Mosaic tells us we need to apply this to composer to make it work: dskhudia/composer@4d55bdb

We should expect a speed-up too.

Add (decoupled) LION optimizer

Mosaic has been preferring this over AdamW and it uses less memory since it only keeps track of momentum. We can find an implementation in this PR. Eventually this will be added to composer, but in the meantime we can just copy it over.

Continue running the 7B

One experiment is, let's just keep running the 7B and see if it recovers from the spikes.

Try bf16 on AMD hardware

Turns out we never tried it. If this fails, we need to talk to AMD ASAP. We cannot get to 70B without this.

Add a 7B config

We promised a 7B model. Also, we need an appropriately sized model to test multi-node training at smaller scales.

Look at data right where the spike happens

It is suspicious that we had two slightly different models (one with biases, one without), that both spiked at exactly the same moment. This suggests there might be a data issue.

Try adding intermediate layer losses

🚀 The feature, motivation and pitch

E.g. we have an LM loss at 1/2, 1/4, 1/8 of the model.

To avoid the degenerate scenario where, for example, the first half of the model does well but the 2nd half just becomes a bunch of ~identity layers, we could have a separate LM head for each loss, i.e. at each layer in the model where we apply an LM loss. So we'd have to untie the embedding matrix from the LM head.

Alternatives

No response

Additional context

No response

Multi-Query attention from PaLM

🚀 The feature, motivation and pitch

Iz and I were talking about this today, can be under nice to have

This is from the PaLM paper:

"The standard Transformer formulation uses k attention heads, where the input vector for each timestep is linearly projected into “query”, “key”, and “value” tensors of shape [k, h], where h is the attention head size. Here, the key/value projections are shared for each head, i.e. “key” and “value” are projected to [1, h], but “query” is still projected to shape [k, h]. We have found that this has a neutral effect on model quality and training speed (Shazeer, 2019), but results in a significant cost savings at autoregressive decoding time. This is because standard multi-headed attention has low efficiency on accelerator hardware during auto-regressive decoding, because the key/value tensors are not shared between examples, and only a single token is decoded at a time."

Alternatives

No response

Additional context

No response

Rename "DOLMA" to "OLMo"

We should either wait until #61 merges, or do this on as part of that PR.

We need to grep through and change all mentions of "DOLMA" / "Dolma" / "dolma" and also rename the Python module itself.

Basically:

# Rename Python module.
mv dolma olmo
# Find and replace all mentions using `fd` and `sd` (`brew install fd sd`)
fd -H --exclude .git | xargs sd 'DOLMA' 'OLMo'
fd -H --exclude .git | xargs sd 'Dolma' 'Olmo'
fd -H --exclude .git | xargs sd 'dolma' 'olmo'

Does using `Dropout` layers, even if the probability is 0, have a performance penalty?

❓ The question

Ideally there should be no performance penalty for dropout layers when the dropout probability is 0. But if there is, we should bypass dropout when p=0.0.

I'm currently testing this here: https://wandb.ai/ai2-llm/dropout-benchmarks

There will be 4 runs:

  1. 1.2b-bf16-no-dropout: uses a patched branch that bypasses all calls to dropout (except inside of the scaled_dot_product_attention function which we have no control over). This model is compiled using the default settings.
  2. 1.2b-bf16-zero-dropout: uses the usual implementation without any code changes were we still call the Dropout modules even though the dropout probability is set to 0. This model is compiled using the default settings.
  3. 1.2b-bf16-no-compile-no-dropout: same as 1.2b-bf16-no-dropout except this model is NOT compiled.
  4. 1.2b-bf16-no-compile-zero-dropout: same as 1.2b-bf16-zero-dropout except this model is NOT compiled.

Collect 70B S2 tokens

Exact spec still WIP, but TODOs are basically:

  1. Athena query to get Titles & Abstracts from S2AG. Form JSON blob per document of the form:
{"text": "...", "paper_id": <identifier>}
  • To concatenate, " ".join([title, abstract]) should be sufficient.
  • Double-check whether structured abstracts preserve whitespace.
  1. Athena query to get S2ORC-OA papers. Form JSON blob per document of the form:
{"text": "...", "paper_id": <identifier>}
  • To concatenate, also whitespace join to linearize structured content.
  • Keep everything for now, including tables, bibliographies, etc.
  1. Build a blocklist of papers. For now, should just be a single file mapping paper_ids to some note or reason for removal. To start, this should be documents that are part of the test set for Catwalk evaluation, especially Pubmed/arXiv abstract generation.

Integrate down-stream evaluation code

🚀 The feature, motivation and pitch

No response

Alternatives

No response

Additional context

Make additional layer and adapter for running code with existing down-stream evaluation tools (e.g., HELM, Catwalk).

Sequential Olmo block should not have shared layernorm

🐛 Describe the bug

Ideally, the Layernorm layers for a sequential block are separate for attention and FFN modules. Good thing is we haven't seen too much difference because of this until now.

        q, k, v = self.att_proj(self.norm(x)).split(self.fused_dims, dim=-1)

        # Get attention scores.
        att, cache = self.attention(q, k, v, attention_bias, layer_past=layer_past, use_cache=use_cache)

        # Add attention scores.
        # shape: (B, T, C)
        x = x + self.dropout(att)

        # Add feed-forward projection.
        # shape: (batch_size, seq_len, d_model)
        x = x + self.dropout(self.ff_out(self.act(self.ff_proj(self.norm(x)))))

self.norm should be self.norm2 ideally in the last line

Versions

No response

Log into some online logging service

This is an experiment, but probably worthwhile. With 1000 nodes, it gets very difficult to see which node did what and when, especially when they fail, if they all log to stdout, which slurs stuffs into a single log file. Papertrail is basically running syslog-as-a-service. We can send log messages there, and then look and filter with their UI. We need to configure our code to write logs to their syslog service to do this.

Add `generate` method to our model implementation

🚀 The feature, motivation and pitch

We need a generate method to run evaluation. Minimum requirement:

  • top_k / top_p support
  • temperature control
  • return log probabilities.

Llama's generate method is fairly straightforward but we can't use it because of it has the wrong license.

Alternatives

  • Converting the model in HuggingFace and use their generate method. This will eventually need to be done, but, since we haven't fully finalized the architecture, this is too soon.
  • Finding a Apache 2.0 generation method.

Additional context

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.