Skip to content

Commit

Permalink
Use PyTorchModelHubMixin for InstructionDataGuardNet (#416)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Yurick <[email protected]>
  • Loading branch information
sarahyurick authored Dec 9, 2024
1 parent b4c67b5 commit 87d0cc7
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions nemo_curator/classifiers/aegis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import torch.nn.functional as F
from crossfit import op
from crossfit.backend.torch.hf.model import HFModel
from huggingface_hub import hf_hub_download
from huggingface_hub import PyTorchModelHubMixin
from peft import PeftModel
from safetensors.torch import load_file
from torch.nn import Dropout, Linear
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer

Expand Down Expand Up @@ -75,7 +74,7 @@ class AegisConfig:
]


class InstructionDataGuardNet(torch.nn.Module):
class InstructionDataGuardNet(torch.nn.Module, PyTorchModelHubMixin):
def __init__(self, input_dim, dropout=0.7):
super().__init__()
self.input_dim = input_dim
Expand Down Expand Up @@ -180,12 +179,14 @@ def load_model(self, device: str = "cuda"):
add_instruction_data_guard=self.config.add_instruction_data_guard,
)
if self.config.add_instruction_data_guard:
weights_path = hf_hub_download(
repo_id=self.config.instruction_data_guard_path,
filename="model.safetensors",
model.instruction_data_guard_net = (
model.instruction_data_guard_net.from_pretrained(
self.config.instruction_data_guard_path
)
)
model.instruction_data_guard_net = model.instruction_data_guard_net.to(
device
)
state_dict = load_file(weights_path)
model.instruction_data_guard_net.load_state_dict(state_dict)
model.instruction_data_guard_net.eval()

model = model.to(device)
Expand Down

0 comments on commit 87d0cc7

Please sign in to comment.