Home

Awesome

Lemur: Open Foundation Models for Language Agents

<p align="center"> <img src="https://i.imgur.com/Tga8kHW.jpeg" alt="Lemur"> </p> <a href="https://huggingface.co/OpenLemur" target="_blank"> <img alt="Models" src="https://img.shields.io/badge/🤗-Models-blue" /> </a> <a href="https://xlang.ai/blog/openlemur" target="_blank"> <img alt="Blog" src="https://img.shields.io/badge/📖-Blog-red" /> </a> <a href="https://arxiv.org/abs/2310.06830" target="_blank"> <img alt="Paper" src="https://img.shields.io/badge/📜-Paper-purple" /> </a> <a href="https://github.com/OpenLemur/lemur" target="_blank"> <img alt="Stars" src="https://img.shields.io/github/stars/OpenLemur/lemur?style=social" /> </a> <a href="https://github.com/OpenLemur/lemur/issues" target="_blank"> <img alt="Open Issues" src="https://img.shields.io/github/issues-raw/OpenLemur/lemur" /> </a> <a href="https://twitter.com/XLangNLP" target="_blank"> <img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/XLANG NLP Lab" /> </a> <a href="https://join.slack.com/t/xlanggroup/shared_invite/zt-20zb8hxas-eKSGJrbzHiPmrADCDX3_rQ" target="_blank"> <img alt="Join Slack" src="https://img.shields.io/badge/Slack-join-blueviolet?logo=slack&amp" /> </a> <a href="https://discord.gg/4Gnw7eTEZR" target="_blank"> <img alt="Discord" src="https://dcbadge.vercel.app/api/server/4Gnw7eTEZR?compact=true&style=flat" /> </a>

Lemur is an openly accessible language model optimized for both natural language and coding capabilities to serve as the backbone of versatile language agents. As language models continue to evolve from conversational chatbots to functional agents that can act in the real world, they need both strong language understanding and the ability to execute actions. Lemur balances natural language and coding skills to enable agents to follow instructions, reason for tasks, and take grounded actions.

<div align="center"> <img src="./assets/interface.png"> </div>

Please refer to our paper and code for more details:

🔥 News

Models

We released our models on the HuggingFace Hub:

Table of Contents

Why Lemur?

Most existing open-source models specialize in either natural language or code. Lemur combines both strengths by:

This two-stage training produces state-of-the-art performance averaged across diverse language and coding benchmarks, surpassing other available open-source models and narrowing the gap between open-source and commercial models on agent abilities.

Quickstart

Setup

First, we have to install all the libraries listed in requirements.txt

conda create -n xchat python=3.10
conda activate xchat
conda install pytorch==2.0.1 pytorch-cuda=11.8 -c pytorch -c nvidia
conda install -c "nvidia/label/cuda-11.8.0" cuda-nvcc

Then, install the xchat package:

git clone git@github.com:OpenLemur/Lemur.git
cd Lemur
pip install -e .

Lemur-70B

For the base model lemur-70b-v1, you can use it in this way:

<details> <summary>Click me</summary> <p>
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("OpenLemur/lemur-70b-v1")
model = AutoModelForCausalLM.from_pretrained("OpenLemur/lemur-70b-v1", device_map="auto", load_in_8bit=True)

# Text Generation Example
prompt = "The world is "
input = tokenizer(prompt, return_tensors="pt")
output = model.generate(**input, max_length=50, num_return_sequences=1)
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
print(generated_text)

# Code Generation Example
prompt = """
def factorial(n):
   if n == 0:
      return 1
"""
input = tokenizer(prompt, return_tensors="pt")
output = model.generate(**input, max_length=200, num_return_sequences=1)
generated_code = tokenizer.decode(output[0], skip_special_tokens=True)
print(generated_code)
</p> </details>

Lemur-70B-Chat

We instruction-finetune lemur-70b-v1 model with ChatML format to obtain lemur-70b-chat-v1. You can use lemur-70b-chat-v1 in this way:

