2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license as due to their complexity multigpu tests could impact other tests and to aid debug we have those in a separate module split we want this test to run even if there is only one gpu but if there are more we use them all ngpu getgpucount distributedargs f m torch distributed launch nprocpernodengpu self testfiledirrundistributedeval py printmetrics 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license as due to their complexity multi gpu tests could impact other tests and to aid debug we have those in a separate module model_name helsinki nlp opus mt en ro save_dir output_dir data_dir self test_file_dir_str test_data wmt_en_ro num_beams 2 task translation we want this test to run even if there is only one gpu but if there are more we use them all m torch distributed launch nproc_per_node n_gpu self test_file_dir run_distributed_eval py print metrics
import os
import sys

from transformers.testing_utils import TestCasePlus, execute_subprocess_async, get_gpu_count, require_torch_gpu, slow

from .utils import load_json


class TestSummarizationDistillerMultiGPU(TestCasePlus):
    @classmethod
    def setUpClass(cls):
        return cls

    @slow
    @require_torch_gpu
    def test_distributed_eval(self):
        output_dir = self.get_auto_remove_tmp_dir()
        args = f.split()

        
        n_gpu = get_gpu_count()
        distributed_args = f.split()
        cmd = [sys.executable] + distributed_args + args
        execute_subprocess_async(cmd, env=self.get_env())

        metrics_save_path = os.path.join(output_dir, "test_bleu.json")
        metrics = load_json(metrics_save_path)
        
        self.assertGreaterEqual(metrics["bleu"], 25)