mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 00:43:54 +08:00
* Tinygrad bump from sync-20250627 * bump tinygrad_repo * Reformat metadata generator to match driving_models.json * bump tinygrad * Revert "bump tinygrad" This reverts commitf479dfd502. * revert me after SP model compiled * Model recompiled successfully, initiate "revert me after SP model compiled" This reverts commit95706eb688. * The "FillMe" placeholder caused an extra 10 seconds of work * bump to 22Jul2025 * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * Allow more dynamic short names This should hopefully be future-proof for now.. It's robust enough to return the correct word-digit format (see example on how it generates from given display name below): 'Last Horizon V2 (November 22, 2024)' -> LHV2 'Alabama (November 25, 2024)' -> ALABAMA 'PlayStation (December 03, 2024)' -> PLAYSTAT 'Postal Service (December 09, 2024)' -> PS 'Null Pointer (December 13, 2024)' -> NP 'North America (December 16, 2024)' -> NA 'National Public Radio (December 18, 2024)' -> NPR 'Filet o Fish (March 7, 2025)' -> FOF 'Tomb Raider 2 (April 18, 2025)' -> TR2 'Tomb Raider 3 (April 22, 2025)' -> TR3 'Tomb Raider 4 (April 25, 2025)' -> TR4 'Tomb Raider 5 (April 25, 2025)' -> TR5 'Tomb Raider 6 (April 30, 2025)' -> TR6 'Tomb Raider 7 (May 07, 2025)' -> TR7 'Down to Ride (Revision: May 10, 2025)' -> DTR 'SP Vikander Model (May 16, 2025)' -> SPVM 'VFF Driving (May 15, 2025)' -> VFFD 'Secret Good Openpilot (May 16, 2025)' -> SGO 'Vegetarian Filet o Fish (May 29, 2025)' -> VFOF 'Down To Ride (Revision: May 30, 2025)' -> DTR 'Vegetarian Filet o Fish v2 (June 05, 2025)' -> VFOFV2 'Kerrygold Driving (June 08, 2025)' -> KD 'Tomb Raider 10 (June 16, 2025)' -> TR10 'Organic Kerrygold (June 17, 2025)' -> OK 'Liquid Crystal Driving (June 21, 2025)' -> LCD 'Vegetarian Filet o Fish v3 (June 21, 2025)' -> VFOFV3 'Vibe Model [Custom Model]' -> VMCM 'Tomb Raider 13 (June 27, 2025)' -> TR13 'Aggressive TR (June 28, 2025)' -> ATR 'Tomb Raider 14 (June 30, 2025)' -> TR14 'Cookiemonster Tomb Raider (July 02, 2025)' -> CTR 'Down to Ride (Revision: July 07, 2025)' -> DTR 'Simple Plan Driving (July 07, 2025)' -> SPD 'Down to Ride (Revision: July 08, 2025)' -> DTR 'Tomb Raider 15 (July 09, 2025)' -> TR15 'Tomb Raider 15 rev-2 (July 11, 2025)' -> TR15R2 'Le Tomb Raider 14 (July 14, 2025)' -> LTR14 'Le Tomb Raider 14h (July 17, 2025)' -> LTR14H 'Tomb Raider 16 (July 18, 2025)' -> TR16 'Tomb Raider 16v2 (July 21, 2025)' -> TR16V2 * Update build-all-tinygrad-models.yaml * Update build-all-tinygrad-models.yaml * No need to sleep 3 seconds, just send it * try dynamic * cleanup * Update build-single-tinygrad-model.yaml * bc devtekve said. also, this is repetitive af * Revert "bc devtekve said. also, this is repetitive af" This reverts commit3a0c1562de. * maybe we could use a script instead that both build all That both build all and sunnypilot-build-model reference * refactor: consolidate model building steps into a single workflow * tweak * tweakx2 * tweakx3 * tweakx4 * dunno dunno... * output dir * lots of changes * Revert "lots of changes" This reverts commit4aadb0ee29. * fail if all fail * no inputs needed * make it easier for us * note failure and exit 0 * Update build-all-tinygrad-models.yaml * not needed unless we really want it * Update build-single-tinygrad-model.yaml * Merge branch 'sync-20250627-tinygrad' of github.com:sunnypilot/sunnypilot into sync-20250627-tinygrad * retry for failed ? * always run this step because sometimes one build fails which causes the matrix to fail, but most builds still have uploaded artifacts. * strip * no escape * Update build-all-tinygrad-models.yaml * Test case from terminal run (openpilot) james@Mac sunnypilot % jq -c '[.bundles[] | select(.runner=="tinygrad") | {ref, display_name: (.display_name | gsub(" \\([^)]*\\)"; "")), is_20hz}]' \ /Users/james/Documents/GitHub/sunnypilot-docs/docs/driving_models_v6.json > matrix.json mkdir -p output touch "output/model-Tomb Raider 16v2 (July 21, 2025)-544" touch "output/model-Space Lab Model (July 24, 2025)-547" touch "output/model-Space Lab Model v1 (July 24, 2025)-548" built=(); while IFS= read -r line; do built+=("$line"); done < <( ls output | sed -E 's/^model-//' | sed -E 's/-[0-9]+$//' | sed -E 's/ \([^)]*\)//' | awk '{gsub(/^ +| +$/, ""); print}' ) jq -c --argjson built "$(printf '%s\n' "${built[@]}" | jq -R . | jq -s .)" \ 'map(select(.display_name as $n | ($built | index($n | gsub("^ +| +$"; "")) | not)))' \ matrix.json > retry_matrix.json cat retry_matrix.json [] (openpilot) james@Mac sunnypilot % * always * great success * add suffix to retry artifact so it doesn't conflict * retry to get_model too * and there haha * unnecessary hyphen * compare built to missing. include retries * adjust copy of artifacts. * Update build-all-tinygrad-models.yaml * Update model selector versioning and add documentation * Update retry condition for failed models in build-all-tinygrad-models.yaml * Update retry condition for failed models in build-all-tinygrad-models.yaml * Update build-single-tinygrad-model.yaml * false * default none because why not * red diff? i think? * meh ... not needed i guess * error error error * Nayan is watching... always watching mike wazowski * string all the way * lots of retries just in case because im scared * more robust * ONLY ONE!!!!!! * delete.... a lot * fix artifacts * fix artifacts * make sure each is unique :) * skip files like artifact duhhhh * artifact name dir * concurrency * copy here * Update build-single-tinygrad-model.yaml * Update build-single-tinygrad-model.yaml * bump * bump tinygrad * max parallel? if not, i have the other remedy ready in build-all * revert me! * I resynced tinygrad woo hoo * setup shouldnt fail * pull * big ole diff * condition * Update build-all-tinygrad-models.yaml * not always() never always() never!!! * not failure instead of great success * Update build-all-tinygrad-models.yaml * yay that worked. lets invoke build-single one last time * these arent used and are just taking up 250MB space * really frog? * bump back to 3 * self-hosted, tici * rename to trigger tests * 2 and done --------- Co-authored-by: DevTekVE <devtekve@gmail.com>
220 lines
8.1 KiB
YAML
220 lines
8.1 KiB
YAML
name: Build Model from Upstream
|
|
|
|
env:
|
|
BUILD_DIR: "/data/openpilot"
|
|
OUTPUT_DIR: ${{ github.workspace }}/output
|
|
SCONS_CACHE_DIR: ${{ github.workspace }}/release/ci/scons_cache
|
|
UPSTREAM_REPO: "commaai/openpilot"
|
|
TINYGRAD_PATH: ${{ github.workspace }}/tinygrad_repo
|
|
MODELS_DIR: ${{ github.workspace }}/selfdrive/modeld/models
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
upstream_branch:
|
|
description: 'Upstream branch to build from'
|
|
required: true
|
|
default: 'master'
|
|
type: string
|
|
custom_name:
|
|
description: 'Custom name for the model (no date, only name)'
|
|
required: false
|
|
type: string
|
|
is_20hz:
|
|
description: 'Is this a 20Hz model'
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
artifact_suffix:
|
|
description: 'Suffix for artifact name'
|
|
required: false
|
|
type: string
|
|
default: ''
|
|
workflow_dispatch:
|
|
inputs:
|
|
upstream_branch:
|
|
description: 'Upstream branch to build from'
|
|
required: true
|
|
default: 'master'
|
|
type: string
|
|
custom_name:
|
|
description: 'Custom name for the model (no date, only name)'
|
|
required: false
|
|
type: string
|
|
is_20hz:
|
|
description: 'Is this a 20Hz model'
|
|
required: false
|
|
type: boolean
|
|
default: true
|
|
|
|
|
|
run-name: Build model [${{ inputs.custom_name || inputs.upstream_branch }}] from ref [${{ inputs.upstream_branch }}]
|
|
|
|
jobs:
|
|
get_model:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
REF: ${{ inputs.upstream_branch }}
|
|
outputs:
|
|
model_date: ${{ steps.commit-date.outputs.model_date }}
|
|
steps:
|
|
# Note: To allow dynamic models from both openpilot and sunnypilot (merges/mashups), we try commaai as default,
|
|
# and fallback to sunnypilot if the ref checkout fails.
|
|
- name: Checkout commaai/openpilot
|
|
id: checkout_upstream
|
|
continue-on-error: true
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: commaai/openpilot
|
|
ref: ${{ inputs.upstream_branch }}
|
|
submodules: recursive
|
|
path: openpilot
|
|
|
|
- name: Fallback to sunnypilot/sunnypilot
|
|
if: steps.checkout_upstream.outcome == 'failure'
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: sunnypilot/sunnypilot
|
|
ref: ${{ inputs.upstream_branch }}
|
|
submodules: recursive
|
|
path: openpilot
|
|
- name: Get commit date
|
|
id: commit-date
|
|
run: |
|
|
cd ${{ github.workspace }}/openpilot
|
|
commit_date=$(git log -1 --format=%cd --date=format:'%B %d, %Y')
|
|
echo "model_date=${commit_date}" >> $GITHUB_OUTPUT
|
|
cat $GITHUB_OUTPUT
|
|
- run: |
|
|
cd ${{ github.workspace }}/openpilot
|
|
git lfs pull
|
|
- name: 'Upload Artifact'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: models-${{ env.REF }}${{ inputs.artifact_suffix }}
|
|
path: ${{ github.workspace }}/openpilot/selfdrive/modeld/models/*.onnx
|
|
|
|
build_model:
|
|
runs-on: [self-hosted, tici]
|
|
needs: get_model
|
|
env:
|
|
MODEL_NAME: ${{ inputs.custom_name || inputs.upstream_branch }} (${{ needs.get_model.outputs.model_date }})
|
|
REF: ${{ inputs.upstream_branch }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
submodules: recursive
|
|
|
|
- run: git lfs pull
|
|
- name: Cache SCons
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{env.SCONS_CACHE_DIR}}
|
|
key: scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }}-model-${{ github.sha }}
|
|
# Note: GitHub Actions enforces cache isolation between different build sources (PR builds, workflow dispatches, etc.)
|
|
# for security. Only caches from the default branch are shared across all builds. This is by design and cannot be overridden.
|
|
restore-keys: |
|
|
scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }}-model
|
|
scons-${{ runner.os }}-${{ runner.arch }}-${{ github.head_ref || github.ref_name }}
|
|
scons-${{ runner.os }}-${{ runner.arch }}-${{ env.MASTER_NEW_BRANCH }}-model
|
|
scons-${{ runner.os }}-${{ runner.arch }}-${{ env.MASTER_BRANCH }}-model
|
|
scons-${{ runner.os }}-${{ runner.arch }}-${{ env.MASTER_NEW_BRANCH }}
|
|
scons-${{ runner.os }}-${{ runner.arch }}-${{ env.MASTER_BRANCH }}
|
|
scons-${{ runner.os }}-${{ runner.arch }}
|
|
|
|
- name: Set environment variables
|
|
id: set-env
|
|
run: |
|
|
# Set up common environment
|
|
source /etc/profile;
|
|
export UV_PROJECT_ENVIRONMENT=${HOME}/venv
|
|
export VIRTUAL_ENV=$UV_PROJECT_ENVIRONMENT
|
|
printenv >> $GITHUB_ENV
|
|
if [[ "${{ runner.debug }}" == "1" ]]; then
|
|
cat $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Setup build environment
|
|
run: |
|
|
mkdir -p "${BUILD_DIR}/"
|
|
sudo find $BUILD_DIR/ -mindepth 1 -delete
|
|
echo "Starting build stage..."
|
|
echo "BUILD_DIR: ${BUILD_DIR}"
|
|
echo "CI_DIR: ${CI_DIR}"
|
|
echo "VERSION: ${{ steps.set-env.outputs.version }}"
|
|
echo "UV_PROJECT_ENVIRONMENT: ${UV_PROJECT_ENVIRONMENT}"
|
|
echo "VIRTUAL_ENV: ${VIRTUAL_ENV}"
|
|
echo "-------"
|
|
if [[ "${{ runner.debug }}" == "1" ]]; then
|
|
printenv
|
|
fi
|
|
PYTHONPATH=$PYTHONPATH:${{ github.workspace }}/ ${{ github.workspace }}/scripts/manage-powersave.py --disable
|
|
rm -rf ${{ env.MODELS_DIR }}/*.onnx
|
|
|
|
- name: Download model artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: models-${{ env.REF }}${{ inputs.artifact_suffix }}
|
|
path: ${{ github.workspace }}/selfdrive/modeld/models
|
|
|
|
- name: Build Model
|
|
run: |
|
|
source /etc/profile
|
|
export UV_PROJECT_ENVIRONMENT=${HOME}/venv
|
|
export VIRTUAL_ENV=$UV_PROJECT_ENVIRONMENT
|
|
export PYTHONPATH="${PYTHONPATH}:${{ env.TINYGRAD_PATH }}"
|
|
|
|
# Loop through all .onnx files
|
|
find "${{ env.MODELS_DIR }}" -maxdepth 1 -name '*.onnx' | while IFS= read -r onnx_file; do
|
|
base_name=$(basename "$onnx_file" .onnx)
|
|
output_file="${{ env.MODELS_DIR }}/${base_name}_tinygrad.pkl"
|
|
|
|
echo "Compiling: $onnx_file -> $output_file"
|
|
QCOM=1 python3 "${{ env.TINYGRAD_PATH }}/examples/openpilot/compile3.py" "$onnx_file" "$output_file"
|
|
QCOM=1 python3 "${{ env.MODELS_DIR }}/../get_model_metadata.py" "$onnx_file" || true
|
|
done
|
|
|
|
- name: Prepare Output
|
|
run: |
|
|
sudo rm -rf ${{ env.OUTPUT_DIR }}
|
|
mkdir -p ${{ env.OUTPUT_DIR }}
|
|
|
|
# Copy the model files
|
|
rsync -avm \
|
|
--include='*.dlc' \
|
|
--include='*.thneed' \
|
|
--include='*.pkl' \
|
|
--include='*.onnx' \
|
|
--exclude='*' \
|
|
--delete-excluded \
|
|
--chown=comma:comma \
|
|
${{ env.MODELS_DIR }}/ ${{ env.OUTPUT_DIR }}/
|
|
|
|
python3 "${{ github.workspace }}/release/ci/model_generator.py" \
|
|
--model-dir "${{ env.MODELS_DIR }}" \
|
|
--output-dir "${{ env.OUTPUT_DIR }}" \
|
|
--custom-name "${{ env.MODEL_NAME }}" \
|
|
--upstream-branch "${{ inputs.upstream_branch }}" \
|
|
${{ inputs.is_20hz && '--is-20hz' || '' }}
|
|
|
|
- name: Write artifact name to file
|
|
run: echo "model-${{ env.MODEL_NAME }}${{ inputs.artifact_suffix }}-${{ github.run_number }}" > ${{ env.OUTPUT_DIR }}/artifact_name.txt
|
|
|
|
- name: Upload Build Artifacts
|
|
id: upload-artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: model-${{ env.MODEL_NAME }}${{ inputs.artifact_suffix }}-${{ github.run_number }}
|
|
path: ${{ env.OUTPUT_DIR }}
|
|
|
|
- name: Upload artifact name file
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: artifact-name-${{ inputs.custom_name || inputs.upstream_branch }}
|
|
path: ${{ env.OUTPUT_DIR }}/artifact_name.txt
|
|
|
|
- name: Re-enable powersave
|
|
if: always()
|
|
run: |
|
|
PYTHONPATH=$PYTHONPATH:${{ github.workspace }}/ ${{ github.workspace }}/scripts/manage-powersave.py --enable
|