-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[wip] switch to transformers main again. #12976
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
base: main
Are you sure you want to change the base?
Changes from all commits
039324a
c152b18
f8e50fa
c5e023f
d0f279c
96f0804
ea90a74
37cfcee
926db24
cec0209
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,9 @@ | |
| import os | ||
| import sys | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| from diffusers.utils import is_transformers_version | ||
|
|
||
|
|
||
| sys.path.append("..") | ||
|
|
@@ -30,6 +33,7 @@ | |
| logger.addHandler(stream_handler) | ||
|
|
||
|
|
||
| @unittest.skipIf(is_transformers_version(">=", "4.57.5"), "Size mismatch") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internal discussion: https://huggingface.slack.com/archives/C014N4749J9/p1768474502541349 |
||
| class CustomDiffusion(ExamplesTestsAccelerate): | ||
| def test_custom_diffusion(self): | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| torch.nn.ConvTranspose2d, | ||
| torch.nn.ConvTranspose3d, | ||
| torch.nn.Linear, | ||
| torch.nn.Embedding, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happening because of the way weight loading is done in v5. |
||
| # TODO(aryan): look into torch.nn.LayerNorm, torch.nn.GroupNorm later, seems to be causing some issues with CogVideoX | ||
| # because of double invocation of the same norm layer in CogVideoXLayerNorm | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,13 @@ | |
| from torch import nn | ||
|
|
||
| from ..models.modeling_utils import load_state_dict | ||
| from ..utils import _get_model_file, is_accelerate_available, is_transformers_available, logging | ||
| from ..utils import ( | ||
| _get_model_file, | ||
| is_accelerate_available, | ||
| is_transformers_available, | ||
| is_transformers_version, | ||
| logging, | ||
| ) | ||
|
|
||
|
|
||
| if is_transformers_available(): | ||
|
|
@@ -549,17 +555,29 @@ def unload_textual_inversion( | |
|
|
||
| # Delete from tokenizer | ||
| for token_id, token_to_remove in zip(token_ids, tokens): | ||
| del tokenizer._added_tokens_decoder[token_id] | ||
| del tokenizer._added_tokens_encoder[token_to_remove] | ||
| if is_transformers_version("<=", "4.58.0"): | ||
| del tokenizer._added_tokens_decoder[token_id] | ||
| del tokenizer._added_tokens_encoder[token_to_remove] | ||
| elif is_transformers_version(">", "4.58.0"): | ||
| del tokenizer.added_tokens_decoder[token_id] | ||
| del tokenizer.added_tokens_encoder[token_to_remove] | ||
|
|
||
| # Make all token ids sequential in tokenizer | ||
| key_id = 1 | ||
| for token_id in tokenizer.added_tokens_decoder: | ||
| if token_id > last_special_token_id and token_id > last_special_token_id + key_id: | ||
| token = tokenizer._added_tokens_decoder[token_id] | ||
| tokenizer._added_tokens_decoder[last_special_token_id + key_id] = token | ||
| del tokenizer._added_tokens_decoder[token_id] | ||
| tokenizer._added_tokens_encoder[token.content] = last_special_token_id + key_id | ||
| if is_transformers_version("<=", "4.58.0"): | ||
| token = tokenizer._added_tokens_decoder[token_id] | ||
| tokenizer._added_tokens_decoder[last_special_token_id + key_id] = token | ||
| del tokenizer._added_tokens_decoder[token_id] | ||
| elif is_transformers_version(">", "4.58.0"): | ||
| token = tokenizer.added_tokens_decoder[token_id] | ||
| tokenizer.added_tokens_decoder[last_special_token_id + key_id] = token | ||
| del tokenizer.added_tokens_decoder[token_id] | ||
| if is_transformers_version("<=", "4.58.0"): | ||
| tokenizer._added_tokens_encoder[token.content] = last_special_token_id + key_id | ||
| elif is_transformers_version(">", "4.58.0"): | ||
| tokenizer.added_tokens_encoder[token.content] = last_special_token_id + key_id | ||
|
Comment on lines
+569
to
+580
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still doesn't solve the following issue: FAILED tests/pipelines/test_pipelines.py::DownloadTests::test_textual_inversion_unload - AttributeError: CLIPTokenizer has no attribute _added_tokens_decoder. Did you mean: 'added_tokens_decoder'?Internal thread: https://huggingface.slack.com/archives/C014N4749J9/p1768536480412119 |
||
| key_id += 1 | ||
| tokenizer._update_trie() | ||
| # set correct total vocab size after removing tokens | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,9 @@ def _get_prompt_embeds( | |
| truncation=True, | ||
| padding="max_length", | ||
| ) | ||
| input_ids = ( | ||
| input_ids["input_ids"] if not isinstance(input_ids, list) and "input_ids" in input_ids else input_ids | ||
| ) | ||
|
Comment on lines
+281
to
+283
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internal discussion https://huggingface.slack.com/archives/C014N4749J9/p1768537424692669 |
||
| input_ids = torch.LongTensor(input_ids) | ||
| input_ids_batch.append(input_ids) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,17 @@ def test_load_from_config_diffusers_with_subfolder(self, mock_load_config): | |
| side_effect=[EnvironmentError("File not found"), {"model_type": "clip_text_model"}], | ||
| ) | ||
| def test_load_from_config_transformers_with_subfolder(self, mock_load_config): | ||
| model = AutoModel.from_pretrained("hf-internal-testing/tiny-stable-diffusion-torch", subfolder="text_encoder") | ||
| model = AutoModel.from_pretrained( | ||
| "hf-internal-testing/tiny-stable-diffusion-torch", subfolder="text_encoder", use_safetensors=False | ||
| ) | ||
|
Comment on lines
+23
to
+25
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internal discussion: https://huggingface.slack.com/archives/C014N4749J9/p1768462040821759 |
||
| assert isinstance(model, CLIPTextModel) | ||
|
|
||
| def test_load_from_config_without_subfolder(self): | ||
| model = AutoModel.from_pretrained("hf-internal-testing/tiny-random-longformer") | ||
| assert isinstance(model, LongformerModel) | ||
|
|
||
| def test_load_from_model_index(self): | ||
| model = AutoModel.from_pretrained("hf-internal-testing/tiny-stable-diffusion-torch", subfolder="text_encoder") | ||
| model = AutoModel.from_pretrained( | ||
| "hf-internal-testing/tiny-stable-diffusion-torch", subfolder="text_encoder", use_safetensors=False | ||
| ) | ||
| assert isinstance(model, CLIPTextModel) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,7 +108,7 @@ def get_dummy_inputs(self, device, seed=0): | |
| generator = torch.Generator(device=device).manual_seed(seed) | ||
| inputs = { | ||
| "prompt": "dance monkey", | ||
| "negative_prompt": "", | ||
| "negative_prompt": "bad", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise, the corresponding tokenizer outputs: negative_prompt=[' ']
prompt=[' ']
text_input_ids=tensor([], size=(1, 0), dtype=torch.int64)which leads to: E RuntimeError: cannot reshape tensor of 0 elements into shape [1, 0, -1, 8] because the unspecified dimension size -1 can be any value and is ambiguous |
||
| "generator": generator, | ||
| "num_inference_steps": 2, | ||
| "guidance_scale": 6.0, | ||
|
|
||
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.
Temporary. For this PR.