|
1 | | -name: Build Wheels |
| 1 | +name: Build with Dual Cache (示例) |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: [ "main" ] |
6 | | - tags: [ 'v*.*.*' ] |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
7 | 8 |
|
8 | 9 | jobs: |
9 | 10 | build: |
10 | 11 | runs-on: ubuntu-latest |
11 | | - permissions: |
12 | | - contents: write |
13 | | - packages: write |
14 | | - id-token: write |
15 | | - |
16 | | - timeout-minutes: 600 |
17 | | - |
| 12 | + |
18 | 13 | steps: |
19 | | - - name: Free Disk Space (Ubuntu) |
20 | | - uses: jlumbroso/free-disk-space@main |
21 | | - with: |
22 | | - tool-cache: true |
23 | | - android: true |
24 | | - dotnet: true |
25 | | - haskell: true |
26 | | - large-packages: true |
27 | | - swap-storage: false |
28 | | - docker-images: false |
29 | | - |
30 | | - - name: Checkout repository |
31 | | - uses: actions/checkout@v3 |
32 | | - with: |
33 | | - submodules: recursive |
34 | | - |
35 | | - - name: Add Swap |
36 | | - run: | |
37 | | - SWAP_FILE="/mnt/swapfile" |
38 | | -
|
39 | | - swapon --show |
40 | | - echo "Trying to disable and remove existing swap if needed..." |
41 | | - if swapon --show=NAME | grep -q "$SWAP_FILE"; then |
42 | | - echo "Disabling existing swap at $SWAP_FILE..." |
43 | | - sudo swapoff "$SWAP_FILE" |
44 | | - fi |
45 | | -
|
46 | | - if [ -f "$SWAP_FILE" ]; then |
47 | | - echo "Removing existing file at $SWAP_FILE..." |
48 | | - sudo rm -f "$SWAP_FILE" |
49 | | - fi |
50 | | -
|
51 | | - echo "Creating new 32G swap file..." |
52 | | - sudo dd if=/dev/zero of=$SWAP_FILE bs=1G count=32 |
53 | | - sudo chmod 600 "$SWAP_FILE" |
54 | | - sudo mkswap "$SWAP_FILE" |
55 | | - sudo swapon "$SWAP_FILE" |
56 | | -
|
57 | | - echo "Final swap status:" |
58 | | - swapon --show |
59 | | - free -h |
60 | | -
|
61 | | - - name: Setup Docker buildx |
62 | | - uses: docker/setup-buildx-action@v3 |
63 | | - |
64 | | - # Avoid using local disk for buildx cache; use GHA cache backend |
65 | | - - name: Prune Docker to free space |
66 | | - run: | |
67 | | - docker system prune -af --volumes || true |
68 | | - rm -rf /tmp/.buildx-cache || true |
69 | | - rm -rf ./out || true |
70 | | -
|
71 | | - # Build and export wheels directly (fastest method) |
72 | | - - name: Build and export wheels |
73 | | - uses: docker/build-push-action@v5 |
74 | | - with: |
75 | | - context: . |
76 | | - target: wheels # We'll add this target to Dockerfile |
77 | | - outputs: type=local,dest=./out |
78 | | - cache-from: type=gha |
79 | | - cache-to: type=gha,mode=max |
80 | | - |
81 | | - - name: Verify exported wheels |
82 | | - run: | |
83 | | - echo "Wheel files exported directly during build:" |
84 | | - ls -la ./out/ |
85 | | - echo "Wheel count: $(ls -1 ./out/*.whl | wc -l)" |
86 | | -
|
87 | | - - name: Upload wheels as artifact |
88 | | - uses: actions/upload-artifact@v4 |
89 | | - with: |
90 | | - name: wheels |
91 | | - path: ./out/*.whl |
92 | | - |
93 | | - - name: Upload .whl to GitHub Release |
94 | | - if: startsWith(github.ref, 'refs/tags/') |
95 | | - env: |
96 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
97 | | - run: | |
98 | | - TAG_NAME=${GITHUB_REF##*/} |
99 | | -
|
100 | | - # Get wheel file information |
101 | | - LIGHTKERNEL_WHEEL=$(ls ./out/lightllm_kernel-*.whl | head -n1 | xargs basename) |
102 | | - FA3_MTP_WHEEL=$(ls ./out/flash_attn_3-*.whl | head -n1 | xargs basename) |
103 | | -
|
104 | | - gh release create "$TAG_NAME" ./out/*.whl \ |
105 | | - --title "LightKernel Release $TAG_NAME" \ |
106 | | - --notes "🎯 **LightKernel Release $TAG_NAME** |
107 | | -
|
108 | | - This automated release contains pre-compiled wheel packages: |
109 | | -
|
110 | | - 📦 **Packages:** |
111 | | - - **$LIGHTKERNEL_WHEEL** - Core CUDA kernel library |
112 | | - - **$FA3_MTP_WHEEL** - Fa3 MTP 3.0 (Hopper) |
113 | | -
|
114 | | - 🚀 **Quick Installation:** |
115 | | - \`\`\`bash |
116 | | - # Install both packages |
117 | | - pip install https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/$LIGHTKERNEL_WHEEL |
118 | | - pip install https://github.com/${{ github.repository }}/releases/download/$TAG_NAME/$FA3_MTP_WHEEL |
119 | | - \`\`\` |
120 | | -
|
121 | | - 🔧 **Build Environment:** |
122 | | - - CUDA: 12.6.1 with cuDNN |
123 | | - - PyTorch: 2.8.0 |
124 | | - - Python: 3.10 |
125 | | - - Architecture: CUDA Compute Capabilities 9.0 |
126 | | -
|
127 | | -
|
128 | | -
|
129 | | - Built on $(date -u)" \ |
130 | | - || echo "Release already exists, skipping" |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + # 🔄 第1层:Docker BuildKit缓存(您已有的) |
| 18 | + - name: Docker cache - restore |
| 19 | + uses: actions/cache@v4 |
| 20 | + with: |
| 21 | + path: /tmp/.buildx-cache |
| 22 | + key: buildx-${{ runner.os }}-${{ github.sha }} |
| 23 | + restore-keys: | |
| 24 | + buildx-${{ runner.os }}- |
| 25 | +
|
| 26 | + # 🔄 第2层:ccache编译缓存(新增) |
| 27 | + - name: ccache - restore |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: /tmp/ccache |
| 31 | + key: ccache-${{ runner.os }}-${{ hashFiles('**/*.cpp', '**/*.cu', '**/*.h') }} |
| 32 | + restore-keys: | |
| 33 | + ccache-${{ runner.os }}- |
| 34 | +
|
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v3 |
| 37 | + |
| 38 | + # 🚀 使用双重缓存构建 |
| 39 | + - name: Build with dual cache |
| 40 | + uses: docker/build-push-action@v5 |
| 41 | + with: |
| 42 | + context: . |
| 43 | + file: ./Dockerfile |
| 44 | + push: false |
| 45 | + tags: lightkernel:latest |
| 46 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 47 | + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max |
| 48 | + # 挂载ccache缓存到容器中 |
| 49 | + cache-mount: | |
| 50 | + type=cache,target=/tmp/ccache,source=/tmp/ccache |
| 51 | +
|
| 52 | + # 更新buildx缓存 |
| 53 | + - name: Move cache |
| 54 | + run: | |
| 55 | + rm -rf /tmp/.buildx-cache |
| 56 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments