Skip to main content

RepoQA: Evaluating Long-Context Code Understanding

🏠 Homepage: https://evalplus.github.io/repoqa.html

🚀 Installation

# without vLLM (can run openai, anthropic, and huggingface backends)
pip install --upgrade repoqa
# To enable vLLM
pip install --upgrade "repoqa[vllm]"
⏬ Install nightly version :: click to expand ::
pip install --upgrade "git+https://github.com/evalplus/repoqa.git"                 # without vLLM
pip install --upgrade "repoqa[vllm] @ git+https://github.com/evalplus/repoqa@main" # with vLLM
⏬ Using RepoQA as a local repo? :: click to expand ::
git clone https://github.com/evalplus/repoqa.git
cd repoqa
export PYTHONPATH=$PYTHONPATH:$(pwd)
pip install -r requirements.txt

🏁 Search Needle Function (SNF)

Search Needle Function is the first and base RepoQA task which aims to practice LLMs' ability of long-context code understanding and retrieval. Its corresponding real-life scenario is to perform precise code search from function description.

🔎 More dataset details :: click to expand ::

You can run the SNF evaluation using various backends:

OpenAI Compatible Servers

repoqa.search_needle_function --model "gpt4-turbo" --backend openai
# 💡 If you use openai API compatible server such as vLLM servers:
# repoqa.search_needle_function --base-url "http://localhost:[PORT]/v1" \
#                               --model "Qwen/CodeQwen1.5-7B-Chat" --backend openai

Anthropic Compatible Servers

repoqa.search_needle_function --model "claude-3-haiku-20240307" --backend anthropic

vLLM

repoqa.search_needle_function --model "Qwen/CodeQwen1.5-7B-Chat" --backend vllm
🔎 Context extension for small-ctx models :: click to expand ::

There are two ways to unlock a model's context at inference time:

  1. Direct Extension: Edit max_positional_embedding of the model's config.json (e.g., hub/models--meta-llama--Meta-Llama-3-8B-Instruct/snapshots/[hash]/config.json) to something like 22528.
  2. Dynamic RoPE Scaling: To extend Meta-Llama-3-8B-Instruct from 8k to 32k (4x), edit the config.json:

"rope_scaling": {"type": "dynamic", "factor": 4.0}

Note: This works for vLLM <0.4.3 and HuggingFace transformers. RepoQA will automatically configure dynamic RoPE for vLLM >= 0.4.3

HuggingFace transformers

repoqa.search_needle_function --model "Qwen/CodeQwen1.5-7B-Chat" --backend hf --trust-remote-code
🔨 Having trouble installing `flash-attn`? :: click to expand ::

If you have trouble with pip install flash-attn --no-build-isolation, you can try to directly use pre-built wheels:

export FLASH_ATTN_VER=2.5.8 # check latest version at https://github.com/Dao-AILab/flash-attention/releases
export CUDA_VER="cu122"     # check available ones at https://github.com/Dao-AILab/flash-attention/releases
export TORCH_VER=$(python -c "import torch; print('.'.join(torch.__version__.split('.')[:2]))")
export PY_VER=$(python -c "import platform; print(''.join(platform.python_version().split('.')[:2]))")
export OS_ARCH=$(python -c "import platform; print(f'{platform.system().lower()}_{platform.machine()}')")

export WHEEL=flash_attn-${FLASH_ATTN_VER}+${CUDA_VER}torch${TORCH_VER}cxx11abiFALSE-cp${PY_VER}-cp${PY_VER}-${OS_ARCH}.whl
wget https://github.com/Dao-AILab/flash-attention/releases/download/v${FLASH_ATTN_VER}/${WHEEL}
pip install ${WHEEL}

Google Generative AI API (Gemini)

repoqa.search_needle_function --model "gemini-1.5-pro-latest" --backend google

CLI Usage

  • Input:
    • --model: Hugging-Face model ID, such as ise-uiuc/Magicoder-S-DS-6.7B
    • --backend: vllm (default) or openai
    • --base-url: OpenAI API base URL
    • --code-context-size (default: 16384): #tokens (by DeepSeekCoder tokenizer) of repository context
    • --caching (default: True): accelerate subsequent runs by caching preprocessing; --nocaching to disable
    • --max-new-tokens (default: 1024): Maximum #new tokens to generate
    • --system-message (default: None): system message (note it's not supported by some models)
    • --tensor-parallel-size: #GPUS for doing tensor parallelism (only for vLLM)
    • --languages (default: None): List of languages to evaluate (None means all)
    • --result-dir (default: "results"): Directory to save the model outputs and evaluation results
    • --ignore-comments (default: False): During evaluation, ignore groundtruth and model comments
    • --trust-remote-code (default: False): allow remote code (for HuggingFace transformers and vLLM)
    • --attn-implementation (default: None): Use "flash_attention_2" if your HF hits OOM
  • Output:
    • results/ntoken_{code-context-size}/{model}.jsonl: Model generated outputs
    • results/ntoken_{code-context-size}/{model}-SCORE.json: Evaluation results

Compute Scores

By default, the repoqa.search_needle_function command will evaluate model outputs and compute scores after text generation. However, you can also separately compute scores using the following command:

repoqa.compute_score --model-output-path={model-output}.jsonl

📚 Read More

Metadata

Release files for repoqa 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for repoqa 0.1.2
File Size Uploaded Provenance Actions
repoqa-0.1.2.tar.gz 5.4 MB Without provenance Details for repoqa-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for repoqa 0.1.2
File Interpreter ABI Platform Actions
repoqa-0.1.2-py3-none-any.whl Python 3 none any Details for repoqa-0.1.2-py3-none-any.whl

Total release size: 5.5 MB

Release files / repoqa-0.1.2.tar.gz

Download URL repoqa-0.1.2.tar.gz
Size 5.4 MB
Tags Source
SHA-256 checksum
How to use checksums
c08efb7f700c40c4d2e6f89d748049c3d14eaea3f14fda7192bcd1392d16cd60
BLAKE2b-256 checksum
How to use checksums
1363c8154ab5680cdd6d8d56408a57af8e64cb95c6d52dbdf5e19f5866722777
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.13

Release files / repoqa-0.1.2-py3-none-any.whl

Download URL repoqa-0.1.2-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f18e82dc678ff90478a80473a171a63fffc49563283a0714a942dabdc1be35ab
BLAKE2b-256 checksum
How to use checksums
e30de85e54061821c76af16fcc9264b6019a0c1391ce7024d6b6d5a96154cd4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.8.13

Security for repoqa 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page