Skip to content

fix: compute test metrics once over the complete test set - #3

Merged
aaronwtr merged 7 commits into
mainfrom
fix/test-metrics-full-set
Oct 16, 2026
Merged

aaronwtr merged 7 commits into
mainfrom
fix/test-metrics-full-set

Conversation

@aaronwtr

@aaronwtr aaronwtr commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

What changes

  • varformer/training/lightning_module.py: the test branch of _log no longer logs one value per batch. It stores probabilities, calls and labels in fp32 for each test source. on_test_epoch_end computes accuracy, AUROC, Spearman, recall, precision, F1 and AUPRC once over the complete test set and logs them under the same names (test_<metric>_<source>).
  • Varformer.evaluate() therefore returns metrics over the complete test set.
  • The training Spearman stays a per-batch value and is marked as monitoring only.
  • Comments in lightning_module.py and data/loaders.py are shortened to describe the current behaviour.

Behaviour change

Before this change, each test metric was the batch-size-weighted mean of per-batch values, computed on the precision of the model output. The values of test_* metrics change for test sets that are larger than one batch.

Tests

  • New test: test_test_metrics_are_computed_once_over_the_complete_test_set.
  • pytest on the tracked tests: 83 passed, 1 skipped. ruff check passes on the changed files.

Second commit: genetic constraint is not a default model input

  • gc_exclude_features now defaults to ["geneticConstraint"] (varformer/config.py and both default.yml files). The paper selects the benchmark negatives by this feature, so the models in the paper do not use it as an input. The benchmark construction still reads the value as metadata.
  • Varformer.from_pretrained and from_checkpoint read gc_exclude_features from the checkpoint. Checkpoints that were trained with the feature therefore still load. A checkpoint that was saved before the option existed loads with all features.
  • README.md: the model section and the variant head section state which gene features the paper models use.

Behaviour change

A new training run has nine Open Targets features instead of ten. Pass config_overrides={"gc_exclude_features": []} to train with all ten.

Tests

  • New tests: test_genetic_constraint_is_not_a_default_model_input and test_saved_gc_exclusions.
  • pytest on the tracked tests: 85 passed, 1 skipped. ruff check passes on the changed files.

Merge of main

main is merged into this branch (e5672d5), so the branch includes the removal of scores/gene_scores.tsv.gz (5f6bbc6).

Third commit: the paper settings are the defaults

varformer/config.py and both default.yml files now use the settings of the paper models:

Setting Before Now
precision 16-mixed 32-true
variant_head False True
variant_loss_weight 0.0 0.1
wandb True False

The other defaults already matched the training settings in the paper (batch size 128, 100 epochs, AdamW, weight decay 3e-4, cosine annealing with warm restarts every 200 steps between 1e-4 and 1e-5, gradient clipping at 1.0, maximum norm 20 for the mutation embeddings, dropout 0.3).

Behaviour change

Training with the defaults now needs variant_labels_path (or the VARFORMER_VARIANT_LABELS environment variable). Without it, training stops with the existing error "set variant_labels_path". To train without the variant head, pass config_overrides={"variant_head": False, "variant_loss_weight": 0.0}.

Tests

  • New test: test_defaults_match_the_paper_models.

Fourth commit: no Hugging Face release in the README

Trained weights are not distributed. README.md:

  • removes the Hugging Face badge and the "Pending" line about checkpoints on the Hub;
  • renames "Available checkpoints" to "Checkpoints" and states that from_pretrained loads local checkpoints;
  • describes the new defaults in the variant head section and adds variant_labels_path to the training example;
  • removes "paper-era" wording and the sentence about the public release of checkpoints.

pytest on the tracked tests: 86 passed, 1 skipped. ruff check varformer tests passes.

Test metrics were logged as the mean of per-batch values. They are now accumulated in fp32 and computed once per test source in on_test_epoch_end, so Varformer.evaluate() returns metrics over the complete test set.

Also shorten code comments to describe the current behaviour.
The benchmark negatives are selected by geneticConstraint, so the feature
is no longer a model input by default. Checkpoint loading reads the
setting from the checkpoint, so models trained with the feature still load.
The paper models train with 32-bit precision and the variant head
(loss weight 0.1), without Weights & Biases logging. Training with the
defaults now needs variant_labels_path.
Trained weights are not distributed. The README now describes local
checkpoints and the new defaults.
Comment thread varformer/config.py Outdated
use_pvc: bool = True
shuffle_pvc_across_genes: bool = False
gc_exclude_features: list[str] = Field(default_factory=list)
gc_exclude_features: list[str] = Field(default_factory=lambda: ["geneticConstraint"])

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we hardcode geneticConstraint here? we pass the features to exclude in the config right?

Comment thread README.md
[![CI](https://github.com/aaronwtr/Varformer/actions/workflows/ci.yml/badge.svg)](https://github.com/aaronwtr/Varformer/actions/workflows/ci.yml)
[![Paper](https://img.shields.io/badge/paper-preprint%20pending-lightgrey.svg)](#)
[![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-checkpoints%20pending-yellow)](#)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change title to also include "...drug target and variant prioritization"

Comment thread README.md
The paper trains separate models for four variant catalogues: African/African-American (AFR), Admixed American (AMR), Non-Finnish European (NFE), and South Asian (SAS, via the Genes & Health British Bangladeshi and Pakistani cohort).

<p align="center">
<img src="docs/figures/overview_figure.png" alt="Varformer architecture overview" width="780"/>

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to update the overview figure in accordance with the latest version

Comment thread README.md Outdated

To train without the variant head, set `"variant_head": False` and `"variant_loss_weight": 0.0`.

The gene-level results in the paper come from models with these settings and the default gene features. The variant scores used in the Genes & Health analyses come from SAS models that were trained with the same settings and with `geneticConstraint` as an additional gene input (`"gc_exclude_features": []`). `from_pretrained` and `from_checkpoint` read this setting from the checkpoint.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this please

default.yml is the source of the defaults; the Python model no longer
repeats the feature name.
…w figure

Remove the README paragraph on the gene-level and Genes & Health models.

@aaronwtr aaronwtr left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge

@aaronwtr
aaronwtr merged commit 5355311 into main Oct 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant