diff --git a/src/transformers/models/auto/tokenization_auto.py b/src/transformers/models/auto/tokenization_auto.py index a0f4e4f449f412..20f71f9be5538f 100644 --- a/src/transformers/models/auto/tokenization_auto.py +++ b/src/transformers/models/auto/tokenization_auto.py @@ -109,10 +109,7 @@ ("canine", ("CanineTokenizer", None)), ( "chameleon", - ( - "LlamaTokenizer" if is_sentencepiece_available() else None, - "LlamaTokenizerFast" if is_tokenizers_available() else None, - ), + (None, "LlamaTokenizerFast" if is_tokenizers_available() else None), ), ("chinese_clip", ("BertTokenizer", "BertTokenizerFast" if is_tokenizers_available() else None)), ( diff --git a/src/transformers/models/chameleon/convert_chameleon_weights_to_hf.py b/src/transformers/models/chameleon/convert_chameleon_weights_to_hf.py index 1aebeb0f0bb711..ff45c9b597e0b4 100644 --- a/src/transformers/models/chameleon/convert_chameleon_weights_to_hf.py +++ b/src/transformers/models/chameleon/convert_chameleon_weights_to_hf.py @@ -24,7 +24,7 @@ from transformers import ( ChameleonConfig, - ChameleonForCausalLM, + ChameleonForConditionalGeneration, ChameleonImageProcessor, ChameleonProcessor, ) @@ -49,10 +49,10 @@ Thereafter, models can be loaded via: ```py -from transformers import ChameleonForCausalLM, LlamaTokenizer +from transformers import ChameleonForConditionalGeneration, LlamaTokenizerFast -model = ChameleonForCausalLM.from_pretrained("/output/path") -tokenizer = LlamaTokenizer.from_pretrained("/output/path") +model = ChameleonForConditionalGeneration.from_pretrained("/output/path") +tokenizer = LlamaTokenizerFast.from_pretrained("/output/path") ``` Important note: you need to be able to host the whole model in RAM to execute this script (even if the biggest versions @@ -372,7 +372,7 @@ def permute(w, n_heads, dim1=dim, dim2=dim): vocabulary_map=vocabulary_map, ) with init_empty_weights(): - model = ChameleonForCausalLM(config) + model = ChameleonForConditionalGeneration(config) model.load_state_dict(state_dict, assign=True, strict=False) model.save_pretrained(model_path, safe_serialization=True) @@ -397,7 +397,7 @@ def permute(w, n_heads, dim1=dim, dim2=dim): # taken from https://github.com/facebookresearch/chameleon/blob/7a72f40aa5f462965c8374f25257f55b65b25ff4/data/prompts_for_human_evaluations.jsonl print("Loading the checkpoint in a Chameleon model...") print("*" * 100) - model = ChameleonForCausalLM.from_pretrained( + model = ChameleonForConditionalGeneration.from_pretrained( model_path, attn_implementation="eager", torch_dtype=torch.bfloat16, device_map="auto" ) processor = ChameleonProcessor.from_pretrained(model_path) diff --git a/src/transformers/models/chameleon/processing_chameleon.py b/src/transformers/models/chameleon/processing_chameleon.py index d999267ef1fa9c..dfab8a5dbaf2c7 100644 --- a/src/transformers/models/chameleon/processing_chameleon.py +++ b/src/transformers/models/chameleon/processing_chameleon.py @@ -68,7 +68,7 @@ class ChameleonProcessor(ProcessorMixin): """ attributes = ["image_processor", "tokenizer"] - tokenizer_class = ("LlamaTokenizer", "LlamaTokenizerFast") + tokenizer_class = "LlamaTokenizerFast" image_processor_class = "ChameleonImageProcessor" def __init__(self, image_processor, tokenizer, image_seq_length: int = 1024, image_token: str = ""): diff --git a/tests/models/chameleon/test_processor_chameleon.py b/tests/models/chameleon/test_processor_chameleon.py index 18a517399b8605..74314e3d4c1e95 100644 --- a/tests/models/chameleon/test_processor_chameleon.py +++ b/tests/models/chameleon/test_processor_chameleon.py @@ -2,7 +2,6 @@ import unittest from transformers import ChameleonProcessor -from transformers.models.auto.processing_auto import processor_class_from_name from ...test_processing_common import ProcessorTesterMixin @@ -11,26 +10,6 @@ class ChameleonProcessorTest(ProcessorTesterMixin, unittest.TestCase): from_pretrained_id = "leloy/Anole-7b-v0.1-hf" processor_class = ChameleonProcessor - def get_component(self, attribute, **kwargs): - assert attribute in self.processor_class.attributes - if attribute != "tokenizer": - return super().get_component(attribute, **kwargs) - # We use the fast tokenizer by default as the slow tokenizer expects the vocab file to be present in the loading directory. - # This vocab file is neither in the official repo nor does it get saved when we save the processor in `setUp` below. - component_class_name = getattr(self.processor_class, f"{attribute}_class") - if isinstance(component_class_name, tuple): - if "_fast" in component_class_name[0]: - component_class_name = component_class_name[0] - else: - component_class_name = component_class_name[1] - - component_class = processor_class_from_name(component_class_name) - component = component_class.from_pretrained(self.tmpdirname, **kwargs) # noqa - if attribute == "tokenizer" and not component.pad_token: - component.pad_token = "[TEST_PAD]" - - return component - def setUp(self): self.tmpdirname = tempfile.mkdtemp() processor = self.processor_class.from_pretrained(self.from_pretrained_id)