BigCodeBench

repository·main·Indexed 19 days ago

https://github.com/bigcode-project/bigcodebench

A benchmark for evaluating the practical programming capabilities of LLMs through complex instructions and diverse function calls. It supports code completion and instruction-following tasks across 'full' and 'hard' subsets. The library provides CLI tools for generating code samples (`bigcodebench.generate`), evaluating samples via remote APIs or local execution (`bigcodebench.evaluate`), and verifying code syntax (`bigcodebench.syncheck`). It supports multiple model backends including vLLM, OpenAI, Anthropic, Google, Mistral, and Hugging Face.

Tokens
4.4K
Snippets
13
Records
19
Agent score
18%

What's inside BigCodeBench

  1. Understand BigCodeBench splits and subsets

    main

    BigCodeBench provides different ways to slice the benchmark tasks based on the model type and difficulty:

    Splits

    • complete: Designed for code completion tasks using comprehensive docstrings.
    • instruct: Designed for instruction-tuned and chat models. Models generate code based on natural language instructions requiring complex reasoning.

    Subsets

    • full: The complete set of tasks.
    • hard: A subset of 148 tasks aligned with real-world programming tasks.
  2. Use BigCodeBench as a local repository

    main

    If you want to work with the source code directly, clone the repository, add the current directory to your PYTHONPATH, and install it in editable mode.

    git clone https://github.com/bigcode-project/bigcodebench.git
    cd bigcodebench
    export PYTHONPATH=$PYTHONPATH:$(pwd)
    pip install -e .
  3. Install BigCodeBench and evaluation requirements

    main

    To use BigCodeBench, you should set up an isolated environment. You need two sets of dependencies: one for the core library and one for local evaluation.

    1. Install evaluation requirements: Required if you intend to run evaluations locally.
    2. Install BigCodeBench: The main library.

    To install the nightly version, use the git URL directly.

    # Install evaluation requirements in an isolated environment
    pip install -I -r https://raw.githubusercontent.com/bigcode-project/bigcodebench/main/Requirements/requirements-eval.txt
    
    # Install BigCodeBench dependencies
    pip install bigcodebench --upgrade
    
    # OR: Install nightly version
    pip install "git+https://github.com/bigcode-project/bigcodebench.git" --upgrade
  4. Install BigCodeBench

    main

    To use BigCodeBench for evaluation, install the package via pip. It is also recommended to install flash-attn for code sample generation. If you encounter installation issues with flash-attn, consider using pre-built wheels from the Dao-AILAB releases.

    To install the nightly version (required to use bigcodebench.generate), install directly from the GitHub repository.

    # Standard installation
    pip install bigcodebench --upgrade
    
    # Recommended for generating code samples
    pip install packaging ninja
    pip install flash-attn --no-build-isolation
    
    # Install nightly version to use bigcodebench.generate
    pip install "git+https://github.com/bigcode-project/bigcodebench.git" --upgrade
  5. Run Local Evaluation using Docker

    main

    To evaluate code samples safely in an isolated environment, use the bigcodebench/bigcodebench-evaluate:latest Docker image. It is recommended to mount your current directory to the container.

    Key Docker Flags for Resource Management:

    • --max-as-limit XXX: Change the RAM address space limit (in MB, default 30 GB).
    • --max-data-limit XXX: Change the RAM data segment limit (in MB, default 30 GB).
    • --max-stack-limit XXX: Change the RAM stack limit (in MB, default 10 MB).
    • --min-time-limit XXX: Increase the execution time limit (in seconds, default 240 seconds).

    Usage Examples:

    Standard evaluation:

    docker run -v $(pwd):/app bigcodebench/bigcodebench-evaluate:latest --execution local --split [complete|instruct] --subset [full|hard] --samples samples-sanitized-calibrated.jsonl

    Check ground truths only:

    docker run -v $(pwd):/app bigcodebench/bigcodebench-evaluate:latest --execution local --split [complete|instruct] --subset [full|hard] --samples samples-sanitized-calibrated.jsonl --check-gt-only
  6. Analyze results (Elo Rating and Task Solve Rate)

    main

    BigCodeBench provides a script to replicate performance analysis, including Elo Rating and Task Solve Rate.

    Steps to run analysis:

    1. Place all samples_eval_results.json files into a folder named results.
    2. Ensure the results folder is in the same directory as the analysis script.
    3. Run the script:
    cd analysis
    python get_results.py
  7. Generate code samples using Docker

    main

    You can use pre-built Docker images to generate code samples, which is useful for managing GPU/CPU environments and authentication.

    For GPUs:

    docker run --gpus '"device=$CUDA_VISIBLE_DEVICES"' -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest \
        --model [model_name] \\ 
        --split [complete|instruct] \\ 
        --subset [full|hard] \\ 
        [--greedy] \\ 
        --bs [bs] \\ 
        --temperature [temp] \\ 
        --n_samples [n_samples] \\ 
        --resume \\ 
        --backend [vllm|openai|mistral|anthropic|google|hf] \\ 
        --tp [TENSOR_PARALLEL_SIZE]

    For CPUs:

    docker run -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest \\ 
        --model [model_name] \\ 
        --split [complete|instruct] \\ 
        --subset [full|hard] \\ 
        [--greedy] \\ 
        --bs [bs] \\ 
        --temperature [temp] \\ 
        --n_samples [n_samples] \\ 
        --resume \\ 
        --backend [vllm|hf|openai|mistral|anthropic|google] \\ 
        --tp [TENSOR_PARALLEL_SIZE]

    Authentication: To use gated/private models or paid APIs, pass the required credentials as environment variables:

    • HuggingFace: -e HUGGING_FACE_HUB_TOKEN=$token
    • OpenAI: -e OPENAI_API_KEY=$OPENAI_API_KEY
    • Anthropic: -e ANTHROPIC_KEY=$ANTHROPIC_KEY
    • Mistral: -e MISTRAL_KEY=$MISTRAL_KEY
    • Google: -e GOOGLE_API_KEY=$OPENAI_API_KEY
    # Example for GPU with authentication
    docker run -e OPENAI_API_KEY=$OPENAI_API_KEY --gpus '"device=$CUDA_VISIBLE_DEVICES"' -v $(pwd):/app -t bigcodebench/bigcodebench-generate:latest \
        --model [model_name] \\ 
        --split [complete|instruct] \\ 
        --subset [full|hard] \\ 
        --backend openai
  8. Run Local Evaluation via CLI

    main

    If you choose to run evaluation directly on your host machine (not recommended due to security risks), you must first install the evaluation dependencies in an isolated environment:

    pip install -r https://raw.githubusercontent.com/bigcode-project/bigcodebench/main/Requirements/requirements-eval.txt

    CLI Commands:

    Standard evaluation:

    bigcodebench.evaluate --execution local --split [complete|instruct] --subset [full|hard] --samples samples-sanitized-calibrated.jsonl

    Evaluation without ground truth check:

    bigcodebench.evaluate --execution local --split [complete|instruct] --subset [full|hard] --samples samples-sanitized-calibrated.jsonl --no-gt

    Save pass rate to a file:

    bigcodebench.evaluate --execution local --split [complete|instruct] --subset [full|hard] --samples samples-sanitized-calibrated.jsonl --save_pass_rate

    Cleanup: After evaluation, it is strongly recommended to clean up processes and temporary files:

    pids=$(ps -u $(id -u) -o pid,comm | grep 'bigcodebench' | awk '{print $1}'); if [ -n "$pids" ]; then echo $pids | xargs -r kill; fi;
    rm -rf /tmp/*
    pip install -r https://raw.githubusercontent.com/bigcode-project/bigcodebench/main/Requirements/requirements-eval.txt
    
    bigcodebench.evaluate --execution local --split [complete|instruct] --subset [full|hard] --samples samples-sanitized-calibrated.jsonl
  9. Configure environment variables for remote evaluation

    main

    To use specific model backends for evaluation, you must set the corresponding API keys in your environment variables.

    BackendEnvironment Variable
    E2BE2B_API_KEY
    OpenAIOPENAI_API_KEY
    AnthropicANTHROPIC_API_KEY
    MistralMISTRAL_API_KEY
    GoogleGOOGLE_API_KEY
    Hugging FaceHF_INFERENCE_API_KEY
    export E2B_API_KEY=<your_e2b_api_key>
    export OPENAI_API_KEY=<your_openai_api_key>
    export ANTHROPIC_API_KEY=<your_anthropic_api_key>
    export MISTRAL_API_KEY=<your_mistral_api_key>
    export GOOGLE_API_KEY=<your_google_api_key>
    export HF_INFERENCE_API_KEY=<your_hf_api_key>
  10. Troubleshoot common evaluation issues

    main

    Memory/Import Errors

    If you encounter ImportError: ... failed to map segment from shared object (specifically related to matplotlib), this is likely due to the Docker container's memory limit. Increase the container's memory limit using the Docker flags mentioned in the Docker guide.

    Tokenizer Issues

    If you notice unexpected behavior due to Hugging Face tokenizer updates, try using the --tokenizer_legacy flag during generation.

    Network/Proxy Issues

    If you are behind a proxy and cannot access the internet, use Remote Evaluation instead of local evaluation to ensure accurate results.

    Performance/Timeout

    • LLM solutions are marked as failed on timeout or OOM (Out of Memory).
    • Dynamic timeouts are set based on the ground-truth solution's runtime.
    • Avoid over-stressing the machine (e.g., using --parallel 64 on a 4-core machine) to prevent false timeouts.
  11. Inspect failed samples

    main

    To understand why certain samples failed, use the bigcodebench.inspect command. This will analyze the evaluation results and save the inspection details to an inspect/ directory.

    Inspect results:

    bigcodebench.inspect --eval_results sample-sanitized-calibrated_eval_results.json --split complete --subset hard

    Re-run inspection in place:

    bigcodebench.inspect --eval_results sample-sanitized-calibrated_eval_results.json --split complete --subset hard --in_place
  12. Reference: bigcodebench.evaluate CLI arguments

    main

    The bigcodebench.evaluate command accepts the following arguments:

    • --model: The model identifier (e.g., meta-llama/Meta-Llama-3.1-8B-Instruct).
    • --execution: The execution environment. Options: [e2b|gradio|local].
    • --split: The task split. Options: [complete|instruct].
    • --subset: The task subset. Options: [full|hard].
    • --backend: The model provider/backend. Options: [vllm|openai|anthropic|google|mistral|hf|hf-inference].
    • --bs: Batch size (use 1 for more deterministic greedy decoding).
    • --direct_completion: Use this for base models that have a tokenizer.chat_template to avoid chat-mode evaluation.