Skip to main content
This page walks through the steps for performing downstream validation on the Cerebras Wafer-Scale cluster using BigCode’s Evaluation Harness (BCEH). BCEH is a framework for evaluating code generation models. While you can configure BCEH as part of your training (see Pretraining with Downstream Validation from the Cerebras Model Zoo. The examples in this guide will perform downstream validation on LLaMA3 8B. By the end of this guide, you will be able to leverage the BCEH framework to perform standalone downstream validation on your models on CS-X.

Prerequisites

Please ensure that you have installed the Cerebras Model Zoo package by going through the installation guide. Note that BCEH version tested and packaged in the Cerebras Model Zoo is the pinned to this commit. Please also read through the Trainer Overview and Trainer Configuration Overview), as these guides will help understand how we configure running BCEH standalone.
This guide configures the downstream BCEH run using V2 YAML. While release 2.3 includes support for legacy V1 YAML, please convert the configuration to V2 using convert_legacy_params_to_trainer_params from the script src/cerebras/modelzoo/trainer/utils.py.

Configure the Run

This section covers the required steps for setting up an BCEH run to perform standalone downstream validation on code generation tasks. In particular, you will need to write a YAML configuration file to configure an instance of the Trainer callback. The example in this section configure code evaluation on the bigcode eval harness task humaneval using a single CSX. If you aren’t interested in seeing the break down of the configuration, feel free to skip ahead to the Putting it All Together section to see the full YAML configuration.

Configure the CSX Backend

The first step is to specify the CSX backend and resources required for the run. Please create a YAML configuration file with the following cluster config:
This example uses a single CSX, but you can readily update num_csx to run BCEH on multiple CSXs for improved performance.

Configure the Model

Starting from release 2.4.0, specifying model_name is now deprecated and replaced with name.
Next, please add the following model configuration in the YAML for LLaMA3 8B with 8K context length:
To run downstream validation harness, you must specify the name setting in the model configuration. Valid names corresponding to the supported models include:
  • btlm
  • bloom
  • gpt2
  • gptj
  • falcon
  • gpt3
  • gpt-neox
  • llama
  • mistral
  • mpt
  • jais
  • santacoder
  • starcoder

Configure the BCEH Callback

BCEH is implemented as an extension to the Trainer callback. Add the following configuration for the BigCodeEvalHarness callback.
The bigcode_args section exposes the following settings configure the BCEH run: You can either specify the settings here or pass them via CLI arguments to the standalone BCEH run script. The callback configuration accepts dataloader settings that you must specify in the YAML to set up input data preprocessing for the run: Additionally, you may optionally specify the following, CSX-specific eval harness setting:
  • keep_data_dir: Use this to preserve the preprocessed eval harness task data samples, i.e. the directory specified under data_dir. Defaults to False, i.e. data samples are deleted after the run.

(Optional) Configure HuggingFace (HF) Cache Directory

BCEH utilizes HF’s APIs to download task data and other configurations. This data is by default cached under $HOME/.cache/huggingface. However, you may choose to specify a different directory for this cached data via the HFCacheDir callback:

Configure Generation Settings

All BCEH tasks are generative (autoregressive) in nature. In order to run generative inference on CSX, you must specify the following inference settings in the model config of YAML file:
  • start_token - ID of the special token that indicates where to start inferring for each sample, as described above. You may specify a list of token IDs instead of a single ID. If you do, the model will start inference at the first token that matches any one of the provided IDs. The model will pad inferred predictions with the first ID in the list.
  • stop_sequences - List of sequences (each one being a list of token IDs). If any one of these sequences is emitted by the model, inference will stop for that sample. For example, suppose you would like to stop inferring after either a newline character (e.g. token id 1), or a combination of a period (e.g. token id 2) followed by a space (e.g. token id 3). In this case, set stop_sequences to [[1], [2, 3]]. To stop inferring after seeing a newline character only, set stop_sequences to [[1]]. To disable this feature, set stop_sequences to an empty list []. Additionally, the following optional parameters may be set:
  • max_tokens - Maximum tokens to infer for each sample.
  • loop_dim - Indicates the sequence dimension in the input and output data. Default value is 1. If set to 0, indicates that both input and output data is transposed (i.e. sequence X samples instead of samples X sequence).
