1414limitations under the License.
1515"""
1616
17- from .scheduling import create_sub_slicing_annotations
17+ from .scheduling import create_sub_slicing_annotations , create_placement_policy_label , get_placement_policy_name , is_placement_policy_supported
18+ from .system_characteristics import SystemCharacteristics , AcceleratorType
1819
1920
2021def test_create_sub_slicing_annotations_returns_valid_annotations ():
@@ -29,3 +30,83 @@ def test_create_sub_slicing_annotations_returns_valid_annotations():
2930 ),
3031 'cloud.google.com/gke-tpu-slice-topology: 2x2' ,
3132 ]
33+
34+
35+ def test_create_placement_policy_label_returns_valid_label ():
36+ system_characteristics = SystemCharacteristics (
37+ chips_per_vm = 1 ,
38+ gce_machine_type = 'tpu7x-standard-1t' ,
39+ gke_accelerator = 'tpu7x' ,
40+ requires_workload_policy = False ,
41+ topology = '1x1x1' ,
42+ vms_per_slice = 1 ,
43+ device_type = 'tpu7x' ,
44+ accelerator_type = AcceleratorType .TPU ,
45+ supports_sub_slicing = False ,
46+ )
47+ label = create_placement_policy_label (system_characteristics )
48+ assert (
49+ label
50+ == 'cloud.google.com/placement-policy-name: tpu7x-1x1x1-placement-policy'
51+ )
52+
53+
54+ def test_get_placement_policy_name_returns_valid_name ():
55+ system_characteristics = SystemCharacteristics (
56+ chips_per_vm = 1 ,
57+ gce_machine_type = 'tpu7x-standard-1t' ,
58+ gke_accelerator = 'tpu7x' ,
59+ requires_workload_policy = False ,
60+ topology = '1x1x1' ,
61+ vms_per_slice = 1 ,
62+ device_type = 'tpu7x' ,
63+ accelerator_type = AcceleratorType .TPU ,
64+ supports_sub_slicing = False ,
65+ )
66+ name = get_placement_policy_name (system_characteristics )
67+ assert name == 'tpu7x-1x1x1-placement-policy'
68+
69+
70+ def test_is_placement_policy_supported_returns_true_for_system_characteristics_supporting_workload_policy_and_having_valid_topology ():
71+ system_characteristics = SystemCharacteristics (
72+ chips_per_vm = 1 ,
73+ gce_machine_type = 'tpu7x-standard-1t' ,
74+ gke_accelerator = 'tpu7x' ,
75+ requires_workload_policy = True ,
76+ topology = '1x1x1' ,
77+ vms_per_slice = 1 ,
78+ device_type = 'tpu7x' ,
79+ accelerator_type = AcceleratorType .TPU ,
80+ supports_sub_slicing = False ,
81+ )
82+ assert is_placement_policy_supported (system_characteristics ) is True
83+
84+
85+ def test_is_placement_policy_supported_returns_false_for_system_characteristics_not_supporting_workload_policy_and_having_valid_topology ():
86+ system_characteristics = SystemCharacteristics (
87+ chips_per_vm = 1 ,
88+ gce_machine_type = 'tpu7x-standard-1t' ,
89+ gke_accelerator = 'tpu7x' ,
90+ requires_workload_policy = False ,
91+ topology = '1x1x1' ,
92+ vms_per_slice = 1 ,
93+ device_type = 'tpu7x' ,
94+ accelerator_type = AcceleratorType .TPU ,
95+ supports_sub_slicing = False ,
96+ )
97+ assert is_placement_policy_supported (system_characteristics ) is False
98+
99+
100+ def test_is_placement_policy_supported_returns_false_for_system_characteristics_supporting_workload_policy_and_having_invalid_topology ():
101+ system_characteristics = SystemCharacteristics (
102+ chips_per_vm = 1 ,
103+ gce_machine_type = 'tpu7x-standard-1t' ,
104+ gke_accelerator = 'tpu7x' ,
105+ requires_workload_policy = True ,
106+ topology = 'aaa' ,
107+ vms_per_slice = 1 ,
108+ device_type = 'tpu7x' ,
109+ accelerator_type = AcceleratorType .TPU ,
110+ supports_sub_slicing = False ,
111+ )
112+ assert is_placement_policy_supported (system_characteristics ) is False
0 commit comments