-
Notifications
You must be signed in to change notification settings - Fork 20
2905 lines (2575 loc) · 122 KB
/
Copy pathpr-validation.yml
File metadata and controls
2905 lines (2575 loc) · 122 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: CI Validation (MUSA GPU)
on:
pull_request:
branches: [main, develop]
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
target_branch:
description: "Target branch to check rebase against (for manual run)"
required: false
default: "main"
type: string
commit_sha:
description: "Optional commit SHA to test instead of the workflow SHA"
required: false
default: ""
type: string
baseline_sha:
description: "Optional baseline commit SHA; leave empty to use latest upstream/main"
required: false
default: ""
type: string
schedule:
- cron: "0 14 * * *"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
defaults:
run:
shell: bash
env:
LOG_BASE: /home/runner/ci_logs
MODEL_ROOT: /home/runner/tf_test_model_wheel
BASELINE_REPO_URL: https://github.com/MooreThreads/tensorflow_musa_extension.git
EMPTY_TEST_RESULT_PATTERN: 'No tests found|No test files found|Total Tests:[[:space:]]*0|Total Tests[[:space:]]*│[[:space:]]*0|总计:[[:space:]]*0|no average_time_summary entries|report path missing|log not found'
MIN_INTEGRATION_TESTS: 500
jobs:
prepare_metadata:
name: Prepare Metadata
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 10
outputs:
commit_id: ${{ steps.collect.outputs.commit_id }}
requested_commit_id: ${{ steps.collect.outputs.requested_commit_id }}
requested_baseline_id: ${{ steps.collect.outputs.requested_baseline_id }}
run_kind: ${{ steps.collect.outputs.run_kind }}
run_id: ${{ steps.collect.outputs.run_id }}
workflow_run_id: ${{ steps.collect.outputs.workflow_run_id }}
workflow_run_attempt: ${{ steps.collect.outputs.workflow_run_attempt }}
log_root: ${{ steps.collect.outputs.log_root }}
host_name: ${{ steps.collect.outputs.host_name }}
host_ip: ${{ steps.collect.outputs.host_ip }}
host_sn: ${{ steps.collect.outputs.host_sn }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Prepare metadata
id: collect
run: |
set -euo pipefail
REQUESTED_COMMIT_ID="${{ github.event.inputs.commit_sha || '' }}"
REQUESTED_BASELINE_ID="${{ github.event.inputs.baseline_sha || '' }}"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
RUN_KIND="pr"
RUN_ID="${{ github.event.pull_request.head.sha }}"
EFFECTIVE_COMMIT_ID="${{ github.sha }}"
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
RUN_KIND="daily"
RUN_ID="$(date +%F)"
EFFECTIVE_COMMIT_ID="${{ github.sha }}"
else
RUN_KIND="manual"
EFFECTIVE_COMMIT_ID="${REQUESTED_COMMIT_ID:-${{ github.sha }}}"
if [[ -n "$REQUESTED_COMMIT_ID" ]]; then
RUN_ID="$REQUESTED_COMMIT_ID"
else
RUN_ID="${{ github.run_id }}"
fi
fi
WORKFLOW_RUN_ID="${{ github.run_id }}"
WORKFLOW_RUN_ATTEMPT="${{ github.run_attempt }}"
LOG_ROOT="$LOG_BASE/$RUN_KIND/$RUN_ID/run-$WORKFLOW_RUN_ID/attempt-$WORKFLOW_RUN_ATTEMPT"
JOB_LOG_DIR="$LOG_ROOT/prepare-metadata"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/prepare-metadata.md"
HOST_NAME="$(hostname)"
HOST_IP="$(hostname -I 2>/dev/null | awk '{print $1}' || true)"
if [[ -z "$HOST_IP" ]]; then
HOST_IP="$(hostname -i 2>/dev/null || true)"
fi
HOST_IP="${HOST_IP:-unavailable}"
HOST_SN="$(cat /sys/class/dmi/id/product_serial 2>/dev/null || true)"
HOST_SN="${HOST_SN:-unavailable}"
mkdir -p "$JOB_LOG_DIR"
{
echo "## Prepare Metadata"
echo
echo "- Commit: $EFFECTIVE_COMMIT_ID"
echo "- Requested commit override: ${REQUESTED_COMMIT_ID:-none}"
echo "- Requested baseline override: ${REQUESTED_BASELINE_ID:-none}"
echo "- Run kind: $RUN_KIND"
echo "- Run id: $RUN_ID"
echo "- Workflow run id: $WORKFLOW_RUN_ID"
echo "- Workflow run attempt: $WORKFLOW_RUN_ATTEMPT"
echo "- Log root: $LOG_ROOT"
echo "- Runner: $HOST_NAME"
echo "- Host IP: $HOST_IP"
echo "- Host SN: $HOST_SN"
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "commit_id=$EFFECTIVE_COMMIT_ID" >> "$GITHUB_OUTPUT"
echo "requested_commit_id=$REQUESTED_COMMIT_ID" >> "$GITHUB_OUTPUT"
echo "requested_baseline_id=$REQUESTED_BASELINE_ID" >> "$GITHUB_OUTPUT"
echo "run_kind=$RUN_KIND" >> "$GITHUB_OUTPUT"
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
echo "workflow_run_id=$WORKFLOW_RUN_ID" >> "$GITHUB_OUTPUT"
echo "workflow_run_attempt=$WORKFLOW_RUN_ATTEMPT" >> "$GITHUB_OUTPUT"
echo "log_root=$LOG_ROOT" >> "$GITHUB_OUTPUT"
echo "host_name=$HOST_NAME" >> "$GITHUB_OUTPUT"
echo "host_ip=$HOST_IP" >> "$GITHUB_OUTPUT"
echo "host_sn=$HOST_SN" >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
format:
name: Format Check
needs: prepare_metadata
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 20
outputs:
status: ${{ steps.collect.outputs.status }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Checkout code
run: |
set -euo pipefail
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
COMMIT_ID="${{ needs.prepare_metadata.outputs.commit_id }}"
cd "${RUNNER_TEMP:-/tmp}"
rm -rf "$GITHUB_WORKSPACE"
mkdir -p "$GITHUB_WORKSPACE"
cd "$GITHUB_WORKSPACE"
git init -q
git remote add origin "$REPO_URL"
if git fetch --no-tags --prune --depth=1 origin "$COMMIT_ID"; then
git checkout --force FETCH_HEAD
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch --no-tags --prune --depth=1 origin "refs/pull/${{ github.event.pull_request.number }}/merge"
git checkout --force FETCH_HEAD
else
git fetch --no-tags --prune origin '+refs/heads/*:refs/remotes/origin/*'
git checkout --force "$COMMIT_ID"
fi
git config --global --add safe.directory "$GITHUB_WORKSPACE" || true
git clean -fdx
git --no-pager log -1 --oneline
- name: Run format check
id: run_check
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/format"
LOG_FILE="$JOB_LOG_DIR/format_check.log"
mkdir -p "$JOB_LOG_DIR"
format_exit=0
export JOB_LOG_DIR LOG_FILE
bash -l -c '
set -o pipefail
cd "$GITHUB_WORKSPACE"
FILE_LIST=$(mktemp)
find . \( -path ./build -o -path ./.git \) -prune -o \
-regex ".*\.\(cc\|cpp\|hpp\|c\|h\|cu\)" -print0 > "$FILE_LIST"
if [[ ! -s "$FILE_LIST" ]]; then
echo "No C/C++ files to format-check." | tee "$LOG_FILE"
else
xargs -0 clang-format --Werror --dry-run < "$FILE_LIST" 2>&1 | tee "$LOG_FILE"
fi
' || format_exit=$?
echo "format_exit=$format_exit" >> "$GITHUB_OUTPUT"
- name: Collect format summary
id: collect
if: always()
run: |
set -euo pipefail
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/format"
LOG_FILE="$JOB_LOG_DIR/format_check.log"
LOG_ROOT="${{ needs.prepare_metadata.outputs.log_root }}"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/format.md"
STATUS="success"
JOB_RESULT="success (non-blocking)"
if [[ "${{ steps.run_check.outputs.format_exit }}" != "0" ]]; then
STATUS="failure"
echo "::warning::Format check failed. This job remains non-blocking."
fi
{
echo "## Format Check"
echo
echo "- Job result: $JOB_RESULT"
echo "- Format check result: $STATUS"
echo "- Non-blocking: yes"
echo "- Log file: $LOG_FILE"
echo
echo '```text'
if [[ -f "$LOG_FILE" ]]; then
tail -50 "$LOG_FILE" || true
else
echo "format log not found"
fi
echo '```'
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
build_current:
name: Build Current
needs: prepare_metadata
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 120
outputs:
status: ${{ steps.collect.outputs.status }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Checkout code
run: |
set -euo pipefail
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
COMMIT_ID="${{ needs.prepare_metadata.outputs.commit_id }}"
cd "${RUNNER_TEMP:-/tmp}"
rm -rf "$GITHUB_WORKSPACE"
mkdir -p "$GITHUB_WORKSPACE"
cd "$GITHUB_WORKSPACE"
git init -q
git remote add origin "$REPO_URL"
if git fetch --no-tags --prune --depth=1 origin "$COMMIT_ID"; then
git checkout --force FETCH_HEAD
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch --no-tags --prune --depth=1 origin "refs/pull/${{ github.event.pull_request.number }}/merge"
git checkout --force FETCH_HEAD
else
git fetch --no-tags --prune origin '+refs/heads/*:refs/remotes/origin/*'
git checkout --force "$COMMIT_ID"
fi
git config --global --add safe.directory "$GITHUB_WORKSPACE" || true
git clean -fdx
git --no-pager log -1 --oneline
- name: Build current wheel
id: run_build
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/build-current"
LOG_FILE="$JOB_LOG_DIR/build_current.log"
mkdir -p "$JOB_LOG_DIR"
build_exit=0
export LOG_FILE
bash -l -c '
set -o pipefail
export CPLUS_INCLUDE_PATH="/usr/include/c++/11:/usr/include/x86_64-linux-gnu/c++/11:${CPLUS_INCLUDE_PATH:-}"
cd "$GITHUB_WORKSPACE"
rm -rf ./build ./dist
./build.sh wheel 2>&1 | tee "$LOG_FILE"
' || build_exit=$?
echo "build_exit=$build_exit" >> "$GITHUB_OUTPUT"
- name: Collect build summary
id: collect
if: always()
run: |
set -euo pipefail
LOG_ROOT="${{ needs.prepare_metadata.outputs.log_root }}"
JOB_LOG_DIR="$LOG_ROOT/build-current"
LOG_FILE="$JOB_LOG_DIR/build_current.log"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/build-current.md"
WHEEL_PATH="$(find "$GITHUB_WORKSPACE/dist" -maxdepth 1 -name 'tensorflow_musa-*.whl' -print -quit 2>/dev/null || true)"
STATUS="success"
if [[ "${{ steps.run_build.outputs.build_exit }}" != "0" || -z "$WHEEL_PATH" ]]; then
STATUS="failure"
else
WHEEL_DEST="$LOG_ROOT/wheels/current"
mkdir -p "$WHEEL_DEST"
cp "$WHEEL_PATH" "$WHEEL_DEST/"
fi
WHEEL_SIZE="$(stat -c%s "$WHEEL_PATH" 2>/dev/null || echo "n/a")"
{
echo "## Build Current"
echo
echo "- Status: $STATUS"
echo "- Wheel path: ${WHEEL_PATH:-not found}"
echo "- Wheel size: $WHEEL_SIZE"
echo "- Log file: $LOG_FILE"
echo
echo '```text'
if [[ -f "$LOG_FILE" ]]; then
tail -50 "$LOG_FILE" || true
else
echo "build log not found"
fi
echo '```'
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
- name: Fail job if build failed
if: always() && steps.collect.outputs.status == 'failure'
run: exit 1
build_baseline:
name: Build Baseline
needs: prepare_metadata
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 120
outputs:
status: ${{ steps.collect.outputs.status }}
baseline_sha: ${{ steps.collect.outputs.baseline_sha }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Sync and build baseline
id: run_build
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/build-baseline"
LOG_FILE="$JOB_LOG_DIR/build_baseline.log"
mkdir -p "$JOB_LOG_DIR"
sync_exit=0
build_exit=0
baseline_sha=""
BASELINE_WORKSPACE="$JOB_LOG_DIR/baseline-workspace"
echo "baseline_workspace=$BASELINE_WORKSPACE" >> "$GITHUB_OUTPUT"
export LOG_FILE BASELINE_WORKSPACE BASELINE_REPO_URL
bash -l -c '
BASELINE_PARENT=$(dirname "$BASELINE_WORKSPACE")
mkdir -p "$BASELINE_PARENT"
if [[ ! -d "$BASELINE_WORKSPACE/.git" ]]; then
git clone "$BASELINE_REPO_URL" "$BASELINE_WORKSPACE"
fi
cd "$BASELINE_WORKSPACE"
if git remote get-url upstream >/dev/null 2>&1; then
git remote set-url upstream "$BASELINE_REPO_URL"
else
git remote add upstream "$BASELINE_REPO_URL"
fi
git fetch upstream
if [[ -n "${{ needs.prepare_metadata.outputs.requested_baseline_id }}" ]]; then
git reset --hard "${{ needs.prepare_metadata.outputs.requested_baseline_id }}"
else
git reset --hard upstream/main
fi
git clean -fdx
' || sync_exit=$?
if [[ "$sync_exit" == "0" ]]; then
baseline_sha="$(git -C "$BASELINE_WORKSPACE" rev-parse HEAD 2>/dev/null || true)"
export LOG_FILE BASELINE_WORKSPACE
bash -l -c '
set -o pipefail
export CPLUS_INCLUDE_PATH="/usr/include/c++/11:/usr/include/x86_64-linux-gnu/c++/11:${CPLUS_INCLUDE_PATH:-}"
cd "$BASELINE_WORKSPACE"
rm -rf ./build ./dist
./build.sh wheel 2>&1 | tee "$LOG_FILE"
' || build_exit=$?
fi
echo "sync_exit=$sync_exit" >> "$GITHUB_OUTPUT"
echo "build_exit=$build_exit" >> "$GITHUB_OUTPUT"
echo "baseline_sha=$baseline_sha" >> "$GITHUB_OUTPUT"
- name: Collect build summary
id: collect
if: always()
run: |
set -euo pipefail
LOG_ROOT="${{ needs.prepare_metadata.outputs.log_root }}"
JOB_LOG_DIR="$LOG_ROOT/build-baseline"
LOG_FILE="$JOB_LOG_DIR/build_baseline.log"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/build-baseline.md"
BASELINE_WORKSPACE="${{ steps.run_build.outputs.baseline_workspace }}"
WHEEL_PATH="$(find "$BASELINE_WORKSPACE/dist" -maxdepth 1 -name 'tensorflow_musa-*.whl' -print -quit 2>/dev/null || true)"
BASELINE_SHA="${{ steps.run_build.outputs.baseline_sha }}"
if [[ -z "$BASELINE_SHA" && -d "$BASELINE_WORKSPACE/.git" ]]; then
BASELINE_SHA="$(git -C "$BASELINE_WORKSPACE" rev-parse HEAD 2>/dev/null || true)"
fi
STATUS="success"
if [[ "${{ steps.run_build.outputs.sync_exit }}" != "0" || "${{ steps.run_build.outputs.build_exit }}" != "0" || -z "$WHEEL_PATH" ]]; then
STATUS="failure"
else
WHEEL_DEST="$LOG_ROOT/wheels/baseline"
mkdir -p "$WHEEL_DEST"
cp "$WHEEL_PATH" "$WHEEL_DEST/"
fi
WHEEL_SIZE="$(stat -c%s "$WHEEL_PATH" 2>/dev/null || echo "n/a")"
{
echo "## Build Baseline"
echo
echo "- Status: $STATUS"
echo "- Baseline commit: ${BASELINE_SHA:-unavailable}"
echo "- Wheel path: ${WHEEL_PATH:-not found}"
echo "- Wheel size: $WHEEL_SIZE"
echo "- Log file: $LOG_FILE"
echo
echo '```text'
if [[ -f "$LOG_FILE" ]]; then
tail -50 "$LOG_FILE" || true
else
echo "build log not found"
fi
echo '```'
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
echo "baseline_sha=$BASELINE_SHA" >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
- name: Fail job if build failed
if: always() && steps.collect.outputs.status == 'failure'
run: exit 1
integration:
name: Integration Test
needs: [prepare_metadata, build_current]
if: needs.prepare_metadata.result == 'success' && needs.build_current.result == 'success'
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 45
outputs:
status: ${{ steps.collect.outputs.status }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Checkout code
run: |
set -euo pipefail
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
COMMIT_ID="${{ needs.prepare_metadata.outputs.commit_id }}"
cd "${RUNNER_TEMP:-/tmp}"
rm -rf "$GITHUB_WORKSPACE"
mkdir -p "$GITHUB_WORKSPACE"
cd "$GITHUB_WORKSPACE"
git init -q
git remote add origin "$REPO_URL"
if git fetch --no-tags --prune --depth=1 origin "$COMMIT_ID"; then
git checkout --force FETCH_HEAD
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch --no-tags --prune --depth=1 origin "refs/pull/${{ github.event.pull_request.number }}/merge"
git checkout --force FETCH_HEAD
else
git fetch --no-tags --prune origin '+refs/heads/*:refs/remotes/origin/*'
git checkout --force "$COMMIT_ID"
fi
git config --global --add safe.directory "$GITHUB_WORKSPACE" || true
git clean -fdx
git --no-pager log -1 --oneline
- name: Run integration tests
id: run_test
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/integration"
LOG_FILE="$JOB_LOG_DIR/integration_fusion_tests.log"
mkdir -p "$JOB_LOG_DIR"
test_exit=0
export LOG_FILE WHEEL_DIR="${{ needs.prepare_metadata.outputs.log_root }}/wheels/current"
bash -l <<'BASH' || test_exit=$?
set -e -o pipefail
cd "$GITHUB_WORKSPACE"
pip install "$WHEEL_DIR"/tensorflow_musa-*.whl --no-deps --force-reinstall 2>&1 | tee "$LOG_FILE"
cd "$GITHUB_WORKSPACE/test"
python - <<'PY' 2>&1 | tee -a "$LOG_FILE"
import importlib
import pathlib
import sys
import unittest
test_dir = pathlib.Path("ops")
test_files = sorted(test_dir.glob("*_op_test.py"))
if not test_files:
print("No test files found matching pattern: *_op_test.py in ops/")
sys.exit(1)
sys.path.insert(0, str(test_dir.resolve()))
loader = unittest.TestLoader()
load_failures = []
total_tests = 0
for test_file in test_files:
module_name = test_file.stem
try:
module = importlib.import_module(module_name)
total_tests += loader.loadTestsFromModule(module).countTestCases()
except Exception as exc:
load_failures.append((module_name, exc))
if load_failures:
print(f"Failed to load {len(load_failures)} test module(s):")
for module_name, error in load_failures:
print(f" ops/{module_name}: {error}")
sys.exit(1)
print(f"Discovered test cases: {total_tests}")
if total_tests == 0:
print("No tests found")
sys.exit(1)
PY
timeout 60m python test_runner.py --quiet 2>&1 | tee -a "$LOG_FILE"
BASH
echo "test_exit=$test_exit" >> "$GITHUB_OUTPUT"
- name: Collect integration summary
id: collect
if: always()
run: |
set -euo pipefail
LOG_ROOT="${{ needs.prepare_metadata.outputs.log_root }}"
JOB_LOG_DIR="$LOG_ROOT/integration"
LOG_FILE="$JOB_LOG_DIR/integration_fusion_tests.log"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/integration.md"
STATUS="success"
if [[ "${{ steps.run_test.outputs.test_exit }}" != "0" ]]; then
STATUS="failure"
fi
if [[ ! -f "$LOG_FILE" ]]; then
STATUS="failure"
elif grep -Eq "$EMPTY_TEST_RESULT_PATTERN" "$LOG_FILE"; then
STATUS="failure"
else
total_tests="$(grep -E "Total Tests[[:space:]]*(\||│|:)[[:space:]]*[0-9]+" "$LOG_FILE" | tail -1 | grep -oE "[0-9]+" | tail -1 || true)"
if [[ -z "$total_tests" || "$total_tests" -lt "$MIN_INTEGRATION_TESTS" ]]; then
STATUS="failure"
fi
fi
{
echo "## Integration Test"
echo
echo "- Status: $STATUS"
echo "- Log file: $LOG_FILE"
echo
echo '```text'
if [[ -f "$LOG_FILE" ]]; then
grep -E "Total Tests|Passed|Failed|Errors|Skipped|Pass Rate|Execution Time" "$LOG_FILE" || tail -80 "$LOG_FILE" || true
else
echo "integration log not found"
fi
echo '```'
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
- name: Fail job if integration failed
if: always() && steps.collect.outputs.status == 'failure'
run: exit 1
t_perf:
name: T Performance
needs: [prepare_metadata, build_current, build_baseline]
if: needs.prepare_metadata.result == 'success' && needs.build_current.result == 'success' && needs.build_baseline.result == 'success'
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 60
outputs:
status: ${{ steps.collect.outputs.status }}
baseline_ms: ${{ steps.collect.outputs.baseline_ms }}
current_ms: ${{ steps.collect.outputs.current_ms }}
threshold_ms: ${{ steps.collect.outputs.threshold_ms }}
metrics_summary: ${{ steps.collect.outputs.metrics_summary }}
metrics_json: ${{ steps.collect.outputs.metrics_json }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Run T performance baseline/current
id: run_perf
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/t-perf"
BASELINE_LOG="$JOB_LOG_DIR/t_perf_baseline.log"
CURRENT_LOG="$JOB_LOG_DIR/t_perf_current.log"
mkdir -p "$JOB_LOG_DIR"
rm -f "$BASELINE_LOG" "$CURRENT_LOG"
baseline_exit=0
current_exit=0
guard_failed=0
if [[ -z "${GPU_LOCK_FILE:-}" ]]; then
echo "GPU_LOCK_FILE is not set; refusing to use a global GPU lock." | tee -a "$BASELINE_LOG"
guard_failed=1
lock_file=""
else
lock_file="$GPU_LOCK_FILE"
fi
export MODEL_ROOT JOB_LOG_DIR BASELINE_LOG CURRENT_LOG
if [[ "$guard_failed" == "0" ]]; then
exec 9>"$lock_file"
flock 9
echo "Acquired GPU test lock: $lock_file" | tee -a "$BASELINE_LOG"
pip install "${{ needs.prepare_metadata.outputs.log_root }}"/wheels/baseline/tensorflow_musa-*.whl --no-deps --force-reinstall 2>&1 | tee -a "$BASELINE_LOG"
bash -l -c '
set -o pipefail
cd "$MODEL_ROOT/inference/prunedGraph"
timeout 20m python run_inference.py \
--device musa \
--batch-size 1024 \
--infer-iters 1000 2>&1 | tee "$BASELINE_LOG"
' || baseline_exit=$?
pip install "${{ needs.prepare_metadata.outputs.log_root }}"/wheels/current/tensorflow_musa-*.whl --no-deps --force-reinstall 2>&1 | tee -a "$CURRENT_LOG"
bash -l -c '
set -o pipefail
cd "$MODEL_ROOT/inference/prunedGraph"
timeout 20m python run_inference.py \
--device musa \
--batch-size 100 \
--infer-iters 1000 2>&1 | tee "$CURRENT_LOG"
' || current_exit=$?
else
baseline_exit=1
current_exit=1
fi
echo "baseline_exit=$baseline_exit" >> "$GITHUB_OUTPUT"
echo "current_exit=$current_exit" >> "$GITHUB_OUTPUT"
- name: Collect T performance summary
id: collect
if: always()
run: |
set -euo pipefail
LOG_ROOT="${{ needs.prepare_metadata.outputs.log_root }}"
JOB_LOG_DIR="$LOG_ROOT/t-perf"
BASELINE_LOG="$JOB_LOG_DIR/t_perf_baseline.log"
CURRENT_LOG="$JOB_LOG_DIR/t_perf_current.log"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/t-perf.md"
STATUS="success"
BASELINE_MS=""
CURRENT_MS=""
THRESHOLD_MS=""
METRICS_SUMMARY=""
METRICS_JSON=""
RUNNER_NAME="${RUNNER_NAME:-unknown}"
HOST_NAME="$(hostname)"
HOST_IP="$(hostname -I 2>/dev/null | awk '{print $1}' || true)"
HOST_SN="$(cat /sys/class/dmi/id/product_serial 2>/dev/null || true)"
HOST_IP="${HOST_IP:-unavailable}"
HOST_SN="${HOST_SN:-unavailable}"
if [[ "${{ steps.run_perf.outputs.baseline_exit }}" == "0" && -f "$BASELINE_LOG" ]]; then
BASELINE_MS="$(python3 -c 'import pathlib,re,sys; text=pathlib.Path(sys.argv[1]).read_text(encoding="utf-8", errors="ignore"); matches=re.findall(r"平均:\s*([0-9]+(?:\.[0-9]+)?)\s*ms", text); print(matches[-1] if matches else "")' "$BASELINE_LOG" || true)"
fi
if [[ "${{ steps.run_perf.outputs.current_exit }}" == "0" && -f "$CURRENT_LOG" ]]; then
CURRENT_MS="$(python3 -c 'import pathlib,re,sys; text=pathlib.Path(sys.argv[1]).read_text(encoding="utf-8", errors="ignore"); matches=re.findall(r"平均:\s*([0-9]+(?:\.[0-9]+)?)\s*ms", text); print(matches[-1] if matches else "")' "$CURRENT_LOG" || true)"
fi
if [[ "${{ steps.run_perf.outputs.baseline_exit }}" != "0" || "${{ steps.run_perf.outputs.current_exit }}" != "0" || -z "$BASELINE_MS" || -z "$CURRENT_MS" ]]; then
STATUS="failure"
else
THRESHOLD_MS="$(awk -v base="$BASELINE_MS" 'BEGIN {printf "%.4f", base * 1.05}')"
if awk -v cur="$CURRENT_MS" -v thr="$THRESHOLD_MS" 'BEGIN {exit !(cur > thr)}'; then
STATUS="failure"
fi
fi
METRICS_SUMMARY="baseline=${BASELINE_MS:-n/a} ms, current=${CURRENT_MS:-n/a} ms, threshold=${THRESHOLD_MS:-n/a} ms, result=${STATUS}"
METRICS_JSON="$(python3 - "$STATUS" "$BASELINE_MS" "$CURRENT_MS" "$THRESHOLD_MS" <<'PY'
import json
import sys
status, baseline_ms, current_ms, threshold_ms = sys.argv[1:5]
payload = {
"name": "T Performance",
"kind": "single",
"status": status,
"baseline_ms": baseline_ms or "n/a",
"current_ms": current_ms or "n/a",
"threshold_ms": threshold_ms or "n/a",
}
print(json.dumps(payload, ensure_ascii=False, separators=(",", ":")))
PY
)"
{
echo "## T Performance"
echo
echo "- Status: $STATUS"
echo "- Runner name: $RUNNER_NAME"
echo "- Host name: $HOST_NAME"
echo "- Host IP: $HOST_IP"
echo "- Host SN: $HOST_SN"
echo "- Log artifact: logs-t-perf"
echo "- Baseline: ${BASELINE_MS:-n/a} ms"
echo "- Current: ${CURRENT_MS:-n/a} ms"
echo "- Threshold: ${THRESHOLD_MS:-n/a} ms"
echo
echo "### Baseline log tail"
echo '```text'
if [[ -f "$BASELINE_LOG" ]]; then
tail -20 "$BASELINE_LOG" || true
else
echo "baseline log not found"
fi
echo '```'
echo
echo "### Current log tail"
echo '```text'
if [[ -f "$CURRENT_LOG" ]]; then
tail -20 "$CURRENT_LOG" || true
else
echo "current log not found"
fi
echo '```'
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
echo "baseline_ms=$BASELINE_MS" >> "$GITHUB_OUTPUT"
echo "current_ms=$CURRENT_MS" >> "$GITHUB_OUTPUT"
echo "threshold_ms=$THRESHOLD_MS" >> "$GITHUB_OUTPUT"
echo "metrics_summary=$METRICS_SUMMARY" >> "$GITHUB_OUTPUT"
{
echo "metrics_json<<EOF"
echo "$METRICS_JSON"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
- name: Fail job if T performance regressed
if: always() && steps.collect.outputs.status == 'failure'
run: exit 1
t_accuracy:
name: T Accuracy
needs: [prepare_metadata, build_current]
if: needs.prepare_metadata.result == 'success' && needs.build_current.result == 'success'
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 30
outputs:
status: ${{ steps.collect.outputs.status }}
current_acc: ${{ steps.collect.outputs.current_acc }}
metrics_json: ${{ steps.collect.outputs.metrics_json }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Install current wheel
run: pip install "${{ needs.prepare_metadata.outputs.log_root }}"/wheels/current/tensorflow_musa-*.whl --no-deps --force-reinstall
- name: Run T accuracy current only
id: run_acc
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/t-accuracy"
CURRENT_LOG="$JOB_LOG_DIR/t_accuracy_current.log"
mkdir -p "$JOB_LOG_DIR"
rm -f "$CURRENT_LOG"
current_exit=0
guard_failed=0
if [[ -z "${GPU_LOCK_FILE:-}" ]]; then
echo "GPU_LOCK_FILE is not set; refusing to use a global GPU lock." | tee -a "$CURRENT_LOG"
guard_failed=1
lock_file=""
else
lock_file="$GPU_LOCK_FILE"
fi
export MODEL_ROOT JOB_LOG_DIR CURRENT_LOG
if [[ "$guard_failed" == "0" ]]; then
exec 9>"$lock_file"
flock 9
echo "Acquired GPU test lock: $lock_file" | tee -a "$CURRENT_LOG"
bash -l -c '
set -o pipefail
cd "$MODEL_ROOT/inference/prunedGraph"
TF_ENABLE_ONEDNN_OPTS=0 \
MUSA_ENABLE_TF32=0 \
timeout 20m python run_inference.py \
--device musa \
--batch-size 100 \
--check-acc \
--rtol 1e-2 \
--atol 1e-2 2>&1 | tee "$CURRENT_LOG"
' || current_exit=$?
else
current_exit=1
fi
echo "current_exit=$current_exit" >> "$GITHUB_OUTPUT"
- name: Collect T accuracy summary
id: collect
if: always()
run: |
set -euo pipefail
LOG_ROOT="${{ needs.prepare_metadata.outputs.log_root }}"
JOB_LOG_DIR="$LOG_ROOT/t-accuracy"
CURRENT_LOG="$JOB_LOG_DIR/t_accuracy_current.log"
mkdir -p "$LOG_ROOT/summaries"
SUMMARY_FILE="$LOG_ROOT/summaries/t-accuracy.md"
STATUS="success"
CURRENT_ACC="$(grep -E "整体状态:.*(PASSED|FAILED)" "$CURRENT_LOG" | tail -1 | grep -oE "PASSED|FAILED" || echo "n/a")"
METRICS_JSON=""
RUNNER_NAME="${RUNNER_NAME:-unknown}"
HOST_NAME="$(hostname)"
HOST_IP="$(hostname -I 2>/dev/null | awk '{print $1}' || true)"
HOST_SN="$(cat /sys/class/dmi/id/product_serial 2>/dev/null || true)"
HOST_IP="${HOST_IP:-unavailable}"
HOST_SN="${HOST_SN:-unavailable}"
if [[ "${{ steps.run_acc.outputs.current_exit }}" != "0" ]]; then
STATUS="failure"
fi
if [[ "$CURRENT_ACC" != *"PASSED"* ]]; then
STATUS="failure"
fi
METRICS_JSON="$(python3 - "$STATUS" "$CURRENT_ACC" <<'PY'
import json
import sys
status, current_acc = sys.argv[1:3]
payload = {
"name": "T Accuracy",
"kind": "accuracy",
"status": status,
"current": current_acc or "n/a",
}
print(json.dumps(payload, ensure_ascii=False, separators=(",", ":")))
PY
)"
{
echo "## T Accuracy"
echo
echo "- Status: $STATUS"
echo "- Runner name: $RUNNER_NAME"
echo "- Host name: $HOST_NAME"
echo "- Host IP: $HOST_IP"
echo "- Host SN: $HOST_SN"
echo "- Log artifact: logs-t-accuracy"
echo "- Current: ${CURRENT_ACC:-unavailable}"
echo
echo "### Current highlights"
echo '```text'
if [[ -f "$CURRENT_LOG" ]]; then
grep -E '整体状态:|PASSED|FAILED|rtol|atol|误差|差异' "$CURRENT_LOG" | tail -20 || true
else
echo "current log not found"
fi
echo '```'
} | tee "$SUMMARY_FILE"
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
echo "current_acc=$CURRENT_ACC" >> "$GITHUB_OUTPUT"
{
echo "metrics_json<<EOF"
echo "$METRICS_JSON"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "summary_file=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
- name: Fail job if T accuracy failed
if: always() && steps.collect.outputs.status == 'failure'
run: exit 1
bd_model1:
name: BD Model 1
needs: [prepare_metadata, build_current, build_baseline]
if: needs.prepare_metadata.result == 'success' && needs.build_current.result == 'success' && needs.build_baseline.result == 'success'
runs-on: [self-hosted, musa-gpu]
timeout-minutes: 75
outputs:
status: ${{ steps.collect.outputs.status }}
baseline_ms: ${{ steps.collect.outputs.baseline_ms }}
current_ms: ${{ steps.collect.outputs.current_ms }}
threshold_ms: ${{ steps.collect.outputs.threshold_ms }}
metrics_summary: ${{ steps.collect.outputs.metrics_summary }}
metrics_json: ${{ steps.collect.outputs.metrics_json }}
summary_file: ${{ steps.collect.outputs.summary_file }}
steps:
- name: Run model 1 baseline/current
id: run_perf
run: |
set +e
JOB_LOG_DIR="${{ needs.prepare_metadata.outputs.log_root }}/bd-model1"
BASELINE_LOG="$JOB_LOG_DIR/bd_model1_baseline.log"
CURRENT_LOG="$JOB_LOG_DIR/bd_model1_current.log"
SPEC_PATH="$MODEL_ROOT/inference/metaGraph/meta_graph/meta_graph_1.spec"
mkdir -p "$JOB_LOG_DIR"
rm -f "$BASELINE_LOG" "$CURRENT_LOG"
rm -rf "$JOB_LOG_DIR/baseline-out" "$JOB_LOG_DIR/current-out"
baseline_exit=0
current_exit=0
guard_failed=0
if [[ -z "${GPU_LOCK_FILE:-}" ]]; then
echo "GPU_LOCK_FILE is not set; refusing to use a global GPU lock." | tee -a "$BASELINE_LOG"
guard_failed=1
lock_file=""
else
lock_file="$GPU_LOCK_FILE"
fi
export MODEL_ROOT JOB_LOG_DIR BASELINE_LOG CURRENT_LOG SPEC_PATH
if [[ "$guard_failed" == "0" ]]; then
exec 9>"$lock_file"
flock 9
echo "Acquired GPU test lock: $lock_file" | tee -a "$BASELINE_LOG"
pip install "${{ needs.prepare_metadata.outputs.log_root }}"/wheels/baseline/tensorflow_musa-*.whl --no-deps --force-reinstall 2>&1 | tee -a "$BASELINE_LOG"
bash -l -c '
set -o pipefail
cd "$MODEL_ROOT/inference/metaGraph"
MUSA_PINNED_FEED=1 \
MUSA_PINNED_H2D_ON_COMPUTE_STREAM=1 \
timeout 30m python musa_run_pb_graph.py \
--spec "$SPEC_PATH" \
--bs 32,128,256,1024 \
--run_iters 30 \
--out_root "$JOB_LOG_DIR/baseline-out" 2>&1 | tee "$BASELINE_LOG"
' || baseline_exit=$?
pip install "${{ needs.prepare_metadata.outputs.log_root }}"/wheels/current/tensorflow_musa-*.whl --no-deps --force-reinstall 2>&1 | tee -a "$CURRENT_LOG"
bash -l -c '