Пример #1
0
def test_numa_multi_instance_run_command(
        mock_system, mock_subprocess, mock_platform, mock_os, mock_open,
        mock_path_exists, test_num_instances, test_socket_id, test_cpu_list, expected_cpu_bind):
    """ Test the multi instance run using numactl by trying different combinations of
    cpu lists and the number of cores used per instance. Checks the system call that
    is run to verify that it matches the cpu groups that are expected. """
    platform_util = MagicMock(cpu_core_list=test_cpu_list)
    test_output_dir = "/tmp/output"
    args = MagicMock(verbose=True, model_name=test_model_name, batch_size=100,
                     numa_cores_per_instance=test_num_instances, precision="fp32",
                     output_dir=test_output_dir, socket_id=test_socket_id)
    os.environ["PYTHON_EXE"] = "python"
    os.environ["MPI_HOSTNAMES"] = "None"
    os.environ["MPI_NUM_PROCESSES"] = "None"
    base_model_init = BaseModelInitializer(args, [], platform_util)

    mock_path_exists.return_value = True

    expected_omp_num_threads = "OMP_NUM_THREADS={}".format(test_num_instances)

    # call run_command and then check the output
    test_run_command = "python foo.py"
    base_model_init.run_command(test_run_command)
    system_call_args = mock_system.call_args[0][0]
    assert expected_omp_num_threads in system_call_args

    for cpu_bind in expected_cpu_bind:
        assert "numactl --localalloc --physcpubind={} {} >> {}".\
            format(cpu_bind, test_run_command, test_output_dir) in system_call_args
def test_base_model_initializer(mock_system, mock_subprocess, mock_platform,
                                mock_os):
    # Setup base model init with test settings
    platform_util = MagicMock()
    args = MagicMock(verbose=True, model_name=test_model_name)
    os.environ["PYTHON_EXE"] = "python"
    base_model_init = BaseModelInitializer(args, [], platform_util)

    # call run_command and then check the output
    test_run_command = "python foo.py"
    base_model_init.run_command(test_run_command)
    mock_system.assert_called_with(test_run_command)
Пример #3
0
def test_numa_multi_instance_run_command(mock_system, mock_subprocess,
                                         mock_platform, mock_os, mock_open,
                                         mock_glob, mock_path_exists,
                                         test_num_instances, test_socket_id,
                                         test_cpu_list, expected_cpu_bind,
                                         precision):
    """ Test the multi instance run using numactl by trying different combinations of
    cpu lists and the number of cores used per instance. Checks the system call that
    is run to verify that it matches the cpu groups that are expected. """
    platform_util = MagicMock(cpu_core_list=test_cpu_list)
    test_output_dir = "/tmp/output"
    args = MagicMock(verbose=True,
                     model_name=test_model_name,
                     batch_size=100,
                     numa_cores_per_instance=test_num_instances,
                     precision=precision,
                     output_dir=test_output_dir,
                     mode="inference",
                     socket_id=test_socket_id,
                     benchmark_only=True)
    os.environ["PYTHON_EXE"] = "python"
    os.environ["MPI_HOSTNAMES"] = "None"
    os.environ["MPI_NUM_PROCESSES"] = "None"
    ld_preload_path = "/usr/lib/libtcmalloc.so.4.2.6"
    mock_glob.return_value = [ld_preload_path]
    base_model_init = BaseModelInitializer(args, [], platform_util)

    mock_path_exists.return_value = True

    expected_omp_num_threads = "OMP_NUM_THREADS={}".format(test_num_instances)

    # tcmalloc is used by default for int8, so the LD_PRELOAD path should be set
    expected_ld_preload = ""
    if precision == "int8":
        expected_ld_preload = "LD_PRELOAD={} ".format(ld_preload_path)

    test_run_command = "python foo.py"

    # For int8, add on the LD_PRELOAD prefix. The run command should know how to move this prefix to the
    # front of the command (before numactl)
    if precision == "int8":
        test_run_command_with_prefix = expected_ld_preload + test_run_command
    else:
        test_run_command_with_prefix = test_run_command

    # call run_command and then check the output
    base_model_init.run_command(test_run_command_with_prefix)
    system_call_args = mock_system.call_args[0][0]

    for cpu_bind in expected_cpu_bind:
        expected_cmd = "{}{} numactl --localalloc --physcpubind={} {} >> {}".\
            format(expected_ld_preload, expected_omp_num_threads, cpu_bind, test_run_command, test_output_dir)
        assert expected_cmd in system_call_args
Пример #4
0
def test_base_model_initializer(
        mock_system, mock_subprocess, mock_platform, mock_os, mock_open):
    # Setup base model init with test settings
    platform_util = MagicMock()
    args = MagicMock(verbose=True, model_name=test_model_name, batch_size=100,
                     numa_cores_per_instance=None)
    os.environ["PYTHON_EXE"] = "python"
    os.environ["MPI_HOSTNAMES"] = "None"
    os.environ["MPI_NUM_PROCESSES"] = "None"
    base_model_init = BaseModelInitializer(args, [], platform_util)

    # call run_command and then check the output
    test_run_command = "python foo.py"
    base_model_init.run_command(test_run_command)
    mock_system.assert_called_with(test_run_command)
Пример #5
0
def test_base_model_initializer(mock_system, mock_subprocess, mock_platform,
                                mock_os):
    setup_mock_values(mock_platform, mock_os, mock_subprocess)
    launch_benchmark = LaunchBenchmark()
    args, _ = launch_benchmark.parse_args(example_req_args)
    test_run_command = "python foo.py"
    platform_util = MagicMock()

    # Setup base model init with test settings
    args.verbose = True
    args.model_name = test_model_name
    base_model_init = BaseModelInitializer(args, [], platform_util)

    # call run_command and then check the output
    base_model_init.run_command(test_run_command)
    mock_system.assert_called_with(test_run_command)