Sachin Mehta, Mohammad Hossein Sekhavat, Qingqing Cao, Maxwell Horton, Yanzi Jin, Chenfan Sun, Iman Mirzadeh, Mahyar Najibi, Dmitry Belenko, Peter Zatloukal, Mohammad Rastegari
We introduce OpenELM, a family of OpenEfficient Language Models. OpenELM uses a layer-wise scaling strategy to efficiently allocate parameters within each layer of the transformer model, leading to enhanced accuracy. We pretrained OpenELM models using the CoreNet library. We release both pretrained and instruction tuned models with 270M, 450M, 1.1B and 3B parameters. We release the complete framework, encompassing data preparation, training, fine-tuning, and evaluation procedures, alongside multiple pre-trained checkpoints and training logs, to facilitate open research.
Our pre-training dataset contains RefinedWeb, deduplicated PILE, a subset of RedPajama, and a subset of Dolma v1.6, totaling approximately 1.8 trillion tokens. Please check license agreements and terms of these datasets before using them.
Usage
We have provided an example function to generate output from OpenELM models loaded via HuggingFace Hub in generate_openelm.py.
You can try the model by running the following command:
python generate_openelm.py --model apple/OpenELM-3B-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2
Please refer to this link to obtain your hugging face access token.
Additional arguments to the hugging face generate function can be passed via generate_kwargs. As an example, to speedup the inference, you can try lookup token speculative generation by passing the prompt_lookup_num_tokens argument as follows:
python generate_openelm.py --model apple/OpenELM-3B-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 prompt_lookup_num_tokens=10
Alternatively, try model-wise speculative generation with an assistive model by passing a smaller model through the assistant_model argument, for example:
python generate_openelm.py --model apple/OpenELM-3B-Instruct --hf_access_token [HF_ACCESS_TOKEN] --prompt 'Once upon a time there was' --generate_kwargs repetition_penalty=1.2 --assistant_model [SMALLER_MODEL]
See the technical report for more results and comparison.
Evaluation
Setup
Install the following dependencies:
bash
12# install public lm-eval-harness34harness_repo="public-lm-eval-harness"5git clone https://github.com/EleutherAI/lm-evaluation-harness ${harness_repo}6cd${harness_repo}7# use main branch on 03-15-2024, SHA is dc90fec8git checkout dc90fec
9pip install -e .10cd..1112# 66d6242 is the main branch on 2024-04-01 13pip install datasets@git+https://github.com/huggingface/datasets.git@66d6242
14pip install tokenizers>=0.15.2 transformers>=4.38.2 sentencepiece>=0.2.0
15
Evaluate OpenELM
bash
12# OpenELM-3B-Instruct3hf_model=apple/OpenELM-3B-Instruct
45# this flag is needed because lm-eval-harness set add_bos_token to False by default, but OpenELM uses LLaMA tokenizer which requires add_bos_token to be True6tokenizer=meta-llama/Llama-2-7b-hf
7add_bos_token=True
8batch_size=1910mkdir lm_eval_output
1112shot=013task=arc_challenge,arc_easy,boolq,hellaswag,piqa,race,winogrande,sciq,truthfulqa_mc2
14lm_eval --model hf \15 --model_args pretrained=${hf_model},trust_remote_code=True,add_bos_token=${add_bos_token},tokenizer=${tokenizer}\16 --tasks ${task}\17 --device cuda:0 \18 --num_fewshot ${shot}\19 --output_path ./lm_eval_output/${hf_model//\//_}_${task//,/_}-${shot}shot \20 --batch_size ${batch_size}2>&1|tee ./lm_eval_output/eval-${hf_model//\//_}_${task//,/_}-${shot}shot.log
2122shot=523task=mmlu,winogrande
24lm_eval --model hf \25 --model_args pretrained=${hf_model},trust_remote_code=True,add_bos_token=${add_bos_token},tokenizer=${tokenizer}\26 --tasks ${task}\27 --device cuda:0 \28 --num_fewshot ${shot}\29 --output_path ./lm_eval_output/${hf_model//\//_}_${task//,/_}-${shot}shot \30 --batch_size ${batch_size}2>&1|tee ./lm_eval_output/eval-${hf_model//\//_}_${task//,/_}-${shot}shot.log
3132shot=2533task=arc_challenge,crows_pairs_english
34lm_eval --model hf \35 --model_args pretrained=${hf_model},trust_remote_code=True,add_bos_token=${add_bos_token},tokenizer=${tokenizer}\36 --tasks ${task}\37 --device cuda:0 \38 --num_fewshot ${shot}\39 --output_path ./lm_eval_output/${hf_model//\//_}_${task//,/_}-${shot}shot \40 --batch_size ${batch_size}2>&1|tee ./lm_eval_output/eval-${hf_model//\//_}_${task//,/_}-${shot}shot.log
4142shot=1043task=hellaswag
44lm_eval --model hf \45 --model_args pretrained=${hf_model},trust_remote_code=True,add_bos_token=${add_bos_token},tokenizer=${tokenizer}\46 --tasks ${task}\47 --device cuda:0 \48 --num_fewshot ${shot}\49 --output_path ./lm_eval_output/${hf_model//\//_}_${task//,/_}-${shot}shot \50 --batch_size ${batch_size}2>&1|tee ./lm_eval_output/eval-${hf_model//\//_}_${task//,/_}-${shot}shot.log
51
Bias, Risks, and Limitations
The release of OpenELM models aims to empower and enrich the open research community by providing access to state-of-the-art language models. Trained on publicly available datasets, these models are made available without any safety guarantees. Consequently, there exists the possibility of these models producing outputs that are inaccurate, harmful, biased, or objectionable in response to user prompts. Thus, it is imperative for users and developers to undertake thorough safety testing and implement appropriate filtering mechanisms tailored to their specific requirements.
Citation
If you find our work useful, please cite:
BibTex
1@article{mehtaOpenELMEfficientLanguage2024,
2 title = {{OpenELM}: {An} {Efficient} {Language} {Model} {Family} with {Open} {Training} and {Inference} {Framework}},
3 shorttitle = {{OpenELM}},
4 url = {https://arxiv.org/abs/2404.14619v1},
5 language = {en},
6 urldate = {2024-04-24},
7 journal = {arXiv.org},
8 author = {Mehta, Sachin and Sekhavat, Mohammad Hossein and Cao, Qingqing and Horton, Maxwell and Jin, Yanzi and Sun, Chenfan and Mirzadeh, Iman and Najibi, Mahyar and Belenko, Dmitry and Zatloukal, Peter and Rastegari, Mohammad},
9 month = apr,
10 year = {2024},
11}
1213@inproceedings{mehta2022cvnets,
14 author = {Mehta, Sachin and Abdolhosseini, Farzad and Rastegari, Mohammad},
15 title = {CVNets: High Performance Library for Computer Vision},
16 year = {2022},
17 booktitle = {Proceedings of the 30th ACM International Conference on Multimedia},
18 series = {MM '22}
19}