Mixture-of-Agents (MoA)

repository·main·Indexed 25 days ago

https://github.com/togethercomputer/moa

A layered architecture that leverages multiple LLMs to enhance performance by using several layers of agents to generate and aggregate responses. The repository includes integration with AlpacaEval for benchmarking instruction-following performance using metrics like Win Rate and Standard Error, and provides tools for configuring OpenAI and Azure OpenAI clients via YAML.

Tokens
32.1K
Snippets
99
Records
208
Agent score
84%

What's inside togethercomputer-moa

  1. Understand AlpacaEval Annotator Configurations

    main

    AlpacaEval uses various annotator configurations (evaluators) to score model outputs. These configurations define the API provider, model, parameters, parsing functions, and prompts used during the evaluation process.

    Key metrics used to compare annotators include:

    • Human agreement: Correlation with human judgments.
    • Price: Cost per 1000 examples.
    • Time: Seconds per 1000 examples.
    • Spearman/Pearson corr.: Statistical correlation with human labels.
    • Bias: Tendencies like preferring longer responses or lists.

    Commonly used annotator identifiers include alpaca_eval_gpt4, alpaca_eval_gpt4_fn (using OpenAI function calls), and claude_ranking.

  2. Understand Length-controlled AlpacaEval (LCAE)

    main

    Length-controlled AlpacaEval (LCAE) is an advancement designed to mitigate length bias in automatic evaluators. It addresses the issue where models can artificially increase win-rates by producing longer outputs.

    Key benefits of LCAE include:

    • Higher Correlation: Increases correlation with Chat Arena to 0.98 (up from 0.94 in AlpacaEval 2.0).
    • Reduced Gameability: Decreases length gameability to ~6% (compared to ~21% in standard AlpacaEval), making it 3x harder to manipulate via prompt length.
    • Predictive Modeling: Uses a Generalized Linear Model (GLM) to predict win-rates for different baselines, satisfying properties like win_rate(m,b) = 1 - win_rate(b,m) and win_rate(m,m) = 0.5.
  3. Access released LMSYS datasets

    main

    The following datasets are released by LMSYS and are available on Hugging Face for research and evaluation purposes:

    • LMSYS-Chat-1M: A large-scale real-world LLM conversation dataset.
    • Chatbot Arena Conversation Dataset: Conversations from the Chatbot Arena platform.
    • MT-bench Human Annotation Dataset: Human judgments used for MT-bench evaluation.
    https://huggingface.co/datasets/lmsys/lmsys-chat-1m
    https://huggingface.co/datasets/lmsys/chatbot_arena_conversations
    https://huggingface.co/datasets/lmsys/mt_bench_human_judgments
  4. Understand AlpacaEval limitations

    main

    AlpacaEval is an automatic evaluator for instruction-following capabilities and should not replace human evaluation for critical deployment decisions. Its limitations fall into three main categories:

    1. Instruction Representativeness: The instruction set (derived from datasets like self-instruct, open-assistant, vicuna, koala, and hh-rlhf) may not represent real-world usage or the complexity handled by advanced models like GPT-4.
    2. Automatic Annotator Biases:
      • Length/Style Bias: Annotators (including GPT-4 and Claude) tend to prefer longer outputs and those containing lists. This is partially mitigated by using length-controlled win-rates.
      • Content vs. Style: Annotators may prioritize output style over factuality.
      • Model Similarity Bias: Annotators may prefer models similar to themselves (e.g., GPT-4 preferring GPT-style outputs).
    3. Lack of Safety Evaluation: AlpacaEval does not evaluate toxicity, bias, or other harmful behaviors. High scores in instruction-following do not imply a model is safe for deployment.
  5. Quickstart: Implement MoA in 50 lines of code

    main

    To integrate Mixture-of-Agents (MoA) into your own applications, you can use the minimal implementation provided in moa.py. This example uses 2 layers and 4 LLMs.

    Prerequisites:

    1. Install the Together Python library: pip install together
    2. Obtain a Together API Key.
    3. Export your API key to the environment variable TOGETHER_API_KEY.

    Execution: Run the script using:

    python moa.py
    pip install together
    export TOGETHER_API_KEY=<your_key>
    python moa.py
  6. Use embeddings for similarity, classification, and semantic search

    main

    The test_embedding playground provides scripts to demonstrate common machine learning tasks using embeddings:

    • Text Similarity: Evaluate how similar two pieces of text are using test_sentence_similarity.py.
    • Classification: Build and test custom classifiers using test_classification.py.
    • Semantic Search: Perform searches based on relative text meaning using test_semantic_search.py.

    Prerequisites:

  7. Launch a LightLLM model worker in FastChat

    main

    To use LightLLM as the worker implementation, replace the standard fastchat.serve.model_worker with fastchat.serve.lightllm_worker. Other FastChat components like the controller, Gradio web server, and OpenAI API server remain unchanged.

    When launching, you must provide the --max_total_token_num argument. Refer to the LightLLM documentation to calculate the appropriate value for this argument.

    python3 -m fastchat.serve.lightllm_worker --model-path lmsys/vicuna-7b-v1.5 --tokenizer_mode "auto" --max_total_token_num 154000
  8. Install FastChat

    main

    To install FastChat, update your system packages, install tmux and htop, set up an Anaconda environment with Python 3.9, and install the FastChat package in editable mode from the cloned repository.

    sudo apt update
    sudo apt install tmux htop
    
    wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
    bash Anaconda3-2022.10-Linux-x86_64.sh
    
    conda create -n fastchat python=3.9
    conda activate fastchat
    
    git clone https://github.com/lm-sys/FastChat.git
    cd FastChat
    pip3 install -e .
  9. Analyze an evaluation set using notebooks

    main

    When creating evaluation sets, you should consider data volume and data quality. You can use the following notebooks to perform statistical analysis (such as paired t-tests) to determine how many samples are needed to distinguish between models and which datasets provide the most statistical power.

    Available Notebooks:

    Key Findings from Analysis:

    • Sample Size: Most models can be distinguished with as few as 50-150 samples.
    • Data Quality: Certain datasets, like self-instruct, may yield less statistical power and could potentially be removed from evaluation sets.