-
Notifications
You must be signed in to change notification settings - Fork 5
185 lines (161 loc) · 8.29 KB
/
Copy pathbuild_ai_layer.yml
File metadata and controls
185 lines (161 loc) · 8.29 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
name: Build AI Layer
on:
push:
paths:
- 'model/**'
workflow_dispatch:
permissions:
contents: write
packages: write
id-token: write
attestations: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/executorch-arm-container
jobs:
check-docker-image:
runs-on: ubuntu-latest
outputs:
image-exists: ${{ steps.check.outputs.exists }}
repo-slug: ${{ steps.slug.outputs.repo_slug }}
steps:
- name: Derive lowercase repo slug
id: slug
run: echo "repo_slug=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Check if Docker image exists
id: check
run: |
if docker manifest inspect ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')/executorch-arm-container:latest > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
build-docker-if-needed:
needs: check-docker-image
if: needs.check-docker-image.outputs.image-exists == 'false'
uses: ./.github/workflows/build_docker.yml
permissions:
contents: read # must be >= permissions requested by called workflow
packages: write
id-token: write
# attestations: write # uncomment if attestation step in called workflow is enabled
secrets: inherit
build-ai-layer:
needs: [check-docker-image, build-docker-if-needed]
if: always() && (needs.check-docker-image.outputs.image-exists == 'true' || needs.build-docker-if-needed.result == 'success')
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ needs.check-docker-image.outputs.repo-slug }}/executorch-arm-container:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
GIT_AUTHOR_EMAIL: "action@github.com"
GIT_AUTHOR_NAME: "GitHub Action"
GIT_COMMITTER_EMAIL: "action@github.com"
GIT_COMMITTER_NAME: "GitHub Action"
steps:
- name: Export lowercase repo slug env
run: echo "REPO_SLUG=${{ needs.check-docker-image.outputs.repo-slug }}" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup git config and logging
run: |
git config --global --add safe.directory /github/workspace
# Setup logging directory
mkdir -p $GITHUB_WORKSPACE/ai_layer/logs
export BUILD_TIMESTAMP=$(date '+%Y%m%d_%H%M%S')
echo "BUILD_TIMESTAMP=$BUILD_TIMESTAMP" >> $GITHUB_ENV
echo "LOG_DIR=$GITHUB_WORKSPACE/ai_layer/logs" >> $GITHUB_ENV
echo "MAIN_LOG=$GITHUB_WORKSPACE/ai_layer/logs/build.log" >> $GITHUB_ENV
# Log build start
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] ExecuTorch AI Layer Build Started (GitHub Actions)" | tee $GITHUB_WORKSPACE/ai_layer/logs/build.log
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Timestamp: $BUILD_TIMESTAMP" | tee -a $GITHUB_WORKSPACE/ai_layer/logs/build.log
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Workflow: ${{ github.workflow }}" | tee -a $GITHUB_WORKSPACE/ai_layer/logs/build.log
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Run ID: ${{ github.run_id }}" | tee -a $GITHUB_WORKSPACE/ai_layer/logs/build.log
- name: Convert and build model
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Starting: Model conversion" | tee -a $MAIN_LOG
cd $GITHUB_WORKSPACE/model && python3 aot_model.py 2>&1 | tee $LOG_DIR/model_conversion.log $MAIN_LOG
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Completed: Model conversion" | tee -a $MAIN_LOG
- name: Build ExecuTorch Core Libraries
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Starting: Stage1 build" | tee -a $MAIN_LOG
$GITHUB_WORKSPACE/scripts/build_stage1.sh /workspace/executorch \
$GITHUB_WORKSPACE/out/stage1 \
$GITHUB_WORKSPACE/model/arm-none-eabi-gcc.cmake 2>&1 | tee $LOG_DIR/stage1_build.log $MAIN_LOG
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Completed: Stage1 build" | tee -a $MAIN_LOG
- name: Build ExecuTorch Selective Kernel Libraries
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Starting: Stage2 build" | tee -a $MAIN_LOG
$GITHUB_WORKSPACE/scripts/build_stage2_selective.sh \
/workspace/executorch \
"" \
$GITHUB_WORKSPACE/out/stage2 \
$GITHUB_WORKSPACE/model/arm-none-eabi-gcc.cmake \
$GITHUB_WORKSPACE/model/operators_minimal.txt 2>&1 | tee $LOG_DIR/stage2_build.log $MAIN_LOG
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Completed: Stage2 build" | tee -a $MAIN_LOG
- name: Collect artifacts
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Starting: Package artifacts" | tee -a $MAIN_LOG
cd "$GITHUB_WORKSPACE" && ./scripts/package_sdk.sh \
"$GITHUB_WORKSPACE/out/stage1/assets" \
"$GITHUB_WORKSPACE/out/stage2/assets" \
"$GITHUB_WORKSPACE/model/ethos_u_minimal_example.pte" \
"$GITHUB_WORKSPACE/ai_layer/engine" 2>&1 | tee $LOG_DIR/package_artifacts.log $MAIN_LOG
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Completed: Package artifacts" | tee -a $MAIN_LOG
- name: Convert the model to a header file
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Starting: Model to header conversion" | tee -a $MAIN_LOG
cd "$GITHUB_WORKSPACE" && python3 scripts/pte_to_header.py -p model/ethos_u_minimal_example.pte -d ai_layer/model -o model_pte.h 2>&1 | tee $LOG_DIR/model_to_header.log $MAIN_LOG
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Completed: Model to header conversion" | tee -a $MAIN_LOG
- name: Generate AI layer report
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Starting: Generate report" | tee -a $MAIN_LOG
python3 scripts/generate_ai_layer_report.py 2>&1 | tee $LOG_DIR/generate_report.log $MAIN_LOG || { echo "$(date '+%Y-%m-%d %H:%M:%S') [ERROR] Report generation failed" | tee -a $MAIN_LOG; exit 1; }
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Completed: Generate report" | tee -a $MAIN_LOG
- name: Show report summary and finalize logs
run: |
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] Build summary:" | tee -a $MAIN_LOG
head -n 50 ai_layer/REPORT.md | tee -a $MAIN_LOG || echo "Report could not be displayed" | tee -a $MAIN_LOG
# Create build summary
cat > $LOG_DIR/build_summary.txt << EOF
ExecuTorch AI Layer Build Summary (GitHub Actions)
==================================================
Build Timestamp: $BUILD_TIMESTAMP
Workflow: ${{ github.workflow }}
Run ID: ${{ github.run_id }}
Commit: ${{ github.sha }}
Branch: ${{ github.ref }}
Build Status: SUCCESS
Log Files Generated:
- Main build log: ai_layer/logs/build.log
- Model conversion: ai_layer/logs/model_conversion.log
- Stage1 build: ai_layer/logs/stage1_build.log
- Stage2 build: ai_layer/logs/stage2_build.log
- Package artifacts: ai_layer/logs/package_artifacts.log
- Model to header: ai_layer/logs/model_to_header.log
- Generate report: ai_layer/logs/generate_report.log
Outputs Generated:
- AI Layer libraries: ai_layer/engine/lib/
- AI Layer headers: ai_layer/engine/include/
- Model header: ai_layer/model/model_pte.h
- Build report: ai_layer/REPORT.md
EOF
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] Build completed successfully!" | tee -a $MAIN_LOG
echo "📋 Build logs saved to: ai_layer/logs/" | tee -a $MAIN_LOG
- name: Commit changes including logs
run: |
git add ai_layer/
git diff --staged --quiet || git commit -m "Update AI layer with new model build - Build $BUILD_TIMESTAMP
Build artifacts and logs included:
- Libraries: ai_layer/engine/lib/
- Headers: ai_layer/engine/include/
- Model: ai_layer/model/
- Report: ai_layer/REPORT.md
- Build logs: ai_layer/logs/
Workflow run: ${{ github.run_id }}
Commit: ${{ github.sha }}"
git push