Skip to content

Fix bedroc_score through the Metric wrapper - #5192

Open
barlowa124 wants to merge 1 commit into
deepchem:masterfrom
barlowa124:bedroc-onehot-labels
Open

barlowa124 wants to merge 1 commit into
deepchem:masterfrom
barlowa124:bedroc-onehot-labels

Conversation

@barlowa124

@barlowa124 barlowa124 commented Oct 1, 2026 •

Copy link
Copy Markdown

Description

LinearAttention built its projection matrices inside
build_from_inputs, which runs on the first forward call. TorchModel
has already moved the module to its device by then, so weights were
created on CPU and the first non-CPU forward failed. It also meant
model.parameters() was empty at init time, so an optimizer built
before the first batch never saw the projections.

The projections are now created in __init__ when the input
dimensions are known, with the lazy path retained for deferred shapes.
Weights therefore sit in parameters() immediately and follow
.to(device) like any other layer.

test_linear_attention_pytorch.py gains a device-placement test.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
    • Run yapf -i <modified file> and check no errors (yapf version must be 0.32.0)
    • Run mypy -p deepchem and check no errors (mypy run on modified files, --follow-imports=skip)
    • Run flake8 <modified file> --count and check no errors
    • Run python -m doctest <modified file> and check no errors
  • I have performed a self-review of my own code

Metric defaults classification metrics like bedroc_score to the
'threshold-one-hot' handling mode, which thresholds predictions into
hard labels and leaves labels one-hot encoded. Inside bedroc_score,
flatten() on the (N, 2) label array produced 2N values that zip()
silently truncated against the N prediction scores, destroying the
ranking: perfect and reversed rankings both scored ~0.5.

Bedroc_score is a ranking metric and needs continuous scores, so it
now defaults to 'direct' handling like roc_auc_score. Bedroc_score
also takes the positive-class column when handed 2-D one-hot labels
and asserts label/score shape agreement so truncation fails loudly
instead of silently misaligning.

Fixes deepchem#5191
@barlowa124
barlowa124 force-pushed the bedroc-onehot-labels branch from 2f3c271 to eb4ab0a Compare October 1, 2026 20:44
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