Repository: huggingface/transformers
Pull request: fix 2 encoder_decoder issues on XPU

PASSED pytest -rA tests/models/encoder_decoder/test_modeling_encoder_decoder.py -k test_roberta2roberta_summarization 
PASSED pytest -rA tests/models/encoder_decoder/test_modeling_encoder_decoder.py -k test_bert2gpt2_summarization

Changed files:
filename: tests/models/encoder_decoder/test_modeling_encoder_decoder.py
patch: @@ -19,6 +19,7 @@
 from transformers import is_torch_available, logging
 from transformers.testing_utils import (
     CaptureLogger,
+    Expectations,
     require_deterministic_for_xpu,
     require_torch,
     require_torch_sdpa,
@@ -946,9 +947,28 @@ def test_roberta2roberta_summarization(self):
 
         ARTICLE_TOSHIBA = """An independent panel appointed by Toshiba found institutional accounting irregularities, the firm said in a statement to investors. Toshiba said it "takes the situation it has caused very seriously" and that it "deeply apologised" to shareholders. The overstatement was roughly triple an initial Toshiba estimate. The probe could lead to a restatement of earnings, a board overhaul and potential action by regulators. "Within Toshiba, there was a corporate culture in which one could not go against the wishes of superiors," the report said. "Therefore, when top management presented 'challenges', division presidents, line managers and employees below them continually carried out inappropriate accounting practices to meet targets in line with the wishes of their superiors." The improper accounting practices stretched back to 2008."""
 
-        EXPECTED_SUMMARY_PS3 = """Sony has said that a bug in its PlayStation 3 console is preventing them from using the machine as a computer."""
-
-        EXPECTED_SUMMARY_TOSHIBA = """Japanese electronics giant Toshiba overstated its annual earnings by more than a third last year, according to a report."""
+        # fmt: off
+        EXPECTED_SUMMARIES_PS3 = Expectations(
+            {
+                ("xpu", 3): """Sony has said that a bug in its PlayStation 3 console is preventing them from using the machine as a computer .""",
+                ("cuda", 7): """Sony has said that a bug in its PlayStation 3 console is preventing them from using the machine as a computer.""",
+            }
+        ) # fmt: on
+        EXPECTED_SUMMARY_PS3 = EXPECTED_SUMMARIES_PS3.get_expectation()
+
+        EXPECTED_SUMMARIES_TOSHIBA = Expectations(
+            {
+                (
+                    "xpu",
+                    3,
+                ): """Japanese electronics giant Toshiba overstated its annual earnings by more than a third last year , according to a report .""",
+                (
+                    "cuda",
+                    7,
+                ): """Japanese electronics giant Toshiba overstated its annual earnings by more than a third last year, according to a report.""",
+            }
+        )
+        EXPECTED_SUMMARY_TOSHIBA = EXPECTED_SUMMARIES_TOSHIBA.get_expectation()
 
         input_dict = tokenizer(
             [ARTICLE_PS3, ARTICLE_TOSHIBA], max_length=512, padding="max_length", return_tensors="pt"
@@ -1091,7 +1111,19 @@ def test_bert2gpt2_summarization(self):
 
         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."""
 
-        EXPECTED_SUMMARY_STUDENTS = """SAS Alpha Epsilon suspended the students, but university president says it's permanent.\nThe fraternity has had to deal with a string of student deaths since 2010.\nSAS has more than 200,000 members, many of whom are students.\nA student died while being forced into excessive alcohol consumption."""
+        EXPECTED_SUMMARIES_STUDENTS = Expectations(
+            {
+                (
+                    "xpu",
+                    3,
+                ): """SAS Alpha Epsilon suspended the students, but university president says it's permanent .\nThe fraternity has had to deal with a string of student deaths since 2010 .\nSAS has more than 200,000 members, many of whom are students .\nA student died while being forced into excessive alcohol consumption .""",
+                (
+                    "cuda",
+                    7,
+                ): """SAS Alpha Epsilon suspended the students, but university president says it's permanent.\nThe fraternity has had to deal with a string of student deaths since 2010.\nSAS has more than 200,000 members, many of whom are students.\nA student died while being forced into excessive alcohol consumption.""",
+            }
+        )
+        EXPECTED_SUMMARY_STUDENTS = EXPECTED_SUMMARIES_STUDENTS.get_expectation()
 
         input_dict = tokenizer_in(ARTICLE_STUDENTS, return_tensors="pt")
         output_ids = model.generate(input_dict["input_ids"].to(torch_device))