-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgithub-actions.yml
More file actions
116 lines (97 loc) · 3.21 KB
/
Copy pathgithub-actions.yml
File metadata and controls
116 lines (97 loc) · 3.21 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
# Example GitHub Actions workflow for AMS model scanning
# Place in .github/workflows/model-safety.yml
#
# Exit codes from `ams scan`: 0 = PASS, 1 = CRITICAL, 2 = WARNING,
# 3 = identity verification failed.
name: Model Safety Check
on:
push:
paths:
- 'models/**'
pull_request:
paths:
- 'models/**'
workflow_dispatch:
inputs:
model_path:
description: 'Path to model to scan'
required: true
default: 'models/my-model'
env:
MODEL_PATH: ${{ github.event.inputs.model_path || 'models/my-model' }}
jobs:
safety-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true # If using Git LFS for model weights
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install AMS
run: |
pip install "ams-scanner[cli]"
- name: Run safety scan
id: scan
run: |
# Capture the exit code so results can be reported before gating
set +e
ams scan "$MODEL_PATH" --json > scan-results.json
echo "exit_code=$?" >> $GITHUB_OUTPUT
set -e
LEVEL=$(jq -r '.safety_report.overall_level' scan-results.json)
echo "safety_level=$LEVEL" >> $GITHUB_OUTPUT
- name: Upload scan results
uses: actions/upload-artifact@v4
with:
name: ams-scan-results
path: scan-results.json
- name: Post scan summary
run: |
echo "## AMS Safety Scan Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Overall Safety Level:** ${{ steps.scan.outputs.safety_level }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Concept Results" >> $GITHUB_STEP_SUMMARY
echo '```json' >> $GITHUB_STEP_SUMMARY
jq '.safety_report.concept_results | map_values(del(.direction))' scan-results.json >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Fail on unsafe model
if: steps.scan.outputs.safety_level == 'CRITICAL'
run: |
echo "Model failed safety check with CRITICAL level"
exit 1
# Optional: Identity verification against known baseline
identity-verification:
runs-on: ubuntu-latest
needs: safety-scan
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install AMS
run: pip install "ams-scanner[cli]"
- name: Verify model identity
env:
BASELINE: meta-llama/Llama-3.1-8B-Instruct
run: |
set +e
ams scan "$MODEL_PATH" \
--verify "$BASELINE" \
--json > verify-results.json
set -e
VERIFIED=$(jq -r '.verification_report.verified' verify-results.json)
echo "Verified: $VERIFIED"
if [ "$VERIFIED" != "true" ]; then
echo "Model does not match claimed baseline"
exit 1
fi