|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2025 Google LLC |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +echo "Running Support Matrices Generator Tests..." |
| 19 | + |
| 20 | +export TPU_VERSION="tpu6e" |
| 21 | +export BUILDKITE_TAG="test_version" |
| 22 | +TEST_DIR=$(mktemp -d) |
| 23 | +trap 'rm -rf "$TEST_DIR" v6' EXIT |
| 24 | + |
| 25 | +cd "$(dirname "$0")/.." |
| 26 | + |
| 27 | +# Mock buildkite-agent |
| 28 | +buildkite-agent() { |
| 29 | + local cmd="$1" |
| 30 | + local subcmd="$2" |
| 31 | + if [[ "$cmd" == "meta-data" && "$subcmd" == "get" ]]; then |
| 32 | + local key="$3" |
| 33 | + if [[ "$key" == "model-list" ]]; then |
| 34 | + echo -e "test_model" |
| 35 | + elif [[ "$key" == "feature-list" ]]; then |
| 36 | + echo -e "kernel support matrix microbenchmarks" |
| 37 | + elif [[ "$key" == "v6test_model_category" ]]; then |
| 38 | + echo "text-only" |
| 39 | + elif [[ "$key" == "v6test_model:UnitTest" ]]; then |
| 40 | + echo "✅ Passing" |
| 41 | + elif [[ "$key" == "v6test_model:Accuracy/Correctness" ]]; then |
| 42 | + echo "❌ Failing" |
| 43 | + elif [[ "$key" == "v6test_model:Benchmark" ]]; then |
| 44 | + echo "⚪ N/A" |
| 45 | + elif [[ "$key" == "v6kernel support matrix microbenchmarks_category" ]]; then |
| 46 | + echo "kernel support matrix microbenchmarks" |
| 47 | + else |
| 48 | + echo "❓ Untested" |
| 49 | + fi |
| 50 | + elif [[ "$cmd" == "meta-data" && "$subcmd" == "set" ]]; then |
| 51 | + echo "$3=$4" >> "$TEST_DIR/metadata.txt" |
| 52 | + elif [[ "$cmd" == "artifact" && "$subcmd" == "upload" ]]; then |
| 53 | + cp "$3" "$TEST_DIR/" |
| 54 | + fi |
| 55 | +} |
| 56 | +export -f buildkite-agent |
| 57 | + |
| 58 | +# Mock mapfile for MacOS compatibility (Bash 3.2 doesn't have it) |
| 59 | +mapfile() { |
| 60 | + local array_name="" |
| 61 | + for arg in "$@"; do |
| 62 | + if [[ "$arg" != "-t" ]]; then |
| 63 | + array_name="$arg" |
| 64 | + fi |
| 65 | + done |
| 66 | + local lines=() |
| 67 | + while IFS= read -r line || [ -n "$line" ]; do |
| 68 | + lines+=("$line") |
| 69 | + done |
| 70 | + if [[ -n "$array_name" ]]; then |
| 71 | + eval "$array_name=(\"\${lines[@]}\")" |
| 72 | + fi |
| 73 | +} |
| 74 | +export -f mapfile |
| 75 | + |
| 76 | +# Set up mock microbenchmark input |
| 77 | +mkdir -p v6 |
| 78 | +cat << 'EOF' > v6/kernel_support_matrix_microbenchmarks.csv |
| 79 | +kernels,CorrectnessTest,PerformanceTest,TPU Versions |
| 80 | +fused_moe-w8a8,❓ Untested,❓ Untested,v6 |
| 81 | +fused_moe-w8a16,✅ Passing,✅ Passing,v6 |
| 82 | +fused_moe-w16a16,⚪ N/A,⚪ N/A,v6 |
| 83 | +mla,✅ Passing,❓ Untested,v6 |
| 84 | +generic ragged paged attention v3,✅ Passing,✅ Passing,v6 |
| 85 | +EOF |
| 86 | + |
| 87 | +# Execute the script |
| 88 | +bash .buildkite/scripts/generate_support_matrices.sh > /dev/null |
| 89 | + |
| 90 | +# Assertions |
| 91 | +echo "Verifying Outputs..." |
| 92 | +if ! grep -q "CI_TESTS_FAILED=true" "$TEST_DIR/metadata.txt"; then |
| 93 | + echo "❌ ERROR: CI_TESTS_FAILED was not set to true despite test_model failing." |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | + |
| 97 | +PIVOT_CSV="$TEST_DIR/kernel_support_matrix-microbenchmarks.csv" |
| 98 | +if [[ ! -f "$PIVOT_CSV" ]]; then |
| 99 | + echo "❌ ERROR: Pivoted Microbenchmark CSV not uploaded." |
| 100 | + exit 1 |
| 101 | +fi |
| 102 | + |
| 103 | +# Verify header |
| 104 | +if ! grep -q "Kernel,W16 A16 (Corr),W16 A16 (Perf),W8 A8 (Corr),W8 A8 (Perf),W8 A16 (Corr),W8 A16 (Perf),W4 A4 (Corr),W4 A4 (Perf),W4 A8 (Corr),W4 A8 (Perf),W4 A16 (Corr),W4 A16 (Perf)" "$PIVOT_CSV"; then |
| 105 | + echo "❌ ERROR: Incorrect Pivot Header." |
| 106 | + cat "$PIVOT_CSV" |
| 107 | + exit 1 |
| 108 | +fi |
| 109 | + |
| 110 | +# Verify mla outputs correctly |
| 111 | +if ! grep -q "\"mla\*\",✅ Passing,❓ Untested,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A" "$PIVOT_CSV"; then |
| 112 | + echo "❌ ERROR: mla parsing failed or default values are incorrect." |
| 113 | + cat "$PIVOT_CSV" |
| 114 | + exit 1 |
| 115 | +fi |
| 116 | + |
| 117 | +# Verify fused_moe outputs correctly |
| 118 | +if ! grep -q "\"fused_moe\",⚪ N/A,⚪ N/A,❓ Untested,❓ Untested,✅ Passing,✅ Passing,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A" "$PIVOT_CSV"; then |
| 119 | + echo "❌ ERROR: fused_moe parsing failed." |
| 120 | + cat "$PIVOT_CSV" |
| 121 | + exit 1 |
| 122 | +fi |
| 123 | + |
| 124 | +# Verify string substitution correctness |
| 125 | +if ! grep -q "\"generic ragged paged attention v3\*\",✅ Passing,✅ Passing,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A,⚪ N/A" "$PIVOT_CSV"; then |
| 126 | + echo "❌ ERROR: generic ragged paged attention v3 substitution failed." |
| 127 | + cat "$PIVOT_CSV" |
| 128 | + exit 1 |
| 129 | +fi |
| 130 | + |
| 131 | +echo "✅ All tests passed successfully!" |
0 commit comments