Code Structure
Overview of the MedHELM benchmarking pipeline and how to extend it.
Birds-eye view
- A
Scenario(from aScenarioSpec) defines a task and dataset. It producesInstanceobjects with inputs andReferenceoutputs. - A
DataPreprocessorconverts a scenario into instances and applies augmentations fromDataAugmenterSpec. - An
Adapter(fromAdaptationSpec) turns instances intoRequestobjects for the model. - An
Executorruns requests and collectsRequestResultobjects in aScenarioState. - A
Metric(fromMetricSpec) computesStatobjects (accuracy, ROUGE, summarization scores, etc.). - A
Runnerorchestrates the above for eachRunSpec.
Class categories:
- Specifications (
RunSpec,AdapterSpec, …) — user configuration - States (
Instance,RequestResult, …) — serializable data - Controllers (
Scenario,Adapter,Metric,Runner) — implementation logic
MedHELM run specs live in src/helm/benchmark/run_specs/. Scenarios live in src/helm/benchmark/scenarios/.
Adding new scenarios
- Create
src/helm/benchmark/scenarios/your_scenario.pywith aScenariosubclass implementingget_instances(). - Each
InstanceneedsInput,Reference(s), and a split (TRAIN_SPLIT,VALID_SPLIT, orTEST_SPLIT). Mark correct references withCORRECT_TAG. - Set
name,description, andtagson the scenario class. - Choose metrics in an existing
*_metrics.pyor add a task-specific metric class. Many tasks usebasic_metrics.pyviacommon_metric_specs.py. - Add a
@run_spec_function("your_name")insrc/helm/benchmark/run_specs/medhelm_run_specs.pythat buildsScenarioSpec,AdapterSpec,MetricSpeclist, and returns aRunSpec. - Test with
medhelm-run -r your_name:model=openai/gpt2 --suite dev --max-eval-instances 10. - For leaderboard visibility, add the scenario to
src/helm/benchmark/static/schema_medhelm.yaml.
For private organization data, read from a configured local path (see private run entry configs such as run_entries_medhelm_private_stanford.conf) rather than committing restricted files.
See Adding New Scenarios for a step-by-step tutorial with MedHELM examples.
Adding new metrics
Generic metrics (reusable across tasks):
- Add a scoring function to
basic_metrics.pyorevaluate_reference_metrics.py. - Register it in the metric function mapping.
- Expose it via
common_metric_specs.pyif needed.
Task-specific metrics:
- Create
your_task_metrics.pywith a class extendingMetricfrommetric.py. - Implement
evaluate_generation()returning a list ofStatobjects.
Summarization benchmarks use summarization_metrics.py (requires pip install "medhelm[summarization]").
Data augmentations
Pass a DataAugmenterSpec with PerturbationSpec entries into RunSpec:
data_augmenter_spec = DataAugmenterSpec(
perturbation_specs=[
PerturbationSpec(
class_name="helm.benchmark.augmentations.perturbation.ExtraSpacePerturbation",
args={"num_spaces": 5},
)
],
should_perturb_references=False,
should_augment_train_instances=False,
should_include_original_train=False,
should_augment_eval_instances=True,
should_include_original_eval=True,
)
See Perturbations for available perturbations.
Multimodal MedHELM benchmarks
Image-generation scenarios (radiology, mental disorders) live under src/helm/benchmark/scenarios/image_generation/ with metrics under src/helm/benchmark/metrics/image_generation/. Install pip install "medhelm[heim]" for image-generation metrics.
Vision-language (VQA-RAD) and audio (speech disorder) scenarios have dedicated run spec modules: medical_multimodal_run_specs.py and speech_disorder_audio_run_specs.py.
Supporting new Hugging Face tokenizers
- Use the Hugging Face model name (e.g.
EleutherAI/gpt-j-6B). - Add loading logic in
HuggingFaceTokenizers.load_tokenizer. - Add a test in
test_huggingface_tokenizer.py. - Add a
WindowServicesubclass and register it inWindowServiceFactory.