1818 required : false
1919 type : boolean
2020 default : true
21+ models-quant-level :
22+ description : ' AI Models quantization level'
23+ required : false
24+ type : string
25+ default : ' INT4'
2126 build-onnx :
2227 description : ' Build ONNX Runtime WASM'
2328 required : false
4045 required : false
4146 type : boolean
4247 default : true
48+ models-quant-level :
49+ description : ' AI Models quantization level'
50+ required : false
51+ type : choice
52+ options :
53+ - INT4
54+ - INT8
55+ default : INT4
4356 build-onnx :
4457 description : ' Build ONNX Runtime WASM'
4558 required : false
@@ -168,7 +181,7 @@ jobs:
168181 retention-days : 7
169182
170183 build-models :
171- name : 🤖 Build AI Models (INT4 Quantized)
184+ name : 🤖 Build AI Models (${{ inputs.models-quant-level || ' INT4' }} Quantized)
172185 if : ${{ inputs.build-models != false }}
173186 runs-on : ubuntu-latest
174187 timeout-minutes : 60
@@ -223,9 +236,14 @@ jobs:
223236 MODELS_VERSION=$(node -p "require('./packages/models/package.json').version")
224237 # Hash includes script files and package.json.
225238 HASH=$(find packages/models -type f \( -name "*.mjs" -o -name "package.json" \) | sort | xargs sha256sum | sha256sum | cut -d' ' -f1)
226- FULL_HASH="${HASH}-${MODELS_VERSION}"
239+ # Include quantization level in cache key.
240+ QUANT_LEVEL="${{ inputs.models-quant-level || 'INT4' }}"
241+ FULL_HASH="${HASH}-${MODELS_VERSION}-${QUANT_LEVEL}"
227242 echo "hash=$FULL_HASH" >> $GITHUB_OUTPUT
243+ echo "quant-level=${QUANT_LEVEL}" >> $GITHUB_OUTPUT
244+ echo "suffix=$(echo ${QUANT_LEVEL} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
228245 echo "Models version: v$MODELS_VERSION"
246+ echo "Quantization level: $QUANT_LEVEL"
229247
230248 - name : Restore models cache
231249 id : models-cache
@@ -239,7 +257,8 @@ jobs:
239257 - name : Verify cached artifacts
240258 id : models-cache-valid
241259 run : |
242- if [ -f "packages/models/dist/minilm-l6.onnx" ] && [ -f "packages/models/dist/codet5-encoder.onnx" ]; then
260+ SUFFIX="${{ steps.models-cache-key.outputs.suffix }}"
261+ if [ -f "packages/models/dist/minilm-l6-${SUFFIX}.onnx" ] && [ -f "packages/models/dist/codet5-encoder-${SUFFIX}.onnx" ]; then
243262 echo "valid=true" >> $GITHUB_OUTPUT
244263 echo "Cache hit: artifacts found"
245264 ls -lh packages/models/dist/
@@ -252,34 +271,46 @@ jobs:
252271 - name : Build AI models
253272 if : steps.models-cache-valid.outputs.valid != 'true' || inputs.force
254273 run : |
255- echo "::group::Building INT4-quantized AI models"
274+ QUANT_LEVEL="${{ steps.models-cache-key.outputs.quant-level }}"
275+ echo "::group::Building ${QUANT_LEVEL}-quantized AI models"
276+
277+ # Build command with quantization flag.
278+ BUILD_CMD="pnpm --filter @socketsecurity/models run build --"
279+
280+ if [ "$QUANT_LEVEL" = "INT8" ]; then
281+ BUILD_CMD="$BUILD_CMD --int8"
282+ fi
283+
256284 if [ "${{ inputs.force }}" = "true" ]; then
257- pnpm --filter @socketsecurity/models run build -- --force
258- else
259- pnpm --filter @socketsecurity/models run build
285+ BUILD_CMD="$BUILD_CMD --force"
260286 fi
287+
288+ echo "Running: $BUILD_CMD"
289+ eval $BUILD_CMD
290+
261291 echo "Build exit code: $?"
262292 echo "Checking for build artifacts..."
263293 ls -lh packages/models/dist/ || echo "dist directory not found"
264294 echo "::endgroup::"
265295
266296 - name : Verify build artifacts
267297 run : |
298+ SUFFIX="${{ steps.models-cache-key.outputs.suffix }}"
268299 echo "=== AI Models Build Artifacts ==="
269- if [ ! -f "packages/models/dist/minilm-l6.onnx" ]; then
270- echo "ERROR: minilm-l6.onnx not found!"
300+ if [ ! -f "packages/models/dist/minilm-l6-${SUFFIX} .onnx" ]; then
301+ echo "ERROR: minilm-l6-${SUFFIX} .onnx not found!"
271302 ls -lh packages/models/dist/ || echo "Directory does not exist"
272303 exit 1
273304 fi
274- if [ ! -f "packages/models/dist/codet5-encoder.onnx" ]; then
275- echo "ERROR: codet5-encoder.onnx not found!"
305+ if [ ! -f "packages/models/dist/codet5-encoder-${SUFFIX} .onnx" ]; then
306+ echo "ERROR: codet5-encoder-${SUFFIX} .onnx not found!"
276307 exit 1
277308 fi
278309 ls -lh packages/models/dist/
279310 echo ""
280- echo "minilm-l6.onnx size: $(du -h packages/models/dist/minilm-l6.onnx | cut -f1)"
281- echo "codet5-encoder.onnx size: $(du -h packages/models/dist/codet5-encoder.onnx | cut -f1)"
282- echo "codet5-decoder.onnx size: $(du -h packages/models/dist/codet5-decoder.onnx | cut -f1)"
311+ echo "minilm-l6-${SUFFIX} .onnx size: $(du -h packages/models/dist/minilm-l6-${SUFFIX} .onnx | cut -f1)"
312+ echo "codet5-encoder-${SUFFIX} .onnx size: $(du -h packages/models/dist/codet5-encoder-${SUFFIX} .onnx | cut -f1)"
313+ echo "codet5-decoder-${SUFFIX} .onnx size: $(du -h packages/models/dist/codet5-decoder-${SUFFIX} .onnx | cut -f1)"
283314
284315 - name : Upload models artifacts
285316 uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
@@ -446,7 +477,14 @@ jobs:
446477 echo "| 🧘 Yoga Layout | \`yoga.wasm\`, \`yoga.js\` |" >> $GITHUB_STEP_SUMMARY
447478 fi
448479 if [ -d "artifacts/ai-models" ]; then
449- echo "| 🤖 AI Models | \`minilm-l6.onnx\` (INT4), \`codet5-encoder.onnx\` (INT4), \`codet5-decoder.onnx\` (INT4) |" >> $GITHUB_STEP_SUMMARY
480+ # Detect quantization level from file names.
481+ if [ -f "artifacts/ai-models/minilm-l6-int8.onnx" ]; then
482+ echo "| 🤖 AI Models | \`minilm-l6-int8.onnx\` (INT8), \`codet5-encoder-int8.onnx\` (INT8), \`codet5-decoder-int8.onnx\` (INT8) |" >> $GITHUB_STEP_SUMMARY
483+ elif [ -f "artifacts/ai-models/minilm-l6-int4.onnx" ]; then
484+ echo "| 🤖 AI Models | \`minilm-l6-int4.onnx\` (INT4), \`codet5-encoder-int4.onnx\` (INT4), \`codet5-decoder-int4.onnx\` (INT4) |" >> $GITHUB_STEP_SUMMARY
485+ else
486+ echo "| 🤖 AI Models | $(ls artifacts/ai-models/*.onnx 2>/dev/null | xargs -n1 basename | sed 's/^/`/;s/$/`/' | tr '\n' ',' | sed 's/,$//' || echo "No ONNX files found") |" >> $GITHUB_STEP_SUMMARY
487+ fi
450488 fi
451489 if [ -d "artifacts/onnx-runtime" ]; then
452490 echo "| 🌐 ONNX Runtime | \`ort-wasm-simd-threaded.wasm\`, \`ort-wasm-simd-threaded.mjs\` |" >> $GITHUB_STEP_SUMMARY
0 commit comments