Skip to content
Discussion options

You must be logged in to vote

The slowness is expected — Spearman correlation requires ranking (sorting), and sorting on GPU is inherently slower than vectorized arithmetic (which is why Pearson is fast).

Options to speed it up:

1. Compute on CPU (counterintuitive but often faster for ranking):

from torchmetrics.functional.regression import spearman_corrcoef

score = spearman_corrcoef(preds.cpu(), target.cpu())

2. Compute less frequently — epoch-only:

class MyModel(L.LightningModule):
    def __init__(self):
        super().__init__()
        self.spearman = SpearmanCorrCoef()

    def validation_step(self, batch, batch_idx):
        self.spearman.update(preds, target)  # just update, don't compute

    def on_validat…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants