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 that padding_side always defaults to "right" when no value is explicitly passed #814

Open
wants to merge 6 commits into
base: dev-3.x
Choose a base branch
from

Conversation

degenfabian
Copy link
Contributor

@degenfabian degenfabian commented Dec 14, 2024

Description

Currently, when the user does not pass in an explicit value for default_padding_side, the tokenizer that is created/loaded for a model is always assigned the default value of "right", even when we load in a model from Huggingface whose tokenizer might already have a default_padding_side value assigned to it. There is an example of that in issue #801. Since this default value could differ from the global default value "right" in TransformerLens, this PR creates the following resolution order:

  1. If the user explicitly sets a value, use that value
  2. If the tokenizer already has a default_padding_side value, use that one
  3. Global default ("right")

This works similarly to the way the defaulting of prepend_bos was changed in PR #775

Fixes #801

For the example used in Issue #801:

from transformers import AutoTokenizer

from transformer_lens import HookedTransformer

model = HookedTransformer.from_pretrained("google/gemma-2-2b")
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")

print(model.tokenizer.padding_side)
print(tokenizer.padding_side)

The output is now:

left
left

instead of:

right
left

I also fixed a little typo where an error message says that padding_side is set incorrectly although the assertion statement checks for the value of default_prepend_bos.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

@bryce13950 bryce13950 changed the base branch from dev to dev-3.x December 28, 2024 00:54
@bryce13950
Copy link
Collaborator

This is going to be put into 3.0. The default behavior is being changed, and even though it is currently not correct, people may not be setting the value for this explicitly when they want it to be right, since it already is right. Changing that in a minor release could cause a lot of subtle issues, and frustrations. We do have a conflict with the Othello demo now. If you run it again with what is currently in dev, that should resolve it.

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