InfiniteBench

repository·main·Indexed 18 days ago

https://github.com/openbmb/infinitebench

A benchmark designed to evaluate Large Language Models (LLMs) on their ability to process and reason over extremely long contexts (100k+ tokens). It covers five key domains—Retrieval, Mathematics, Code, Question Answering (QA), and Summarization—using both real-world and synthetic data in English and Chinese. The benchmark includes 12 tasks with an average context length of 195K tokens and provides tools for inference and score computation using metrics such as Accuracy, ROUGE F1, and rougeLsum.

Tokens
12.5K
Snippets
45
Records
56
Agent score
62%

What's inside InfiniteBench

  1. Overview of InfiniteBench

    main
    InfiniteBench is a benchmark designed to evaluate Large Language Models (LLMs) on long-context capabilities exceeding 100K tokens. It features an average context length of 195K tokens and covers five key domains: Retrieval, Mathematics, Code, Question Answering (QA), and Summarization. The benchmark includes both real-world and synthetic data in both English and Chinese.
  2. InfiniteBench Task Composition and Metrics

    main

    InfiniteBench evaluates models on 12 tasks designed for 100k+ token contexts. The evaluation metrics vary by task type:

    • Accuracy: Used for Math.Find, Math.Calc, Code.Run, Code.Debug, En.Dia, En.MC, Retrieve.KV, Retrieve.Number, and Retrieve.PassKey.
    • ROUGE F1: Used for Zh.QA and En.QA.
    • rougeLsum (🤗 Evaluate): Used for En.Sum.

    Task Details Overview:

    Task NameContextAvg Input TokensDescription
    En.SumFake Book171.5kSummarization of a fake book.
    En.QAFake Book192.6kFree-form QA on fake book.
    En.MCFake Book184.4kMultiple choice on fake book.
    En.DiaScript103.6kIdentifying talkers in scripts.
    Zh.QANew Book2068.6kQA on newly collected books.
    Code.DebugCode Document114.7kFinding crashing functions in code.
    Code.RunSynthetic75.2kSimulating synthetic function execution.
    Math.CalcSynthetic43.9kLong arithmetic equations.
    Math.FindSynthetic87.9kFinding integers in a long list.
    Retrieve.PassKeySynthetic122.4kRetrieving hidden keys in noise.
    Retrieve.NumberSynthetic122.4kLocating repeated numbers in noise.
    Retrieve.KVSynthetic89.9kFinding dictionary values from keys.
  3. Run inference for InfiniteBench tasks

    main

    To evaluate a model (e.g., GPT-4) on a specific task, navigate to the src directory and run the evaluation script with the --task flag.

    Available tasks for --task flag:

    • passkey (Retrieve.PassKey)
    • number_string (Retrieve.Number)
    • kv_retrieval (Retrieve.KV)
    • longbook_sum_eng (En.Sum)
    • longbook_qa_eng (En.QA)
    • longbook_qa_chn (Zh.QA)
    • longbook_choice_eng (En.MC)
    • longdialogue_qa_eng (En.Dia)
    • math_calc (Math.Calc)
    • math_find (Math.Find)
    • code_debug (Code.Debug)
    • code_run (Code.Run)
    cd src
    python eval_gpt4.py --task passkey
  4. Run InfiniteBench evaluations

    main

    To run evaluations, ensure the data folder is in your current directory (or specify the location using the --data_dir argument). The data folder must contain the .jsonl files corresponding to the tasks.

    Navigate to the src folder and execute the evaluation script for your target model and task.

    Example commands:

    python eval_yarn_mistral.py --task kv_retrieval
    python eval_gpt4.py --task longbook_sum_qa
    python eval_rwkv.py --task passkey
  5. Download InfiniteBench datasets

    main

    You can download the InfiniteBench data using one of the following three methods:

    1. Direct Download

    Download directly from Hugging Face: https://huggingface.co/datasets/xinrongzhang2022/InfiniteBench

    2. Using 🤗 Datasets library

    Use the datasets Python library to load the data with specific features:

    from datasets import load_dataset, Value, Sequence
    
    # Define the schema
    ft = Features({
        "id": Value("int64"), 
        "context": Value("string"), 
        "input": Value("string"), 
        "answer": Sequence(Value("string")), 
        "options": Sequence(Value("string"))
    })
    
    # Load the dataset
    dataset = load_dataset("xinrongzhang2022/InfiniteBench", features=ft)

    3. Using Shell Scripts

    Run the provided download script to dump data directly into a data folder:

    cd InfiniteBench
    bash scripts/download_dataset.sh
    from datasets import load_dataset, Value, Sequence
    ft = Features({"id": Value("int64"), "context": Value("string"), "input": Value("string"), "answer": Sequence(Value("string")), "options": Sequence(Value("string"))})
    dataset = load_dataset("xinrongzhang2022/InfiniteBench", features=ft)
  6. Scoring logic for specific task types

    main

    The library implements specialized scoring logic for different evaluation paradigms:

    Task CategoryFunctionLogic Description
    Retrievalget_score_one_kv_retrievalChecks if the label exists as a word in the prediction after cleaning punctuation.
    Passkey/Numberget_score_one_passkeyUses first_int_match to extract the first integer from the prediction and compares it to the label.
    Code Executionget_score_one_code_runExtracts the last integer from the prediction and compares it to the label.
    Code Debuggingget_score_one_code_debugUses regex to find the last option (A-J) or checks for specific answer prefixes (e.g., "answer is:").
    Math (Find)get_score_one_math_findExtracts the first integer or float from the prediction and compares it to the label.
    Math (Calc)get_score_one_math_calcCompares the sequence of integers in the prediction against the sequence in the label.
    Longbook QAget_score_one_longbook_qa_engUses token-based F1 score via qa_f1_score on normalized text.
    Longbook Sumget_score_one_longbook_sum_engUses ROUGE-Lsum via the evaluate library.
  7. Run model evaluation using GPT-4 via eval_gpt4.py

    main

    The eval_gpt4.py script allows you to evaluate models on InfiniteBench tasks using the OpenAI GPT-4 API. It processes examples from a specified task, generates predictions, and saves them to a JSONL file. The script supports resuming from where it left off if an output file already exists in the target directory.

    To use this script, you must ensure your OpenAI API key and Organization ID are configured within the script (or via the environment if modified), and provide the necessary command-line arguments for the task and data directory.

    python src/eval_gpt4.py --task <task_name> --data_dir <path_to_data> --output_dir <path_to_output> [--verbose]
    
    # Example usage:
    python src/eval_gpt4.py --task long_context_qa --data_dir ./data --output_dir ./results --verbose
  8. Run evaluation with Yi-200k models

    main

    The eval_yi_200k.py script is a specialized evaluation entrypoint designed for models with long context windows (up to 200k tokens), specifically optimized for the Yi-200k model architecture using vLLM.

    It automates the process of loading a model, loading InfiniteBench datasets, generating predictions with specific truncation logic, and saving results to JSONL files. The script handles input truncation to ensure the context stays within the model's limits (using a 'middle' truncation strategy) before performing inference.

    To use this script, you must provide arguments via the CLI (parsed by args.py). Key parameters include:

    • --model_path: Path to the model weights.
    • --model_name: Name of the model (used for directory organization).
    • --task: The InfiniteBench task name.
    • --data_dir: Directory containing the dataset.
    • --output_dir: Directory where results will be saved.
    • --start_idx / --stop_idx: Range of examples to evaluate.
    • --verbose: Enable detailed logging of inputs and predictions.
    # Example CLI invocation (assuming args.py defines these flags)
    python src/eval_yi_200k.py \
        --model_path /path/to/yi-200k \
        --model_name yi-200k \
        --task task_name \
        --data_dir ./data \
        --output_dir ./results \
        --start_idx 0 \
        --stop_idx 100
  9. Configure API keys and local model endpoints

    main

    The project uses a config.txt file to manage credentials and service endpoints. The load_and_log_configs() function parses this file into a structured dictionary.

    Config Sections and Keys:

    [API]

    Used for cloud providers:

    • anthropic_api_key, openai_api_key, cohere_api_key, groq_api_key, huggingface_api_key, openrouter_api_key, deepseek_api_key, mistral_api_key
    • Model identifiers: anthropic_model, openai_model, etc.

    [Local-API]

    Used for self-hosted inference servers:

    • kobold_api_IP, llama_api_IP, ooba_api_IP, tabby_api_IP, vllm_api_IP, ollama_api_IP, aphrodite_api_IP
    • Keys: kobold_api_key, llama_api_key, etc.

    [Paths]

    • output_path: Where results are saved (default: results).

    [Processing]

    • processing_choice: Hardware preference (e.g., cpu).