diff --git a/scripts/kernel-set-check.sh b/scripts/kernel-set-check.sh index a5d703463..7b7bb931b 100755 --- a/scripts/kernel-set-check.sh +++ b/scripts/kernel-set-check.sh @@ -229,17 +229,47 @@ fi # engine#2599: two ELFs with the same content under different names is a refusal. See the header for why a # hash is the only host-side instrument that can see it. check_twins() { - local dir=$1 dup + # engine#2611 tolerates exactly ONE shape of twin at load: a prefill ELF byte-identical to its own `_m16` + # sibling, where open_prefill sizes the context from the twin's 16 rows and says so. That pack is correct but + # SLOW (16 rows a chunk instead of 128), so it is a WARNING here -- refusing it would block a pack the loader + # now runs. Any OTHER identical pair has no such reconciliation and stays a FAIL. + local dir=$1 dup fail_list="" warn_list="" h name prev="" prevname="" dup=$(find "$dir" -maxdepth 2 -name '*.elf' -type f -print0 2>/dev/null | - xargs -0 -r md5sum 2>/dev/null | sort | awk '{h=$1; $1=""; if (h==prev) print prevname " and" $0; prev=h; prevname=$0}') - if [ -n "$dup" ]; then - printf 'FAIL %s: ELFs with identical content under different names (a copied twin computes the wrong M):\n%s\n' \ - "$(basename "$dir")" "$dup" + xargs -0 -r md5sum 2>/dev/null | sort | awk '{print $1, $2}') + while read -r h name; do + [ -n "$h" ] || continue + if [ "$h" = "$prev" ]; then + local base_a=${prevname##*/} base_b=${name##*/} + # Compare the GEOMETRY, not the role or the suffix. Identical content is expected -- and correct -- + # when two names encode the same design: gate and up are both K5120 x N17408, so one ELF serves both + # roles and the stock sets ship it that way (engine#2599 review at 08:51Z). A `_m16` / `_t2s2_m16` + # suffix is the same design at a smaller M, which open_prefill reroutes and notes by name. Identical + # content under DIFFERENT K or N is the defect: one build copied over another's name, so a 128-row + # chunk computes 16 rows. + local ga gb + ga=$(printf '%s' "$base_a" | grep -oE '_K[0-9]+_N[0-9]+' | head -1) + gb=$(printf '%s' "$base_b" | grep -oE '_K[0-9]+_N[0-9]+' | head -1) + if [ -n "$ga" ] && [ "$ga" = "$gb" ]; then + warn_list="$warn_list + $prevname and $name (same geometry: one design under two role/suffix names)" + else + fail_list="$fail_list + $prevname and $name" + fi + fi + prev=$h; prevname=$name + done <<< "$dup" + if [ -n "$warn_list" ]; then + printf 'WARN %s: byte-identical ELFs that encode the same geometry (expected: gate and up share one design, and a _m16 twin is the same design at a smaller M):%s\n' \ + "$(basename "$dir")" "$warn_list" + fi + if [ -n "$fail_list" ]; then + printf 'FAIL %s: ELFs with identical content under names with DIFFERENT geometry (one build copied over another name):%s\n' \ + "$(basename "$dir")" "$fail_list" return 1 fi return 0 } - rc=0 for dir in "$@"; do check_set "$dir" || { rc=$?; [ "$rc" -gt 1 ] && rc=2; } diff --git a/tests/kernel_set_check_test.sh b/tests/kernel_set_check_test.sh index c5a8aa73e..1f9c7c13a 100755 --- a/tests/kernel_set_check_test.sh +++ b/tests/kernel_set_check_test.sh @@ -236,16 +236,37 @@ mkdir -p "$tmp/twin/good" "$tmp/twin/dup" printf 'A' > "$tmp/twin/good/full_i8_O_K768_N768_b8.elf" printf 'B' > "$tmp/twin/good/full_i8_O_K768_N768_b8_m16.elf" printf 'A' > "$tmp/twin/dup/full_i8_O_K768_N768_b8.elf" -printf 'A' > "$tmp/twin/dup/full_i8_O_K768_N768_b8_m16.elf" +printf 'A' > "$tmp/twin/dup/full_i8_GU_K768_N3072_b8.elf" # NOT a _m16 twin: no documented reconciliation "$script" "$tmp/twin/good" > "$tmp/out21" 2>&1 check $([ $? -ne 0 ] || ! has "$tmp/out21" "identical content" && echo ok || echo fail) \ "distinct ELFs are not reported as twins" "$script" "$tmp/twin/dup" > "$tmp/out22" 2>&1 check $(has "$tmp/out22" "identical content" && echo ok || echo fail) \ "two ELFs with the same content are refused" -check $(has "$tmp/out22" "full_i8_O_K768_N768_b8.elf" && has "$tmp/out22" "_m16.elf" && echo ok || echo fail) \ +check $(has "$tmp/out22" "full_i8_O_K768_N768_b8.elf" && has "$tmp/out22" "full_i8_GU_K768_N3072_b8.elf" && echo ok || echo fail) \ "... and both paths are named" +# engine#2599 review (08:51Z): the real sets ship ONE ELF serving two roles when the geometry matches -- gate +# and up are both K5120 x N17408 -- and a `_m16` twin is the same design at a smaller M. Both are expected, so +# both WARN. Identical content under DIFFERENT geometry is the defect and still FAILs. +mkdir -p "$tmp/twin/real_stock" "$tmp/twin/real_m16" "$tmp/twin/real_cross" "$tmp/twin/real_bad" +printf 'A' > "$tmp/twin/real_stock/full_i8_G_K5120_N17408.elf" +printf 'A' > "$tmp/twin/real_stock/full_i8_U_K5120_N17408.elf" +printf 'A' > "$tmp/twin/real_m16/full_i8_G_K5120_N17408_m16.elf" +printf 'A' > "$tmp/twin/real_m16/full_i8_U_K5120_N17408_m16.elf" +printf 'A' > "$tmp/twin/real_cross/full_i8_G_K5120_N17408_m16.elf" +printf 'A' > "$tmp/twin/real_cross/full_i8_U_K5120_N17408.elf" +printf 'A' > "$tmp/twin/real_bad/full_i8_G_K5120_N17408.elf" +printf 'A' > "$tmp/twin/real_bad/full_i8_U_K5120_N5120.elf" +for d in real_stock real_m16 real_cross; do + "$script" "$tmp/twin/$d" > "$tmp/out-$d" 2>&1 + check $(has "$tmp/out-$d" "WARN" && ! has "$tmp/out-$d" "DIFFERENT geometry" && echo ok || echo fail) \ + "a real-set shape ($d) is warned about, not refused" +done +"$script" "$tmp/twin/real_bad" > "$tmp/out-real_bad" 2>&1 +check $(has "$tmp/out-real_bad" "DIFFERENT geometry" && echo ok || echo fail) \ + "identical content under different geometry is refused" + if [ "$fails" -ne 0 ]; then printf 'kernel_set_check: %d failure(s)\n' "$fails" exit 1