This repository was archived by the owner on Aug 30, 2025. It is now read-only.
Fix for issue with reading ModernBERT jailbreak classifier model - #54
Closed
srampal wants to merge 0 commit into
Closed
Fix for issue with reading ModernBERT jailbreak classifier model#54srampal wants to merge 0 commit into
srampal wants to merge 0 commit into
Conversation
srampal
marked this pull request as draft
August 21, 2025 10:59
Member
|
Thanks for the testing. It looks the regression was introduced in this commit Per this thread, torhc.compile adds new tensor names. |
rootfs
reviewed
Aug 21, 2025
|
|
||
| // Check if the _orig_mod prefix version exists | ||
| // We'll use the known shape for ModernBERT embeddings | ||
| if let Ok(_) = self.inner.get((50368, 768), "_orig_mod.model.embeddings.tok_embeddings.weight") { |
Member
|
@srampal can you reduce the scope of this patch? A simple change is to prepends match FixedModernBertForTokenClassification::load(vb.clone(), &config) {
Ok(model) => ModernBertModel::Token(model),
Err(_) => {
// Try with _orig_mod prefix (torch.compile models)
ModernBertModel::Token(FixedModernBertForTokenClassification::load(vb.pp("_orig_mod"), &config)?)
}
} |
Contributor
Author
|
Reverted this fix .. working on an alternate fix via |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The issue with the jailbreak classifier has been successfully resolved. Here's what was causing the problem and
how it was fixed:
Root Cause
The jailbreak classifier model was saved with PyTorch's torch.compile() or similar compilation process, which
added the _orig_mod. prefix to all tensor names. For example:
Solution
The fix implements a PrefixedVarBuilder wrapper that:
Key Changes
/home/ubuntu/repos/github.com/srampal/semantic_router/candle-binding/src/modernbert.rs
Result
✅ All three classifiers now initialize successfully:
✅ Server starts successfully: The router now starts on port 50051 and all components are functional.
The fix is backward-compatible and will work with both types of models (with and without the _orig_mod.
prefix), ensuring robust model loading for future updates.