Code Monkey home page Code Monkey logo

lloco's Introduction

LLoCO: Learning Long Contexts Offline

LLoCO is a technique that learns documents offline through context compression and in-domain parameter-efficient finetuning using LoRA, which enables LLMs to handle long context efficiently.

lloco-arch

Getting Started

Installation

Setup a new environment and run:

pip install -r requirements.txt

Download Datasets (Optional)

Use the following command to download the QuALITY dataset. Other datasets are loaded from HuggingFace and can be downloaded automatically during data loading.

cd data
wget https://raw.githubusercontent.com/nyu-mll/quality/main/data/v1.0.1/QuALITY.v1.0.1.htmlstripped.train
wget https://raw.githubusercontent.com/nyu-mll/quality/main/data/v1.0.1/QuALITY.v1.0.1.htmlstripped.dev

Preprocess Summary Embeddings

First generate summary embeddings for the datasets. An example bash script is stored in scripts/preproc_emb.sh, which preprocess the training dataset of QuALITY:

python3 preproc_embs.py \
    --emb_model_name "autocomp" \
    --dataset quality \
    --split train \
    --data_path ./data/QuALITY.v1.0.1.htmlstripped.train \
    --out_path ./embeddings/quality_train_embs.pth \
    --truncation False \

This script will generate summary embeddings for QuALITY training set, and store the embeddings in the /embeddings folder. Embedding generation for other datasets works similarly.

Finetune

Here is an example bash script to finetune the QuALITY dataset. This script is in scripts/finetune_quality.sh.

torchrun --nproc_per_node=4 finetune_quality.py  \
        --output_dir output/lloco_quality \
        --run_name lloco_quality \
        --data_path ./data/QuALITY.v1.0.1.htmlstripped.train \
        --embedding_path ./embeddings/quality_train_embs.pth \
        ...

Inference & Evaluation

Below is a bash script to run inference over the validation sets are contained in script/inference.sh. Evaluation results are stored in out_path, and the finetuned model is specified by peft_model.

python3 inference.py  \
    --model_name_or_path meta-llama/Llama-2-7b-chat-hf \
    --dataset_name qmsum \
    --eval_mode autocomp \
    --out_path ./eval/qmsum_lloco.json \
    --peft_model output/lloco_qmsum  \
    --embedding_path ./embeddings/qmsum_val_embs.pth \
    ...

After obtaining the prediction files, use the following evaluation scripts in the /eval folder to get the scores for each dataset.

Evaluate QuALITY:

python3 quality_evaluator.py --quality_path {quality_path} --pred_path {prediction_file}

Evaluate QMSum, Qasper, NarrativeQA:

python3 scroll_evaluator.py --split validation --dataset_name {dataset_name} --predictions {prediction_file} --metrics_output_dir .

Evaluate HotpotQA:

python3 hotpot_evaluator.py --pred_path {prediction_fild}

TODOs

  • Release finetuning and inference code.
  • Release pre-trained LoRA weights on HuggingFace.
  • Integrate to VLLM.

Citation

If you find LLoCO useful or relevant to your project and research, please kindly cite our paper:

@article{tan2024lloco,
  title   = {LLoCO: Learning Long Contexts Offline},
  author  = {Sijun Tan and Xiuyu Li and Shishir Patil and Ziyang Wu and Tianjun Zhang and Kurt Keutzer and Joseph E. Gonzalez and Raluca Ada Popa},
  year    = {2024},
  journal = {arXiv preprint arXiv: 2404.07979}
}

Acknowledgements

We referred to AutoCompressors for the context encoder implementation.

lloco's People

Contributors

eltociear avatar xiuyu-li avatar jeffreysijuntan avatar

Stargazers

Gibran Iqbal avatar  avatar song avatar  avatar Dawei Zhu avatar Ramsey avatar  avatar Chien-Yu Lin avatar Michael Luo avatar  avatar Sachin Chanchani avatar polya avatar Andrew Chauzov avatar  avatar Aditya Verma avatar Chandan Jog avatar elucida avatar Alberto Ferrer avatar Iron-Bound avatar Rohit Saxena avatar Theodore M avatar Lesly Arun Franco avatar Ali Mosavian avatar Gan Longgang avatar  avatar Emma Thompson avatar vignesh avatar  avatar Mohammad Reza Taesiri avatar Anshul Singh avatar Minh Tran avatar  avatar S.C. Sabry avatar Shuai Wang avatar Sadra Barikbin avatar  avatar mukul avatar muhtasham avatar Zeege avatar Asim Shah avatar  avatar suqiang song avatar Hongzheng Chen avatar Wenzhao Zheng avatar Anthony Carlton Russano, III avatar Rohan Paul avatar  avatar  avatar Jose Cohenca avatar Yunqian Fan avatar  avatar Inho Won avatar kyle avatar  avatar  avatar Xiang Zhao avatar Khanh Tran avatar Sehoon Kim avatar ZikaiXiao avatar Jeff Carpenter avatar  avatar MarcoPolignano avatar Rigved  avatar Max Ilyin avatar Yihan Wang avatar  avatar  avatar Hui Su avatar  avatar yukang avatar Ryan C Tufts avatar Xiaohui Yan avatar 唐国梁Tommy avatar Jinhao Zhu avatar Sarah Wooders avatar  avatar Muyang Li avatar Amund Tveit avatar Paragoner avatar Stefan avatar Zachariah Mustafa avatar dImrich avatar  avatar init avatar Vincent avatar  avatar  avatar Daxiong avatar

Watchers

 avatar vignesh avatar  avatar

lloco's Issues

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.