[tests] add torch.use_deterministic_algorithms for XPU (#30774)

* add xpu check

* add marker

* add documentation

* update doc

* fix ci

* remove from global init

* fix
This commit is contained in:
Fanli Lin
2024-05-23 23:53:07 +08:00
committed by GitHub
parent 8366b57241
commit 21339a5213
6 changed files with 30 additions and 2 deletions

View File

@@ -18,7 +18,7 @@ import tempfile
import unittest
from transformers import is_torch_available, logging
from transformers.testing_utils import CaptureLogger, require_torch, slow, torch_device
from transformers.testing_utils import CaptureLogger, require_deterministic_for_xpu, require_torch, slow, torch_device
from ...test_modeling_common import ids_tensor
from ..bart.test_modeling_bart import BartStandaloneDecoderModelTester
@@ -639,6 +639,7 @@ class EncoderDecoderMixin:
loss.backward()
@slow
@require_deterministic_for_xpu
def test_real_model_save_load_from_pretrained(self):
model_2 = self.get_pretrained_model()
model_2.to(torch_device)

View File

@@ -18,7 +18,7 @@ import tempfile
import unittest
from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.testing_utils import require_deterministic_for_xpu, require_torch, slow, torch_device
from ...test_modeling_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_bert import BertModelTester
@@ -422,6 +422,7 @@ class EncoderDecoderMixin:
loss.backward()
@slow
@require_deterministic_for_xpu
def test_real_model_save_load_from_pretrained(self):
model_2, inputs = self.get_pretrained_model_and_inputs()
model_2.to(torch_device)
@@ -578,6 +579,7 @@ class Speech2TextBertModelTest(EncoderDecoderMixin, unittest.TestCase):
def test_save_and_load_from_pretrained(self):
pass
@require_deterministic_for_xpu
# all published pretrained models are Speech2TextModel != Speech2TextEncoder
def test_real_model_save_load_from_pretrained(self):
pass

View File

@@ -22,6 +22,7 @@ import unittest
from transformers import SpeechT5Config, SpeechT5HifiGanConfig
from transformers.testing_utils import (
is_torch_available,
require_deterministic_for_xpu,
require_sentencepiece,
require_tokenizers,
require_torch,
@@ -1071,6 +1072,7 @@ class SpeechT5ForTextToSpeechIntegrationTests(unittest.TestCase):
"Shape mismatch between generate_speech and generate methods.",
)
@require_deterministic_for_xpu
def test_one_to_many_generation(self):
model = self.default_model
processor = self.default_processor