codelion / optillm-modernbert-large

huggingface.co
Total runs: 7
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: February 16 2025

Introduction of optillm-modernbert-large

Model Details of optillm-modernbert-large

How to use?

This model is used in optillm to route between the various approaches based on the prompt.

To use the model with optillm you can just prepend router to the model name. E.g. if we set router-gpt-4o-mini as the model, it will use the gpt-4o-mini as the base model.

Otherwise, refer to the code in router-plugin to see how to use this model for classification.

This model is based on ModernBERT-large and better than the previous router model that was based on bert-large-uncased .

Router results on AIME 2024 pass@1
Model Score
router-gpt4o-mini with codelion/optillm-modernbert-large 13.33
router-gpt4o-mini with codelion/optillm-bert-uncased 6.67
gpt4o-mini 3.33

Usage

To use the model directly you will need to use our OptILMClassifier class as we added additional layers to the base model. The additional effort_encoder is used to take into account the number of tokens a given approach consumes. Also, note the mapping of the returned index to the APPROACHES list as shown below.

import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer, AutoConfig
from huggingface_hub import hf_hub_download
from safetensors import safe_open
from safetensors.torch import load_model
from transformers import AutoTokenizer, AutoModel

# Constants
MAX_LENGTH = 1024
APPROACHES = ["none", "mcts", "bon", "moa", "rto", "z3", "self_consistency", "pvg", "rstar", "cot_reflection", "plansearch", "leap", "re2"]
BASE_MODEL = "answerdotai/ModernBERT-large"
OPTILLM_MODEL_NAME = "codelion/optillm-modernbert-large"

class OptILMClassifier(nn.Module):
    def __init__(self, base_model, num_labels):
        super().__init__()
        self.base_model = base_model
        self.effort_encoder = nn.Sequential(
            nn.Linear(1, 64),
            nn.ReLU(),
            nn.Linear(64, 64),
            nn.ReLU()
        )
        self.classifier = nn.Linear(base_model.config.hidden_size + 64, num_labels)

    def forward(self, input_ids, attention_mask, effort):
        outputs = self.base_model(input_ids=input_ids, attention_mask=attention_mask)
        pooled_output = outputs.last_hidden_state[:, 0]  # Shape: (batch_size, hidden_size)
        effort_encoded = self.effort_encoder(effort.unsqueeze(1))  # Shape: (batch_size, 64)
        combined_input = torch.cat((pooled_output, effort_encoded), dim=1)
        logits = self.classifier(combined_input)
        return logits

def load_optillm_model():
    device = torch.device("mps" if torch.backends.mps.is_available() else "cuda" if torch.cuda.is_available() else "cpu")
    # Load the base model
    base_model = AutoModel.from_pretrained(BASE_MODEL)
    # Create the OptILMClassifier
    model = OptILMClassifier(base_model, num_labels=len(APPROACHES))  
    model.to(device)
    # Download the safetensors file
    safetensors_path = hf_hub_download(repo_id=OPTILLM_MODEL_NAME, filename="model.safetensors")
    # Load the state dict from the safetensors file
    load_model(model, safetensors_path)

    tokenizer = AutoTokenizer.from_pretrained(OPTILLM_MODEL_NAME)
    return model, tokenizer, device

def preprocess_input(tokenizer, system_prompt, initial_query):
    combined_input = f"{system_prompt}\n\nUser: {initial_query}"
    encoding = tokenizer.encode_plus(
        combined_input,
        add_special_tokens=True,
        max_length=MAX_LENGTH,
        padding='max_length',
        truncation=True,
        return_attention_mask=True,
        return_tensors='pt'
    )
    return encoding['input_ids'], encoding['attention_mask']

def predict_approach(model, input_ids, attention_mask, device, effort=0.7):
    model.eval()
    with torch.no_grad():
        input_ids = input_ids.to(device)
        attention_mask = attention_mask.to(device)
        effort_tensor = torch.tensor([effort], dtype=torch.float).to(device)
        
        logits = model(input_ids, attention_mask=attention_mask, effort=effort_tensor)
        probabilities = F.softmax(logits, dim=1)
        predicted_approach_index = torch.argmax(probabilities, dim=1).item()
        confidence = probabilities[0][predicted_approach_index].item()
    
    return APPROACHES[predicted_approach_index], confidence

You can now use the predict_approach method to get the predicted approach as follows:

# Load the trained model
router_model, tokenizer, device = load_optillm_model()

# Preprocess the input
input_ids, attention_mask = preprocess_input(tokenizer, system_prompt, initial_query)

# Predict the best approach
predicted_approach, _ = predict_approach(router_model, input_ids, attention_mask, device)

print(f"Router predicted approach: {predicted_approach}")

Runs of codelion optillm-modernbert-large on huggingface.co

7
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About optillm-modernbert-large huggingface.co Model

More optillm-modernbert-large license Visit here:

https://choosealicense.com/licenses/apache-2.0

optillm-modernbert-large huggingface.co

optillm-modernbert-large huggingface.co is an AI model on huggingface.co that provides optillm-modernbert-large's model effect (), which can be used instantly with this codelion optillm-modernbert-large model. huggingface.co supports a free trial of the optillm-modernbert-large model, and also provides paid use of the optillm-modernbert-large. Support call optillm-modernbert-large model through api, including Node.js, Python, http.

optillm-modernbert-large huggingface.co Url

https://huggingface.co/codelion/optillm-modernbert-large

codelion optillm-modernbert-large online free

optillm-modernbert-large huggingface.co is an online trial and call api platform, which integrates optillm-modernbert-large's modeling effects, including api services, and provides a free online trial of optillm-modernbert-large, you can try optillm-modernbert-large online for free by clicking the link below.

codelion optillm-modernbert-large online free url in huggingface.co:

https://huggingface.co/codelion/optillm-modernbert-large

optillm-modernbert-large install

optillm-modernbert-large is an open source model from GitHub that offers a free installation service, and any user can find optillm-modernbert-large on GitHub to install. At the same time, huggingface.co provides the effect of optillm-modernbert-large install, users can directly use optillm-modernbert-large installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

optillm-modernbert-large install url in huggingface.co:

https://huggingface.co/codelion/optillm-modernbert-large

Url of optillm-modernbert-large

optillm-modernbert-large huggingface.co Url

Provider of optillm-modernbert-large huggingface.co

codelion
ORGANIZATIONS

Other API from codelion

huggingface.co

Total runs: 256
Run Growth: -29
Growth Rate: -11.37%
Updated:December 30 2025
huggingface.co

Total runs: 197
Run Growth: 186
Growth Rate: 94.42%
Updated:March 08 2026
huggingface.co

Total runs: 170
Run Growth: -24
Growth Rate: -14.12%
Updated:November 03 2025
huggingface.co

Total runs: 109
Run Growth: 93
Growth Rate: 85.32%
Updated:January 23 2026
huggingface.co

Total runs: 42
Run Growth: 0
Growth Rate: 0.00%
Updated:November 26 2024
huggingface.co

Total runs: 0
Run Growth: 0
Growth Rate: 0.00%
Updated:October 15 2024