Downloads · 30 days
0
PoHao/opt2.7-fc1-predictor
opt2.7-fc1-predictor is a machine learning model from PoHao. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Small predictor models for facebook/opt-2.7b. Each predictor looks at the input to one decoder layer's fc1 and predicts which output neurons will be activated, so those neurons can be skipped during inference (sparse…
Downloads · 30 days
0
Access
Public
Updated Aug 26, 2026
Repo size
839 MB
Likes
0
Public
Click a slice to open those files.
.pt839 MB · 100%
From the Hugging Face model README
Small predictor models for facebook/opt-2.7b. Each predictor looks at the input to one decoder layer's fc1 and predicts which output neurons will be activated, so those neurons can be skipped during inference (sparse inference).
One predictor per decoder layer (32 total): model_0.pt ... model_31.pt.
Pairs with the fine-tuned model at PoHao/opt2.7-predictor-guided-sft.
import torch.nn as nn
class PredictorMLP(nn.Module):
def __init__(self, input_dim, output_dim, hidden_dim=512):
super().__init__()
self.fc1 = nn.Linear(input_dim, hidden_dim, bias=False)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(hidden_dim, output_dim, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
x = self.sigmoid(x)
return x
input_dim: OPT-2.7B hidden sizeoutput_dim: OPT-2.7B fc1 output sizehidden_dim: 512Output is a value in [0, 1] per neuron; threshold (default 0.5) to get a binary mask.
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("facebook/opt-2.7b")
input_dim = base_model.model.decoder.layers[0].fc1.in_features
output_dim = base_model.model.decoder.layers[0].fc1.out_features
def load_predictor(layer_idx, repo_id="PoHao/opt2.7-fc1-predictor", hidden_dim=512, device="cpu"):
path = hf_hub_download(repo_id=repo_id, filename=f"model_{layer_idx}.pt")
predictor = PredictorMLP(input_dim, output_dim, hidden_dim).to(device)
predictor.load_state_dict(torch.load(path, map_location=device))
predictor.eval()
return predictor
predictor_layer0 = load_predictor(0)
threshold = 0.5
with torch.no_grad():
prob = predictor_layer0(hidden_state) # hidden_state: input to layer 0's fc1
mask = (prob > threshold).float()
fc1_output = fc1_output * mask