-
Notifications
You must be signed in to change notification settings - Fork 570
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·378 lines (340 loc) · 14.4 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·378 lines (340 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash
set -exo pipefail
# Absolute path to the directory of this script.
_TEST_DIR="$(
cd "$(dirname "$0")"
pwd -P
)"
# Import utilities.
source "${_TEST_DIR}/utils/run_tests_utils.sh"
parse_options_to_vars $@
# Consume the parsed commandline arguments.
shift $(($OPTIND - 1))
# Set the `CONTINUE_ON_ERROR` flag to `1` to make the CI tests continue on error.
# This will allow you to see all the failures on your PR, not stopping with the first
# test failure like the default behavior.
CONTINUE_ON_ERROR="${CONTINUE_ON_ERROR:-0}"
if [[ "$CONTINUE_ON_ERROR" == "1" ]]; then
set +e
fi
export TORCH_TEST_DEVICES="$_TEST_DIR/pytorch_test_base.py"
export PYTORCH_TEST_WITH_SLOW=1
export XLA_DUMP_FATAL_STACK=1
export CPU_NUM_DEVICES=4
_TORCH_XLA_DIR=$(
cd ~
dirname "$(python -c 'import torch_xla; print(torch_xla.__file__)')"
)
COVERAGE_FILE="$_TEST_DIR/../.coverage"
function run_coverage {
if ! test_is_selected "$1"; then
return
fi
if [ "${USE_COVERAGE:-0}" != "0" ]; then
coverage run --source="$_TORCH_XLA_DIR" -p "$@"
else
python3 "$@"
fi
}
function run_test {
if ! test_is_selected "$1"; then
return
fi
echo "Running in PjRt runtime: $@"
# TODO(darisoy): run these tests with multiple CPU devices, this fails due to TF issue.
PJRT_DEVICE=CPU CPU_NUM_DEVICES=1 run_coverage "$@"
}
function run_test_without_functionalization {
if ! test_is_selected "$1"; then
return
fi
echo "Running with XLA_DISABLE_FUNCTIONALIZATION: $@"
XLA_DISABLE_FUNCTIONALIZATION=1 run_test "$@"
}
function run_test_multi_devices {
if ! test_is_selected "$1"; then
return
fi
echo "Running in PjRt runtime: $@"
# TODO(darisoy): run these tests with multiple CPU devices, this fails due to TF issue.
PJRT_DEVICE=CPU CPU_NUM_DEVICES=4 run_coverage "$@"
}
function run_test_multi_devices_without_func {
if ! test_is_selected "$1"; then
return
fi
echo "Running with XLA_DISABLE_FUNCTIONALIZATION: $@"
XLA_DISABLE_FUNCTIONALIZATION=1 run_test_multi_devices "$@"
}
function run_use_bf16 {
if ! test_is_selected "$1"; then
return
fi
echo "Running with XLA_USE_BF16: $@"
XLA_USE_BF16=1 run_test "$@"
}
function run_downcast_bf16 {
if ! test_is_selected "$1"; then
return
fi
echo "Running with XLA_DOWNCAST_BF16: $@"
XLA_DOWNCAST_BF16=1 run_test "$@"
}
function run_dynamic {
if ! test_is_selected "$1"; then
return
fi
echo "Running in DynamicShape mode: $@"
XLA_EXPERIMENTAL="nonzero:masked_select:masked_scatter:nms" run_test "$@"
}
function run_eager_debug {
if ! test_is_selected "$1"; then
return
fi
echo "Running in Eager Debug mode: $@"
XLA_USE_EAGER_DEBUG_MODE=1 run_test "$@"
}
function run_pt_xla_debug {
if ! test_is_selected "$1"; then
return
fi
echo "Running in save tensor file mode: $@"
PT_XLA_DEBUG=1 PT_XLA_DEBUG_FILE="/tmp/pt_xla_debug.txt" run_test "$@"
}
function run_pt_xla_debug_level1 {
if ! test_is_selected "$1"; then
return
fi
echo "Running in save tensor file mode: $@"
PT_XLA_DEBUG_LEVEL=1 PT_XLA_DEBUG_FILE="/tmp/pt_xla_debug.txt" run_test "$@"
}
function run_pt_xla_debug_level2 {
if ! test_is_selected "$1"; then
return
fi
echo "Running in save tensor file mode: $@"
PT_XLA_DEBUG_LEVEL=2 PT_XLA_DEBUG_FILE="/tmp/pt_xla_debug.txt" run_test "$@"
}
function run_torch_op_tests {
run_dynamic "$_TEST_DIR/../../test/test_view_ops.py" "$@" -v TestViewOpsXLA
run_test_without_functionalization "$_TEST_DIR/../../test/test_view_ops.py" "$@" -v TestViewOpsXLA
run_test "$_TEST_DIR/../../test/test_torch.py" "$@" -v TestTorchDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/test_torch.py" "$@" -v TestDevicePrecisionXLA
# TODO https://github.com/pytorch/xla/issues/9459: Investigate why this
# doesn't run any tests.
# run_test "$_TEST_DIR/../../test/test_torch.py" "$@" -v TestTensorDeviceOpsXLA
run_test "$_TEST_DIR/../../test/test_indexing.py" "$@" -v TestIndexingXLA
run_test "$_TEST_DIR/../../test/test_indexing.py" "$@" -v NumpyTestsXLA
# run_dynamic "$_TEST_DIR/../../test/test_nn.py" "$@" -v TestNNDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/nn/test_dropout.py" "$@" -v TestDropoutNNDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/nn/test_pooling.py" "$@" -v TestPoolingNNDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/nn/test_embedding.py" "$@" -v TestEmbeddingNNDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/nn/test_convolution.py" "$@" -v TestConvolutionNNDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/nn/test_multihead_attention.py" "$@" -v TestMultiheadAttentionNNDeviceTypeXLA
run_dynamic "$_TEST_DIR/../../test/test_type_promotion.py" "$@" -v TestTypePromotionXLA
}
#######################################################################################
################################# XLA OP TESTS SHARDS #################################
#######################################################################################
# DO NOT MODIFY
# These functions are split to evenly distribute the testing time across shards.
# You should only modify the tests when one function is a significant bottleneck
# over other run_xla_op_tests# tests. If that is the case, you should add a new
# function run_xla_op_testsN+1.
function run_xla_op_tests1 {
run_dynamic "$_TEST_DIR/test_operations.py" "$@" --verbosity=$VERBOSITY
run_dynamic "$_TEST_DIR/ds/test_dynamic_shapes.py"
run_dynamic "$_TEST_DIR/ds/test_dynamic_shape_models.py" "$@" --verbosity=$VERBOSITY
run_eager_debug "$_TEST_DIR/test_operations.py" "$@" --verbosity=$VERBOSITY
run_test "$_TEST_DIR/test_operations.py" "$@" --verbosity=$VERBOSITY
run_test "$_TEST_DIR/test_xla_graph_execution.py" "$@" --verbosity=$VERBOSITY
run_pt_xla_debug_level2 "$_TEST_DIR/test_xla_graph_execution.py" "$@" --verbosity=$VERBOSITY
run_test_without_functionalization "$_TEST_DIR/test_operations.py" "$@" --verbosity=$VERBOSITY
run_pt_xla_debug "$_TEST_DIR/debug_tool/test_pt_xla_debug.py"
run_pt_xla_debug_level1 "$_TEST_DIR/debug_tool/test_pt_xla_debug.py"
run_test "$_TEST_DIR/test_async_closures.py"
run_test "$_TEST_DIR/test_hlo_metadata.py"
# TODO(https://github.com/pytorch/xla/issues/8796): Re-enable this test
# run_test "$_TEST_DIR/test_profiler.py"
run_test "$_TEST_DIR/test_profiler_session.py"
run_test "$_TEST_DIR/pjrt/test_runtime.py"
run_test "$_TEST_DIR/pjrt/test_runtime_multi_cpu.py"
run_test "$_TEST_DIR/pjrt/test_internal_tpu.py"
PJRT_DEVICE=CPU XLA_CUDA=0 run_test "$_TEST_DIR/pjrt/test_ddp.py"
PJRT_DEVICE=CPU XLA_CUDA=0 run_test "$_TEST_DIR/pjrt/test_mesh_service.py"
run_test "$_TEST_DIR/test_python_ops.py"
run_test "$_TEST_DIR/test_ops.py"
run_test "$_TEST_DIR/test_metrics.py"
if [ -f "/tmp/metrics.txt" ]; then
rm /tmp/metrics.txt
fi
XLA_METRICS_FILE=/tmp/metrics.txt run_test "$_TEST_DIR/test_metrics.py"
run_test "$_TEST_DIR/test_deprecation.py"
run_test "$_TEST_DIR/test_data_type.py"
run_test "$_TEST_DIR/test_fp8.py"
run_xla_ir_debug run_test "$_TEST_DIR/test_env_var_mapper.py"
run_xla_hlo_debug run_test "$_TEST_DIR/test_env_var_mapper.py"
run_xla_hlo_debug run_test "$_TEST_DIR/stablehlo/test_stablehlo_save_load.py"
run_save_tensor_ir run_test "$_TEST_DIR/spmd/test_spmd_graph_dump.py"
run_save_tensor_hlo run_test "$_TEST_DIR/spmd/test_spmd_graph_dump.py"
}
function run_xla_op_tests2 {
run_test "$_TEST_DIR/pjrt/test_dtypes.py"
run_test "$_TEST_DIR/test_while_loop.py"
run_test "$_TEST_DIR/scan/test_scan.py"
run_test "$_TEST_DIR/scan/test_scan_spmd.py"
run_test "$_TEST_DIR/scan/test_scan_layers.py"
run_test "$_TEST_DIR/test_gru.py"
run_test "$_TEST_DIR/test_as_stride_use_slice.py"
run_test "$_TEST_DIR/test_placeholder.py"
run_xla_hlo_debug run_test "$_TEST_DIR/scan/test_scan_debug.py"
run_test "$_TEST_DIR/test_autocast.py"
run_test "$_TEST_DIR/eager/test_eager.py"
run_test "$_TEST_DIR/eager/test_eager_with_xla_compile.py"
run_test "$_TEST_DIR/eager/test_eager_with_torch_compile.py"
PJRT_DEVICE=CPU XLA_CUDA=0 run_test "$_TEST_DIR/eager/test_eager_all_reduce_in_place.py"
run_test "$_TEST_DIR/eager/test_eager_spmd.py"
run_test "$_TEST_DIR/test_callback.py"
XLA_USE_SPMD=1 run_test "$_TEST_DIR/test_callback.py"
run_test "$_TEST_DIR/test_assume_pure.py"
run_test "$_TEST_DIR/test_assume_pure_spmd.py"
run_test "$_TEST_DIR/test_assume_pure_torch.py"
run_test "$_TEST_DIR/test_dynamic_shapes_detector.py"
}
function run_xla_op_tests3 {
# TODO(qihqi): this test require tensorflow to run. need to setup separate
# CI with tf.
run_test "$_TEST_DIR/stablehlo/test_exports.py"
run_test "$_TEST_DIR/stablehlo/test_export_fx_passes.py"
run_test "$_TEST_DIR/stablehlo/test_implicit_broadcasting.py"
run_test "$_TEST_DIR/stablehlo/test_composite.py"
run_test "$_TEST_DIR/stablehlo/test_pt2e_qdq.py"
run_test "$_TEST_DIR/stablehlo/test_stablehlo_custom_call.py"
run_xla_hlo_debug run_test "$_TEST_DIR/stablehlo/test_stablehlo_inference.py"
run_test "$_TEST_DIR/stablehlo/test_stablehlo_compile.py"
run_test "$_TEST_DIR/stablehlo/test_unbounded_dynamism.py"
run_test "$_TEST_DIR/quantized_ops/test_quantized_matmul.py"
run_test "$_TEST_DIR/quantized_ops/test_dot_general.py"
run_test "$_TEST_DIR/spmd/test_xla_sharding.py"
run_test "$_TEST_DIR/spmd/test_xla_sharding_hlo.py"
run_test "$_TEST_DIR/spmd/test_xla_virtual_device.py"
run_test "$_TEST_DIR/spmd/test_dynamo_spmd.py"
run_test "$_TEST_DIR/spmd/test_spmd_debugging.py"
run_test "$_TEST_DIR/spmd/test_xla_distributed_checkpoint.py"
run_test "$_TEST_DIR/spmd/test_xla_spmd_python_api_interaction.py"
run_test "$_TEST_DIR/spmd/test_dtensor_integration.py"
run_test "$_TEST_DIR/spmd/test_dtensor_integration2.py"
run_test_multi_devices_without_func "$_TEST_DIR/spmd/test_dtensor_integration3.py"
run_test_multi_devices "$_TEST_DIR/spmd/test_dtensor_convert_mesh.py"
run_test_multi_devices "$_TEST_DIR/spmd/test_xla_dtensor_spec_conversion.py"
run_test_multi_devices "$_TEST_DIR/spmd/test_xla_dtensor_from_local.py"
run_test "$_TEST_DIR/spmd/test_xla_auto_sharding.py"
run_test "$_TEST_DIR/spmd/test_spmd_parameter_wrapping.py"
run_test "$_TEST_DIR/spmd/test_mp_input_sharding.py"
run_test "$_TEST_DIR/spmd/test_train_spmd_linear_model.py" "$@" --skip-gradient-checkpointing
run_test "$_TEST_DIR/test_gradient_accumulation.py"
run_save_tensor_hlo run_test "$_TEST_DIR/spmd/test_spmd_lowering_context.py"
run_test "$_TEST_DIR/test_operations_hlo.py" "$@" --verbosity=$VERBOSITY
run_test "$_TEST_DIR/test_input_output_aliases.py"
run_test_without_functionalization "$_TEST_DIR/test_input_output_aliases.py"
run_test "$_TEST_DIR/test_torch_distributed_xla_backend.py"
run_test "$_TEST_DIR/test_compilation_cache_utils.py"
run_test "$_TEST_DIR/test_persistent_cache.py"
run_test "$_TEST_DIR/test_devices.py"
run_test "$_TEST_DIR/test_manual_xla_registration.py"
# NOTE: this line below is testing export and don't care about GPU
PJRT_DEVICE=CPU CPU_NUM_DEVICES=1 run_coverage "$_TEST_DIR/test_core_aten_ops.py"
run_test "$_TEST_DIR/test_pallas.py"
run_xla_ir_hlo_debug run_test "$_TEST_DIR/test_user_computation_debug_cache.py"
# Test examples
run_test "$_TEST_DIR/../examples/scan/scan_examples.py"
}
function run_xla_op_tests4 {
run_test "$_TEST_DIR/test_jax_interop.py"
}
function run_xla_op_tests5 {
run_test "$_TEST_DIR/dynamo/test_dynamo_integrations_util.py"
run_test "$_TEST_DIR/dynamo/test_dynamo_aliasing.py"
run_test "$_TEST_DIR/dynamo/test_dynamo.py"
run_test "$_TEST_DIR/dynamo/test_dynamo_dynamic_shape.py"
run_test "$_TEST_DIR/dynamo/test_bridge.py"
run_test "$_TEST_DIR/dynamo/test_num_output.py"
run_test "$_TEST_DIR/dynamo/test_graph_input_matcher.py"
run_test "$_TEST_DIR/dynamo/test_dynamo_config.py"
run_save_tensor_ir run_test "$_TEST_DIR/dynamo/test_dynamo_graph_dump.py"
}
#######################################################################################
function run_op_tests {
run_torch_op_tests
run_xla_op_tests1
run_xla_op_tests2
run_xla_op_tests3
run_xla_op_tests4
run_xla_op_tests5
}
function run_mp_op_tests {
run_test "$_TEST_DIR/test_mp_replication.py"
run_test "$_TEST_DIR/test_mp_all_to_all.py"
run_test "$_TEST_DIR/test_mp_all_gather.py"
run_test "$_TEST_DIR/test_mp_reduce_scatter.py"
run_test "$_TEST_DIR/test_zero1.py"
run_test "$_TEST_DIR/test_mp_distributed_mm.py"
run_test "$_TEST_DIR/test_mp_save.py"
run_test "$_TEST_DIR/test_mp_mesh_reduce.py"
run_test "$_TEST_DIR/test_mp_sync_batch_norm.py"
# TODO(JackCaoG): enable this
run_test "$_TEST_DIR/dynamo/test_traceable_collectives.py"
run_test "$_TEST_DIR/test_fsdp_auto_wrap.py"
run_pt_xla_debug "$_TEST_DIR/debug_tool/test_mp_pt_xla_debug.py"
run_test "$_TEST_DIR/torch_distributed/test_torch_distributed_all_gather_xla_backend.py"
run_test "$_TEST_DIR/torch_distributed/test_torch_distributed_all_reduce_xla_backend.py"
run_test "$_TEST_DIR/torch_distributed/test_torch_distributed_bucketed_all_reduce_xla_backend.py"
run_test "$_TEST_DIR/torch_distributed/test_torch_distributed_multi_all_reduce_xla_backend.py"
run_test "$_TEST_DIR/torch_distributed/test_torch_distributed_reduce_scatter_xla_backend.py"
run_test "$_TEST_DIR/torch_distributed/test_ddp.py"
run_test "$_TEST_DIR/torch_distributed/test_torch_distributed_fsdp_meta.py"
}
function run_tests {
# RUN_ flags filter an explicit test type to run, XLA_SKIP_ flags exclude one.
if [[ "$RUN_XLA_OP_TESTS1" == "xla_op1" ]]; then
echo "Running xla op tests..."
run_xla_op_tests1
elif [[ "$RUN_XLA_OP_TESTS2" == "xla_op2" ]]; then
echo "Running xla op tests..."
run_xla_op_tests2
elif [[ "$RUN_XLA_OP_TESTS3" == "xla_op3" ]]; then
echo "Running xla op tests..."
run_xla_op_tests3
elif [[ "$RUN_XLA_OP_TESTS4" == "xla_op4" ]]; then
echo "Running xla op tests..."
run_xla_op_tests4
elif [[ "$RUN_XLA_OP_TESTS5" == "xla_op5" ]]; then
echo "Running xla op tests..."
run_xla_op_tests5
elif [[ "$RUN_TORCH_MP_OP_TESTS" == "torch_mp_op" ]]; then
echo "Running torch op tests..."
run_torch_op_tests
PJRT_DEVICE=CPU XLA_CUDA=0 run_mp_op_tests
else
# Run full tests without sharding, respects XLA_SKIP_*
if [[ "$XLA_SKIP_XLA_OP_TESTS" != "1" ]]; then
run_xla_op_tests1
run_xla_op_tests2
run_xla_op_tests3
run_xla_op_tests4
run_xla_op_tests5
fi
if [[ "$XLA_SKIP_TORCH_OP_TESTS" != "1" ]]; then
run_torch_op_tests
fi
if [[ "$XLA_SKIP_MP_OP_TESTS" != "1" ]]; then
run_mp_op_tests
fi
fi
}
set_test_filter $@
if [ "$LOGFILE" != "" ]; then
run_tests 2>&1 | tee $LOGFILE
else
run_tests
fi