<details> <summary>Click me</summary> <p>
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("OpenLemur/lemur-70b-chat-v1")
model = AutoModelForCausalLM.from_pretrained("OpenLemur/lemur-70b-chat-v1", device_map="auto", load_in_8bit=True)

# Text Generation Example
prompt = """<|im_start|>system
You are a helpful, respectful, and honest assistant.
<|im_end|>
<|im_start|>user
What's a lemur's favorite fruit?<|im_end|>
<|im_start|>assistant
"""
input = tokenizer(prompt, return_tensors="pt")
output = model.generate(**input, max_length=50, num_return_sequences=1)
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
print(generated_text)

# Code Generation Example
prompt = """<|im_start|>system
Below is an instruction that describes a task. Write a response that appropriately completes the request.
<|im_end|>
<|im_start|>user
Write a Python function to merge two sorted lists into one sorted list without using any built-in sort functions.<|im_end|>
<|im_start|>assistant
"""
input = tokenizer(prompt, return_tensors="pt")
output = model.generate(**input, max_length=200, num_return_sequences=1)
generated_code = tokenizer.decode(output[0], skip_special_tokens=True)
print(generated_code)
</p> </details>

Training

<div align="center"> <img src="./assets/training.png"> </div>

Evaluation

We evaluated Lemur across:

<div align="center"> <img src="./assets/agent-scenarios.png"> </div> <div align="center"> <img src="./assets/overall-perform.png"> </div>

Foundational Abilities

We build the evaluation suite based on open-instruct. We will keep updating more tasks and models.

Currently, we support the following tasks:

Interactive Agent Skills

We use the evaluation frameworks provided by MINT, InterCode, and WebArena to evaluate interactive agent skills.

Deploy

We use vLLM to serve the Lemur model. However, the official FastChat codebase does not yet support Lemur-Chat. Therefore, we provide a docker to serve vLLM for Lemur. Please refer to vllm_lemur.sh for more detailed information.

bash scripts/deploy/vllm_lemur.sh

MINT

We fork MINT codebase to share the configs we used. Please refer to this config folder for more details. Please run vllm with vllm_lemur.sh script.

WebArena

We fork WebArena codebase to enable vLLM evaluation. To run the evaluation on WebArena, please refer to our forked WebArena codebase.

InterCode

We fork InterCode codebase and do modifications to enable Lemur evaluation. Please refer to this script folder for more details. Please run text-generation-inference with tgi_lemur.sh script.

Citation

If you find our work helpful, please cite us:

@misc{xu2023lemur,
      title={Lemur: Harmonizing Natural Language and Code for Language Agents}, 
      author={Yiheng Xu and Hongjin Su and Chen Xing and Boyu Mi and Qian Liu and Weijia Shi and Binyuan Hui and Fan Zhou and Yitao Liu and Tianbao Xie and Zhoujun Cheng and Siheng Zhao and Lingpeng Kong and Bailin Wang and Caiming Xiong and Tao Yu},
      year={2023},
      eprint={2310.06830},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

Acknowledgements

The Lemur project is an open collaborative research effort between XLang Lab and Salesforce Research. We thank the following institutions for their gift support:

<div align="center"> <img src="assets/transparent.png" width="20" style="pointer-events: none;"> <a href="https://www.salesforceairesearch.com/"> <img src="assets/salesforce.webp" alt="Salesforce Research" height = 30/> </a> <img src="assets/transparent.png" width="20" style="pointer-events: none;"> <a href="https://research.google/"> <img src="assets/google_research.svg" alt="Google Research" height = 30/> </a> <img src="assets/transparent.png" width="25" style="pointer-events: none;"> <a href="https://www.amazon.science/" style="display: inline-block; margin-bottom: -100px;"> <img src="assets/amazon.svg" alt="Amazon AWS" height = 20 /> </a> </div>