Debian Codegraph @

tests/test_launch.py

raw
1 # Copyright 2021 The HuggingFace Team. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import argparse
16 import unittest
17
18 from accelerate.utils.launch import prepare_multi_gpu_env
19
20
21 class TestPrepareMultiGpuEnv(unittest.TestCase):
22 def test_auto_port_selection(self):
23 args = argparse.Namespace(
24 num_processes=1,
25 num_machines=1,
26 main_process_ip="127.0.0.1",
27 main_process_port=0,
28 machine_rank=0,
29 module=False,
30 no_python=False,
31 debug=False,
32 gpu_ids="all",
33 mixed_precision="no",
34 dynamo_backend="NO",
35 dynamo_mode="default",
36 dynamo_use_fullgraph=False,
37 dynamo_use_dynamic=False,
38 dynamo_use_regional_compilation=False,
39 use_fsdp=False,
40 fsdp_cpu_ram_efficient_loading=False,
41 fsdp_sync_module_states=False,
42 fsdp_version=None,
43 fsdp_sharding_strategy=None,
44 fsdp_reshard_after_forward=False,
45 fsdp_offload_params=False,
46 fsdp_min_num_params=0,
47 fsdp_auto_wrap_policy=None,
48 fsdp_transformer_layer_cls_to_wrap=None,
49 fsdp_backward_prefetch=None,
50 fsdp_state_dict_type=None,
51 fsdp_forward_prefetch=False,
52 fsdp_use_orig_params=False,
53 fsdp_activation_checkpointing=False,
54 use_tp=False,
55 tp_size=1,
56 use_megatron_lm=False,
57 megatron_lm_tp_degree=1,
58 megatron_lm_pp_degree=1,
59 megatron_lm_gradient_clipping=1.0,
60 megatron_lm_num_micro_batches=None,
61 megatron_lm_sequence_parallelism=None,
62 megatron_lm_recompute_activations=None,
63 megatron_lm_use_distributed_optimizer=None,
64 num_cpu_threads_per_process=1,
65 enable_cpu_affinity=False,
66 same_network=False,
67 use_parallelism_config=False,
68 )
69
70 prepare_multi_gpu_env(args)
71 self.assertIn("master_port", args.__dict__)
72 self.assertNotEqual(args.master_port, "0")
73 self.assertTrue(args.master_port.isdigit())