mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
Fix Encoder-Decoder testing issue about repo. names (#19250)
* Change "../gpt2" to "gpt2" Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
parent
2fba98e585
commit
f33858d18a
@ -919,7 +919,7 @@ class GPT2EncoderDecoderModelTest(EncoderDecoderMixin, unittest.TestCase):
|
||||
}
|
||||
|
||||
def get_pretrained_model(self):
|
||||
return EncoderDecoderModel.from_encoder_decoder_pretrained("bert-base-cased", "../gpt2")
|
||||
return EncoderDecoderModel.from_encoder_decoder_pretrained("bert-base-cased", "gpt2")
|
||||
|
||||
def test_encoder_decoder_model_shared_weights(self):
|
||||
pass
|
||||
@ -930,7 +930,7 @@ class GPT2EncoderDecoderModelTest(EncoderDecoderMixin, unittest.TestCase):
|
||||
|
||||
model.to(torch_device)
|
||||
tokenizer_in = AutoTokenizer.from_pretrained("bert-base-cased")
|
||||
tokenizer_out = AutoTokenizer.from_pretrained("../gpt2")
|
||||
tokenizer_out = AutoTokenizer.from_pretrained("gpt2")
|
||||
|
||||
ARTICLE_STUDENTS = """(CNN)Sigma Alpha Epsilon is under fire for a video showing party-bound fraternity members singing a racist chant. SAE's national chapter suspended the students, but University of Oklahoma President David Boren took it a step further, saying the university's affiliation with the fraternity is permanently done. The news is shocking, but it's not the first time SAE has faced controversy. SAE was founded March 9, 1856, at the University of Alabama, five years before the American Civil War, according to the fraternity website. When the war began, the group had fewer than 400 members, of which "369 went to war for the Confederate States and seven for the Union Army," the website says. The fraternity now boasts more than 200,000 living alumni, along with about 15,000 undergraduates populating 219 chapters and 20 "colonies" seeking full membership at universities. SAE has had to work hard to change recently after a string of member deaths, many blamed on the hazing of new recruits, SAE national President Bradley Cohen wrote in a message on the fraternity's website. The fraternity's website lists more than 130 chapters cited or suspended for "health and safety incidents" since 2010. At least 30 of the incidents involved hazing, and dozens more involved alcohol. However, the list is missing numerous incidents from recent months. Among them, according to various media outlets: Yale University banned the SAEs from campus activities last month after members allegedly tried to interfere with a sexual misconduct investigation connected to an initiation rite. Stanford University in December suspended SAE housing privileges after finding sorority members attending a fraternity function were subjected to graphic sexual content. And Johns Hopkins University in November suspended the fraternity for underage drinking. "The media has labeled us as the 'nation's deadliest fraternity,' " Cohen said. In 2011, for example, a student died while being coerced into excessive alcohol consumption, according to a lawsuit. SAE's previous insurer dumped the fraternity. "As a result, we are paying Lloyd's of London the highest insurance rates in the Greek-letter world," Cohen said. Universities have turned down SAE's attempts to open new chapters, and the fraternity had to close 12 in 18 months over hazing incidents."""
|
||||
|
||||
|
@ -908,7 +908,7 @@ class TFGPT2EncoderDecoderModelTest(TFEncoderDecoderMixin, unittest.TestCase):
|
||||
from transformers import EncoderDecoderModel
|
||||
|
||||
tokenizer_in = AutoTokenizer.from_pretrained("bert-base-cased")
|
||||
tokenizer_out = AutoTokenizer.from_pretrained("../gpt2")
|
||||
tokenizer_out = AutoTokenizer.from_pretrained("gpt2")
|
||||
|
||||
"""Not working, because pt checkpoint has `encoder.encoder.layer...` while tf model has `encoder.bert.encoder.layer...`.
|
||||
(For GPT2 decoder, there is no issue)
|
||||
|
@ -673,9 +673,7 @@ class TFVisionEncoderDecoderMixin:
|
||||
@require_tf
|
||||
class TFViT2GPT2EncoderDecoderModelTest(TFVisionEncoderDecoderMixin, unittest.TestCase):
|
||||
def get_pretrained_model(self):
|
||||
return TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
|
||||
"google/vit-base-patch16-224-in21k", "../gpt2"
|
||||
)
|
||||
return TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained("google/vit-base-patch16-224-in21k", "gpt2")
|
||||
|
||||
def get_encoder_decoder_model(self, config, decoder_config):
|
||||
encoder_model = TFViTModel(config, name="encoder")
|
||||
@ -720,12 +718,10 @@ class TFViT2GPT2EncoderDecoderModelTest(TFVisionEncoderDecoderMixin, unittest.Te
|
||||
@require_tf
|
||||
class TFVisionEncoderDecoderModelTest(unittest.TestCase):
|
||||
def get_from_encoderdecoder_pretrained_model(self):
|
||||
return TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
|
||||
"google/vit-base-patch16-224-in21k", "../gpt2"
|
||||
)
|
||||
return TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained("google/vit-base-patch16-224-in21k", "gpt2")
|
||||
|
||||
def get_decoder_config(self):
|
||||
config = AutoConfig.from_pretrained("../gpt2")
|
||||
config = AutoConfig.from_pretrained("gpt2")
|
||||
config.is_decoder = True
|
||||
config.add_cross_attention = True
|
||||
return config
|
||||
@ -735,7 +731,7 @@ class TFVisionEncoderDecoderModelTest(unittest.TestCase):
|
||||
|
||||
def get_encoder_decoder_models(self):
|
||||
encoder_model = TFViTModel.from_pretrained("google/vit-base-patch16-224-in21k", name="encoder")
|
||||
decoder_model = TFGPT2LMHeadModel.from_pretrained("../gpt2", config=self.get_decoder_config(), name="decoder")
|
||||
decoder_model = TFGPT2LMHeadModel.from_pretrained("gpt2", config=self.get_decoder_config(), name="decoder")
|
||||
return {"encoder": encoder_model, "decoder": decoder_model}
|
||||
|
||||
def _check_configuration_tie(self, model):
|
||||
@ -764,7 +760,7 @@ def prepare_img():
|
||||
class TFVisionEncoderDecoderModelSaveLoadTests(unittest.TestCase):
|
||||
def get_encoder_decoder_config(self):
|
||||
encoder_config = AutoConfig.from_pretrained("google/vit-base-patch16-224-in21k")
|
||||
decoder_config = AutoConfig.from_pretrained("../gpt2", is_decoder=True, add_cross_attention=True)
|
||||
decoder_config = AutoConfig.from_pretrained("gpt2", is_decoder=True, add_cross_attention=True)
|
||||
return VisionEncoderDecoderConfig.from_encoder_decoder_configs(encoder_config, decoder_config)
|
||||
|
||||
def get_encoder_decoder_config_small(self):
|
||||
@ -879,7 +875,7 @@ class TFVisionEncoderDecoderModelSaveLoadTests(unittest.TestCase):
|
||||
|
||||
config = self.get_encoder_decoder_config()
|
||||
feature_extractor = AutoFeatureExtractor.from_pretrained("google/vit-base-patch16-224-in21k")
|
||||
decoder_tokenizer = AutoTokenizer.from_pretrained("../gpt2")
|
||||
decoder_tokenizer = AutoTokenizer.from_pretrained("gpt2")
|
||||
|
||||
img = prepare_img()
|
||||
pixel_values = feature_extractor(images=img, return_tensors="tf").pixel_values
|
||||
@ -896,7 +892,7 @@ class TFVisionEncoderDecoderModelSaveLoadTests(unittest.TestCase):
|
||||
encoder = TFAutoModel.from_pretrained("google/vit-base-patch16-224-in21k", name="encoder")
|
||||
# It's necessary to specify `add_cross_attention=True` here.
|
||||
decoder = TFAutoModelForCausalLM.from_pretrained(
|
||||
"../gpt2", is_decoder=True, add_cross_attention=True, name="decoder"
|
||||
"gpt2", is_decoder=True, add_cross_attention=True, name="decoder"
|
||||
)
|
||||
pretrained_encoder_dir = os.path.join(tmp_dirname, "pretrained_encoder")
|
||||
pretrained_decoder_dir = os.path.join(tmp_dirname, "pretrained_decoder")
|
||||
|
Loading…
Reference in New Issue
Block a user