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

enable tokenizer customization in HFDetector #855

Merged

Conversation

jmartin-tech
Copy link
Collaborator

Commonize parameters utilized in HFDetector, existing detectors currently use common arguments.

  • promote tokenizer_kwargs as DEFAULT_PARAM of parent class
  • remove __init()__ overrides not longer needed

Expands on earlier exposure of model selection for HFDetectors in #810

These values seem independent from hf_args used to load the model.

Some additional code review suggests that misleading.MustContradictNLI does not actually consume these values since it overrides detect() with a custom method. Should this PR be expanded to consume values from self.tokenizer_kwargs for max_length and truncation? The values are currently hardcoded in detect() as local values. It does not look like padding is ever consumed in misleading.MustContradictNLI and could be suppressed with instance defaults for that class.

* promote `tokenizer_kwargs` as DEFAULT_PARAM of parent class
* remove `__init()__` overrides not longer needed

Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {"hf_args": {"device": "cpu"}}
DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {
"hf_args": {"device": "cpu"},
"tokenizer_kwargs": {"padding": True, "truncation": True, "max_length": 512},
Copy link
Owner

Choose a reason for hiding this comment

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

I suspect max_length might want to come from model ctx_len - but this is out of scope for this PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd actually exclude max_length since it's very specifically model/config dependent and this might override defaults. If the model's max_length is, for some reason <512, this default could throw errors.

Copy link
Owner

Choose a reason for hiding this comment

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

On the other hand, running without a length cap also risks breaking models (this happens regularly on e.g. some NVCF instances). I think it's OK to offer a default control over this with a mild value that balances both being too high and too low. 512 seems reasonable (bearing in mind that detectors tend to be smaller models - this is a side effect of garak needing to run them at scale, but sometimes having primary compute allocated to the target model, reducing detector resources).

erickgalinkin
erickgalinkin previously approved these changes Aug 28, 2024
Copy link
Collaborator

@erickgalinkin erickgalinkin left a comment

Choose a reason for hiding this comment

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

LGTM

DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {"hf_args": {"device": "cpu"}}
DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {
"hf_args": {"device": "cpu"},
"tokenizer_kwargs": {"padding": True, "truncation": True, "max_length": 512},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd actually exclude max_length since it's very specifically model/config dependent and this might override defaults. If the model's max_length is, for some reason <512, this default could throw errors.

garak/detectors/base.py Outdated Show resolved Hide resolved
@erickgalinkin erickgalinkin dismissed their stale review August 28, 2024 15:19

Did not intend to approve

Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
@jmartin-tech jmartin-tech added enhancement Architectural upgrades detectors work on code that inherits from or manages Detector labels Aug 28, 2024
DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {"hf_args": {"device": "cpu"}}
DEFAULT_PARAMS = Detector.DEFAULT_PARAMS | {
"hf_args": {"device": "cpu"},
"tokenizer_kwargs": {"padding": True, "truncation": True, "max_length": 512},
Copy link
Owner

Choose a reason for hiding this comment

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

On the other hand, running without a length cap also risks breaking models (this happens regularly on e.g. some NVCF instances). I think it's OK to offer a default control over this with a mild value that balances both being too high and too low. 512 seems reasonable (bearing in mind that detectors tend to be smaller models - this is a side effect of garak needing to run them at scale, but sometimes having primary compute allocated to the target model, reducing detector resources).

garak/detectors/base.py Outdated Show resolved Hide resolved
garak/detectors/misleading.py Show resolved Hide resolved
Co-authored-by: Erick Galinkin <erick.galinkin@gmail.com>
Signed-off-by: Leon Derczynski <leonderczynski@gmail.com>
@leondz leondz merged commit bc73683 into leondz:main Sep 3, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
detectors work on code that inherits from or manages Detector enhancement Architectural upgrades
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants