From 2af87d018eff577c421b02e00bf34ab6aeeb8c42 Mon Sep 17 00:00:00 2001 From: Sanchit Gandhi <93869735+sanchit-gandhi@users.noreply.github.com> Date: Thu, 7 Sep 2023 17:49:14 +0100 Subject: [PATCH] [VITS] Fix nightly tests (#25986) * fix tokenizer * make bs even * fix multi gpu test * style * model forward * fix torch import * revert tok pin --- tests/models/vits/test_modeling_vits.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/models/vits/test_modeling_vits.py b/tests/models/vits/test_modeling_vits.py index f28c4686ae..e767b036be 100644 --- a/tests/models/vits/test_modeling_vits.py +++ b/tests/models/vits/test_modeling_vits.py @@ -27,6 +27,7 @@ from transformers.testing_utils import ( is_flaky, is_torch_available, require_torch, + require_torch_multi_gpu, slow, torch_device, ) @@ -177,6 +178,30 @@ class VitsModelTest(ModelTesterMixin, unittest.TestCase): config_and_inputs = self.model_tester.prepare_config_and_inputs() self.model_tester.create_and_check_model_forward(*config_and_inputs) + @require_torch_multi_gpu + # override to force all elements of the batch to have the same sequence length across GPUs + def test_multi_gpu_data_parallel_forward(self): + config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common() + config.use_stochastic_duration_prediction = False + + # move input tensors to cuda:O + for key, value in inputs_dict.items(): + if torch.is_tensor(value): + # make all elements of the batch the same -> ensures the output seq lengths are the same for DP + value[1:] = value[0] + inputs_dict[key] = value.to(0) + + for model_class in self.all_model_classes: + model = model_class(config=config) + model.to(0) + model.eval() + + # Wrap model in nn.DataParallel + model = torch.nn.DataParallel(model) + set_seed(555) + with torch.no_grad(): + _ = model(**self._prepare_for_class(inputs_dict, model_class)).waveform + @unittest.skip("VITS is not deterministic") def test_determinism(self): pass