|
| 1 | +#!/bin/bash |
| 2 | +# MNIST Demo Provenance Collection Script |
| 3 | +# This script runs a demo MNIST workflow (no data prep or training) and collects |
| 4 | +# provenance data |
| 5 | + |
| 6 | +# Configuration |
| 7 | +STORAGE_URL="http://localhost:8080" |
| 8 | + |
| 9 | +# Helper function to extract ID from output |
| 10 | +extract_id() { |
| 11 | + grep -o "ID: [^ ]*" "$1" | cut -d' ' -f2 |
| 12 | +} |
| 13 | + |
| 14 | +TRAIN_DATASET="train-00000-of-00001.parquet" |
| 15 | +TEST_DATASET="test-00000-of-00001.parquet" |
| 16 | + |
| 17 | +if [ ! -e "$TRAIN_DATASET" ]; then |
| 18 | + echo "Warning: Training datset not found. Downloading..." |
| 19 | + wget -q https://huggingface.co/datasets/ylecun/mnist/resolve/main/mnist/$TRAIN_DATASET |
| 20 | +fi |
| 21 | + |
| 22 | +if [ ! -e "$TEST_DATASET" ]; then |
| 23 | + echo "Warning: Test datset not found. Downloading..." |
| 24 | + wget -q https://huggingface.co/datasets/ylecun/mnist/resolve/main/mnist/$TEST_DATASET |
| 25 | +fi |
| 26 | + |
| 27 | +echo -e "=== STEP 0: Setup Provenance Signing/Verification Key Pair ===" |
| 28 | +openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:4096 2>/dev/null |
| 29 | +openssl rsa -pubout -in private.pem -out public.pem 2>/dev/null |
| 30 | + |
| 31 | +read -s -r -p "Press any key to continue" |
| 32 | + |
| 33 | +echo -e "\n=== STEP 1: Generate Provenance for MNIST Training Data ===" |
| 34 | + |
| 35 | +read -s -r -p "Create training dataset manifest..." |
| 36 | +atlas-cli dataset create \ |
| 37 | + --paths="$TRAIN_DATASET" \ |
| 38 | + --ingredient-names="MNIST Training Dataset" \ |
| 39 | + --name="MNIST Training Data" \ |
| 40 | + --author-org="https://huggingface.co/datasets/ylecun/mnist/tree/main/mnist/blob/main/mnist/$TRAIN_DATASET" \ |
| 41 | + --author-name="ylecun" \ |
| 42 | + --storage-type=database \ |
| 43 | + --storage-url=$STORAGE_URL \ |
| 44 | + --key=private.pem \ |
| 45 | + > train_dataset_output.txt |
| 46 | +TRAIN_DATASET_ID=$(extract_id train_dataset_output.txt) |
| 47 | +echo "Dataset ID: $TRAIN_DATASET_ID" |
| 48 | + |
| 49 | +read -s -r -p "Display training data manifest" |
| 50 | +atlas-cli manifest export \ |
| 51 | + --id=$TRAIN_DATASET_ID \ |
| 52 | + --format=json \ |
| 53 | + | jq '.' |
| 54 | + |
| 55 | +read -s -r -p "Press any key to continue" |
| 56 | + |
| 57 | +echo -e "\n=== STEP 2: Generate Provenance for Model Training Artifacts ===" |
| 58 | + |
| 59 | +read -s -r -p "Create training script manifest..." |
| 60 | +atlas-cli software create \ |
| 61 | + --paths=../mnist/train.py \ |
| 62 | + --ingredient-names="MNIST Training Script" \ |
| 63 | + --name="MNIST CNN Training Implementation" \ |
| 64 | + --software-type="script" \ |
| 65 | + --version="1.0.0" \ |
| 66 | + --author-org="Your Organization" \ |
| 67 | + --author-name="Your Name" \ |
| 68 | + --description="PyTorch training script for MNIST CNN model" \ |
| 69 | + --with-tdx \ |
| 70 | + --key=private.pem \ |
| 71 | + --storage-type=database \ |
| 72 | + --storage-url=$STORAGE_URL \ |
| 73 | + > training_script_output.txt |
| 74 | +TRAINING_SCRIPT_ID=$(extract_id training_script_output.txt) |
| 75 | +echo "Training Script ID: $TRAINING_SCRIPT_ID" |
| 76 | + |
| 77 | +touch classifier.onnx |
| 78 | +read -s -r -p "Create model manifest..." |
| 79 | +atlas-cli model create \ |
| 80 | + --paths=classifier.onnx \ |
| 81 | + --ingredient-names="MNIST CNN Model" \ |
| 82 | + --name="Trained MNIST Classifier" \ |
| 83 | + --author-org="Your Organization" \ |
| 84 | + --author-name="Your Name" \ |
| 85 | + --key=private.pem \ |
| 86 | + --storage-type=database \ |
| 87 | + --storage-url=$STORAGE_URL \ |
| 88 | + > model_output.txt |
| 89 | +MODEL_ID=$(extract_id model_output.txt) |
| 90 | +echo "Model ID: $MODEL_ID" |
| 91 | + |
| 92 | +read -s -r -p "Display model's manifest" |
| 93 | +atlas-cli manifest export \ |
| 94 | + --id=$MODEL_ID \ |
| 95 | + --format=json \ |
| 96 | + | jq '.' |
| 97 | + |
| 98 | +read -s -r -p "Press any key to continue" |
| 99 | + |
| 100 | +echo -e "\n=== STEP 3: Link Model Training Manifests ===" |
| 101 | + |
| 102 | +read -s -r -p "Link MNIST training dataset to model..." |
| 103 | +atlas-cli manifest link \ |
| 104 | + --source=$MODEL_ID \ |
| 105 | + --target=$TRAIN_DATASET_ID \ |
| 106 | + --storage-type=database \ |
| 107 | + --storage-url=$STORAGE_URL \ |
| 108 | + > model_train_dataset_link_output.txt |
| 109 | +MODEL_ID=$(extract_id model_train_dataset_link_output.txt) |
| 110 | +echo "Updated Model ID: $MODEL_ID" |
| 111 | + |
| 112 | +read -s -r -p "Link training script to model..." |
| 113 | +atlas-cli manifest link \ |
| 114 | + --source=$MODEL_ID \ |
| 115 | + --target=$TRAINING_SCRIPT_ID \ |
| 116 | + --storage-type=database \ |
| 117 | + --storage-url=$STORAGE_URL \ |
| 118 | + > model_train_script_link_output.txt |
| 119 | +MODEL_ID=$(extract_id model_train_script_link_output.txt) |
| 120 | +echo "Updated Model ID: $MODEL_ID" |
| 121 | + |
| 122 | +read -s -r -p "Display model's manifest" |
| 123 | +atlas-cli manifest export \ |
| 124 | + --id=$MODEL_ID \ |
| 125 | + --format=json \ |
| 126 | + | jq '.' |
| 127 | + |
| 128 | +read -s -r -p "Press any key to continue" |
| 129 | + |
| 130 | +echo -e "\n=== STEP 4: Generate & Link Provenance for Model Evaluation Artifacts ===" |
| 131 | + |
| 132 | +atlas-cli dataset create \ |
| 133 | + --paths="$TEST_DATASET" \ |
| 134 | + --ingredient-names="MNIST Training Dataset" \ |
| 135 | + --name="MNIST Training Data" \ |
| 136 | + --author-org="https://huggingface.co/datasets/ylecun/mnist/tree/main/mnist/blob/main/mnist/$TEST_DATASET" \ |
| 137 | + --author-name="ylecun" \ |
| 138 | + --storage-type=database \ |
| 139 | + --storage-url=$STORAGE_URL \ |
| 140 | + --key=private.pem \ |
| 141 | + > test_dataset_output.txt |
| 142 | +TEST_DATASET_ID=$(extract_id test_dataset_output.txt) |
| 143 | +echo "Test Dataset ID: $TEST_DATASET_ID" |
| 144 | + |
| 145 | +atlas-cli software create \ |
| 146 | + --paths=../mnist/eval.py \ |
| 147 | + --ingredient-names="MNIST Evaluation Script" \ |
| 148 | + --name="MNIST Model Evaluation Implementation" \ |
| 149 | + --software-type="script" \ |
| 150 | + --version="1.0.0" \ |
| 151 | + --author-org="Your Organization" \ |
| 152 | + --author-name="Your Name" \ |
| 153 | + --description="PyTorch evaluation script for MNIST CNN model" \ |
| 154 | + --with-tdx \ |
| 155 | + --key=private.pem \ |
| 156 | + --storage-type=database \ |
| 157 | + --storage-url=$STORAGE_URL \ |
| 158 | + > eval_script_output.txt |
| 159 | +EVAL_SCRIPT_ID=$(extract_id eval_script_output.txt) |
| 160 | +echo "Evaluation Script ID: $EVAL_SCRIPT_ID" |
| 161 | + |
| 162 | +touch eval_results.json |
| 163 | +echo "Creating evaluation results manifest linked to model..." |
| 164 | +atlas-cli evaluation create \ |
| 165 | + --path=eval_results.json \ |
| 166 | + --name="MNIST Model Evaluation Results" \ |
| 167 | + --author-org="Your Organization" \ |
| 168 | + --author-name="Your Name" \ |
| 169 | + --model-id=$MODEL_ID \ |
| 170 | + --dataset-id=$TEST_DATASET_ID \ |
| 171 | + --hash-alg=sha384 \ |
| 172 | + --key=private.pem \ |
| 173 | + --storage-type=database \ |
| 174 | + --storage-url=$STORAGE_URL \ |
| 175 | + > eval_results_output.txt |
| 176 | +EVAL_RESULTS_ID=$(extract_id eval_results_output.txt) |
| 177 | +echo "Evaluation Results ID: $EVAL_RESULTS_ID" |
| 178 | + |
| 179 | +atlas-cli manifest link \ |
| 180 | + --source=$EVAL_RESULTS_ID \ |
| 181 | + --target=$EVAL_SCRIPT_ID \ |
| 182 | + --storage-type=database \ |
| 183 | + --storage-url=$STORAGE_URL \ |
| 184 | + > eval_script_link_output.txt |
| 185 | +EVAL_RESULTS_ID=$(extract_id eval_script_link_output.txt) |
| 186 | +echo "Updated Eval Results ID: $EVAL_RESULTS_ID" |
| 187 | + |
| 188 | +read -s -r -p "Press any key to continue" |
| 189 | + |
| 190 | +echo -e "\n=== STEP 4: Export Provenance Graph ===" |
| 191 | +atlas-cli manifest export \ |
| 192 | + --id=$EVAL_RESULTS_ID \ |
| 193 | + --storage-type=database \ |
| 194 | + --storage-url=$STORAGE_URL \ |
| 195 | + --format=json \ |
| 196 | + --max-depth=10 \ |
| 197 | + --output=mnist_provenance.json |
| 198 | + |
| 199 | +read -s -r -p "Press any key to continue" |
| 200 | + |
| 201 | +echo -e "\n=== STEP 5: Validate Provenance ===" |
| 202 | + |
| 203 | +read -s -r -p "Validate model manifest..." |
| 204 | +atlas-cli manifest validate \ |
| 205 | + --id=$MODEL_ID \ |
| 206 | + --storage-type=database \ |
| 207 | + --storage-url=$STORAGE_URL |
| 208 | + |
| 209 | +read -s -r -p "Validate evaluation results manifest..." |
| 210 | +atlas-cli manifest validate \ |
| 211 | + --id=$EVAL_RESULTS_ID \ |
| 212 | + --storage-type=database \ |
| 213 | + --storage-url=$STORAGE_URL |
| 214 | + |
| 215 | +INVALID_LINKED_MANIFEST_ID="urn:c2pa:123e4567-e89b-12d3-a456-426614174000" |
| 216 | + |
| 217 | +read -s -r -p "Validate bad manifest link (should fail)..." |
| 218 | +atlas-cli manifest verify-link \ |
| 219 | + --source=$MODEL_ID \ |
| 220 | + --target=$INVALID_LINKED_MANIFEST_ID \ |
| 221 | + --storage-type=database \ |
| 222 | + --storage-url=$STORAGE_URL |
| 223 | + |
| 224 | +read -s -r -p "Display exported evaluation results provenance" |
| 225 | +echo -e "\n" |
| 226 | +cat mnist_provenance.json | jq '.' |
| 227 | + |
| 228 | +read -s -r -p "Finish demo" |
| 229 | +echo -e "\n" |
| 230 | +rm -f *_output.txt *.pem classifier.onnx eval_results.json mnist_provenance.json |
0 commit comments