Repository: huggingface/transformers
Pull request: Fix t5 failures

Fix all the remaining T5 failures. 

- The test `test_export_t5_summarization` was failing because `eos_token_id` was not being passed to GenerationConfig in `Seq2SeqLMExportableModule`, causing the generate loop to never stop at the end-of-sequence token and produce extra tokens. 
- The `test_fp16_fp32_conversion` test was failing because T5's `_keep_in_fp32_modules = ["wo"]` was unconditionally forcing the `wo` layer to FP32 for both FP16 and BF16 loading, so I created a centralized `_build_dtype_plan_for_loading()` method that encapsulates all the `dtype_plan` building logic in one place, taking the target dtype as input and properly applying `_keep_in_fp32_modules` (FP16 only) and `_keep_in_fp32_modules_strict` (FP16 and BF16) based on the actual loading `dtype`.
- Fix some expectations (tested for both AMD and Nvidia)

Changed files:
filename: src/transformers/integrations/executorch.py
patch: @@ -879,6 +879,7 @@ def __init__(
                 "batch_size": batch_size,
                 "max_cache_len": max_cache_length,
             },
+            eos_token_id=model.generation_config.eos_token_id,
         )
         self.exported_encoder = None
         self.exported_decoder = None

filename: tests/models/t5/test_modeling_t5.py
patch: @@ -1008,7 +1008,12 @@ def test_small_integration_test(self):
                 ("rocm", (9, 4)): -19.0846,
             }
         ).get_expectation()
-        self.assertTrue(abs(mtf_score - EXPECTED_SCORE) < 1e-4)
+        torch.testing.assert_close(
+            mtf_score,
+            EXPECTED_SCORE,
+            atol=1e-4,
+            rtol=0.0,
+        )
 
     @slow
     def test_small_v1_1_integration_test(self):
@@ -1033,8 +1038,13 @@ def test_small_v1_1_integration_test(self):
         loss = model(input_ids.to(torch_device), labels=labels.to(torch_device)).loss
         mtf_score = -(labels.shape[-1] * loss.item())
 
-        EXPECTED_SCORE = -59.0293
-        self.assertTrue(abs(mtf_score - EXPECTED_SCORE) < 1e-4)
+        EXPECTED_SCORE = -40.1645
+        torch.testing.assert_close(
+            mtf_score,
+            EXPECTED_SCORE,
+            atol=1e-4,
+            rtol=0.0,
+        )
 
     @slow
     def test_small_byt5_integration_test(self):
@@ -1057,8 +1067,13 @@ def test_small_byt5_integration_test(self):
         loss = model(input_ids.to(torch_device), labels=labels.to(torch_device)).loss
         mtf_score = -(labels.shape[-1] * loss.item())
 
-        EXPECTED_SCORE = -60.7397
-        self.assertTrue(abs(mtf_score - EXPECTED_SCORE) < 1e-4)
+        EXPECTED_SCORE = -44.6276
+        torch.testing.assert_close(
+            mtf_score,
+            EXPECTED_SCORE,
+            atol=1e-4,
+            rtol=0.0,
+        )
 
     @slow
     def test_summarization(self):
@@ -1431,8 +1446,8 @@ def test_contrastive_search_t5(self):
     def test_compile_static_cache(self):
         NUM_TOKENS_TO_GENERATE = 40
         EXPECTED_TEXT_COMPLETION = [
-            "theory of relativity states that 1) the speed of light is constant in all inertial reference frames. the laws of physics are the same for all inertial reference frames.",
-            "ketchup is my favorite condiment.",
+            "theory of relativity states that 1) the speed of light is constant in all inertial reference frames . the laws of physics are the same for all inertial reference frames .",
+            "ketchup is my favorite condiment .",
         ]
 
         prompts = [