Skip to content

[fix] Honor explicit CrossEncoder activation overrides when loading - #4006

Merged
tomaarsen merged 2 commits into
huggingface:mainfrom
mottopanikeiku:fix/cross-encoder-activation-override
Sep 11, 2026
Merged

[fix] Honor explicit CrossEncoder activation overrides when loading#4006
tomaarsen merged 2 commits into
huggingface:mainfrom
mottopanikeiku:fix/cross-encoder-activation-override

Conversation

@mottopanikeiku

Copy link
Copy Markdown
Contributor

I fixed CrossEncoder loading so an explicit activation_fn takes precedence over the saved activation. A caller can now replace a custom activation even when its saved class cannot be reconstructed.

Validation on CPU:

  • The saved custom-activation reproduction fails before the fix and passes afterward.
  • tests/cross_encoder/test_model.py: 75 passed, 8 skipped.
  • Tiny BERT training, save/load, and prediction smoke checks pass.
  • Ruff, formatting, and typos hooks pass.

I used AI assistance for the implementation and regression coverage. The checks above were run through that workflow.

@tomaarsen

Copy link
Copy Markdown
Member

Hello!

Thanks for the fix and for the simplification!
I also updated predict() to check activation_fn is None, so callable overrides that evaluate to False, such as an empty nn.Sequential(), are respected. This seems like a nice improvement overall. I'll do another light review and then wait for the tests.

  • Tom Aarsen

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review comments remain, and validation and regression tests pass.

Pull request overview

Updates CrossEncoder loading to honor explicit activation overrides, including falsey callables and unresolvable saved activations.

Changes:

  • Preserves explicit activation overrides during config parsing.
  • Corrects falsey per-call activation handling.
  • Adds regression coverage for loading and prediction behavior.
File summaries
File Summary
tests/cross_encoder/test_model.py Adds activation loading and override regression tests.
sentence_transformers/cross_encoder/model.py Implements activation precedence and override handling.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tomaarsen
tomaarsen merged commit 846c343 into huggingface:main Sep 11, 2026
10 checks 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.

3 participants