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

Fix for transformers moving GenerationMixin.sample #520

Open
wants to merge 1 commit into
base: united
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions modeling/inference_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def __enter__(self):
)

if use_core_manipulations.sample:
use_core_manipulations.old_sample = transformers.GenerationMixin.sample
transformers.GenerationMixin.sample = use_core_manipulations.sample
use_core_manipulations.old_sample = transformers.GenerationMixin._sample
transformers.GenerationMixin._sample = use_core_manipulations.sample

if use_core_manipulations.get_stopping_criteria:
use_core_manipulations.old_get_stopping_criteria = (
Expand All @@ -69,7 +69,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
), "Patch leak: THE MONKEYS HAVE ESCAPED"

if use_core_manipulations.old_sample:
transformers.GenerationMixin.sample = use_core_manipulations.old_sample
transformers.GenerationMixin._sample = use_core_manipulations.old_sample
else:
assert (
not use_core_manipulations.sample
Expand Down
2 changes: 1 addition & 1 deletion modeling/inference_models/hf_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def new_sample(self, *args, **kwargs):
kwargs.setdefault("pad_token_id", 2)
return new_sample.old_sample(self, *args, **kwargs)

new_sample.old_sample = transformers.GenerationMixin.sample
new_sample.old_sample = transformers.GenerationMixin._sample
use_core_manipulations.sample = new_sample

# PEFT Loading. This MUST be done after all save_pretrained calls are
Expand Down