-
Notifications
You must be signed in to change notification settings - Fork 166
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
enable tokenizer customization in HFDetector #855
Conversation
* promote `tokenizer_kwargs` as DEFAULT_PARAM of parent class * remove `__init()__` overrides not longer needed Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
garak/detectors/base.py
Outdated
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}, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
garak/detectors/base.py
Outdated
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}, |
There was a problem hiding this comment.
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.
Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
garak/detectors/base.py
Outdated
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}, |
There was a problem hiding this comment.
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).
Co-authored-by: Erick Galinkin <erick.galinkin@gmail.com> Signed-off-by: Leon Derczynski <leonderczynski@gmail.com>
Commonize parameters utilized in
HFDetector
, existing detectors currently use common arguments.tokenizer_kwargs
as DEFAULT_PARAM of parent class__init()__
overrides not longer neededExpands 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 overridesdetect()
with a custom method. Should this PR be expanded to consume values fromself.tokenizer_kwargs
formax_length
andtruncation
? The values are currently hardcoded indetect()
as local values. It does not look likepadding
is ever consumed inmisleading.MustContradictNLI
and could be suppressed with instance defaults for that class.