Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for finetune guard classifier #325

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

VibhuJawa
Copy link
Collaborator

@VibhuJawa VibhuJawa commented Oct 25, 2024

This PR adds support for FineTuneGuard Model

@VibhuJawa VibhuJawa changed the title Add support for fine-tune classifier Add support for finetune guard classifier Oct 29, 2024
@VibhuJawa VibhuJawa marked this pull request as ready for review November 14, 2024 10:23
- Demonstrated strong zero-shot detection capabilities on novel attacks
- Particularly effective at identifying trigger patterns in partially poisoned datasets

Dataset Format:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: Emphasize more about english

Copy link
Collaborator

@sarahyurick sarahyurick left a comment

Choose a reason for hiding this comment

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

Added a few typo fixes but looks good so far!

When you get a chance can you add it to the examples/ and nemo_curator/scripts/ folders? And to the documentation? You should be able to reference #361 which has all the files that should be created/updated.

class AegisModel(nn.Module):
def __init__(
self,
pretrained_model_name_or_path: str,
peft_model_name_or_path: str,
dtype: torch.dtype,
token: str,
token: Optional[Union[str, bool]],
add_fintune_gaurd: bool = False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
add_fintune_gaurd: bool = False,
add_finetune_guard: bool = False,

):
super().__init__()
base_model = AutoModelForCausalLM.from_pretrained(
pretrained_model_name_or_path, torch_dtype=dtype, token=token
)
self.model = PeftModel.from_pretrained(base_model, peft_model_name_or_path)
self.autocast = autocast
self.add_fintune_gaurd = add_fintune_gaurd
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.add_fintune_gaurd = add_fintune_gaurd
self.add_finetune_guard = add_finetune_guard

):
super().__init__()
base_model = AutoModelForCausalLM.from_pretrained(
pretrained_model_name_or_path, torch_dtype=dtype, token=token
)
self.model = PeftModel.from_pretrained(base_model, peft_model_name_or_path)
self.autocast = autocast
self.add_fintune_gaurd = add_fintune_gaurd
if self.add_fintune_gaurd:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if self.add_fintune_gaurd:
if self.add_finetune_guard:

pad_token_id=0,
)
def _forward(self, batch):
if self.add_fintune_gaurd:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if self.add_fintune_gaurd:
if self.add_finetune_guard:

if self.config.add_finetune_guard:
if self.config.finetune_guard_path is None:
raise ValueError(
"finetune_guard_path must be provided if add_fine_guard is True"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"finetune_guard_path must be provided if add_fine_guard is True"
"finetune_guard_path must be provided if add_finetune_guard is True"

peft_model_name_or_path=self.config.peft_model_name_or_path,
dtype=self.config.dtype,
token=self.config.token,
add_fintune_gaurd=self.config.add_finetune_guard,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
add_fintune_gaurd=self.config.add_finetune_guard,
add_finetune_guard=self.config.add_finetune_guard,

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.

2 participants