Please update the YAML file to add these inference settings:
  1. For start_token, it is ideal to choose a value that’s not going to be generated by the model, i.e. vocab_size in the example above.
  2. The code generation task itself defines stop_sequences. For instance, see the specification of stop tokens for humaneval . The flow will internally override the stop_sequences config with the value from the task, so you can also specify an arbitrary, valid value in the YAML as shown above.

Putting it All Together

Here’s what the full YAML configuration looks like once you follow this guide for configuring the individual pieces:

Running BCEH on CS-X

Once the YAML configuration is complete, use the Model Zoo CLI to run standalone BCEH:
  1. We support only a subset of BigCode’s command line interface (CLI) arguments as listed above.
  2. You may also specify these arguments in the YAML under the bigcode_args key of the BigCodeEvalHarness configuration, but please note that the CLI setting will override the settings in the YAML.
  3. The params argument is required. Use it to specify the path to the YAML configuration file.
  4. Use the --checkpoint_path CLI argument to specify the path to the checkpoint file to load model weights from. If a checkpoint path is not provided, we support checkpoint autoloading in this flow such that the latest checkpoint file will be picked up from the specified model_dir.

Code Generation on CSX

We only support BCEH’s generation-only flow to generate model outputs and dump these generations to JSON files. Use the --save_generations_path argument to specify the path for saving the generations. If no absolute path is provided, the generations will be dumped inside of model_dir. The code execution and evaluation flow is run on CPU, preferably in a sandboxed environment, using these dumped model outputs.

Example

Let’s assume that the YAML configuration file above is written to ./llama3_8B_bceh.yaml. Then, to run code generation for task humaneval set up a bash script as follows:
By default, the model will perform greedy sampling of the inferred tokens, i.e. for all of the model’s outputs, pick the token with the highest probability. In order to perform non-greedy sampling, you can pass in values for temperature, top_k or top_p sampling to either the bash script or under bigcode_args of the YAML. For example:

Code Execution and Evaluation on CPU

To obtain the final eval scores, please clone BigCode’s official repository. Some BigCode tasks, such as humaneval, require executing the model’s generated code for processing the final eval scores. Thus, for security purposes, use the instructions here to set up a containerized environment. Finally, to obtain the final eval scores, invoke the BCEH’s main script using the --load_generations_path CLI argument.

Example Output

Please make note of the path of the model’s output generations in the logs, i.e. <path_to_bigcode_model_dir>/20240627_051131/bigcode_0/generations_humaneval_1.json. Set up a bash script as follows to invoke the BCEH script:
The final code eval results will be saved in file ./evaluation_results.json are as follows:
  1. The config section of the final output JSON contains all the default values from BigCode’s CLI. Feel free to ignore this section and consider only the final eval score, i.e. "pass@1": 0.13414634146341464 above.
  2. Please ensure that --check_references is set for tasks that require code execution.
  3. Setting up a sandboxed environment to run code executions is optional.
  4. Please ensure that the --tasks argument specifies the correct task for which you produced the model’s output generations on CSX, i.e. humaneval in the example above.

Run Multiple Generative Tasks

You can run multiple tasks by configuring multiple BigCodeEvalHarness callbacks (one per task) in the YAML. For example, you may update the YAML config as such to run downstream validation on generative tasks mpbb and humaneval:

Supported Tasks

  • You may perform downstream validation on all BCEH tasks except for DS1000, since it requires Python version 3.7.10, but we support 3.8.0 in our packaged environment.

Adding New Tasks

Please refer to BigCode’s new task implementation guide here to add new tasks.

Limitations

  • You may only specify running a single generative task at a time. You should configure multiple BCEH tasks via separate callbacks, as shown above.
  • We only support the generation flow for BCEH. In order to run the code execution and evalution flow, please create a separate clone of the BCEH repository to obtain the final eval scores using the outputs generated on CSX.
  • Please turn on grad accumulation and choose a small micro batch size (between 16 to 32) under the flags configuration of the BigCodeEvalHarness callback of the YAML.

Conclusion

In summary, by following this guide you have run standalone downstream validation for the Llama3-8B model on BCEH’s task humaneval. You should now be comfortable in configuring more downstream BCEH runs on your model of choice on even more code eval tasks.

What’s next?

To run downstream validation on general eval datasets and tasks, please see check out: You can also perform downstream validation using BCEH as part of your pretraining runs with upstream validation. Check out the following guide: