Skip to content

Commit a749f5f

Browse files
committed
add random offset
1 parent f212c33 commit a749f5f

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

scripts/task_test_blackwell_kernels.sh

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ set -eo pipefail
77
: ${CUDA_VISIBLE_DEVICES:=0}
88
: ${SAMPLE_RATE:=5} # Run every Nth test in sanity mode (5 = ~20% coverage)
99

10+
# Randomize starting offset (0 to SAMPLE_RATE-1) for sampling variety
11+
if [ -z "${SAMPLE_OFFSET:-}" ]; then
12+
SAMPLE_OFFSET=$((RANDOM % SAMPLE_RATE))
13+
fi
14+
1015
# Clean Python bytecode cache to avoid stale imports (e.g., after module refactoring)
1116
echo "Cleaning Python bytecode cache..."
1217
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@@ -38,6 +43,7 @@ fi
3843

3944
if [ "$SANITY_TEST" = "true" ]; then
4045
echo "🔬 SANITY TEST MODE - Running every ${SAMPLE_RATE}th test (~$((100 / SAMPLE_RATE))% coverage)"
46+
echo " Sampling pattern: offset=${SAMPLE_OFFSET} (tests #${SAMPLE_OFFSET}, #$((SAMPLE_OFFSET + SAMPLE_RATE)), #$((SAMPLE_OFFSET + SAMPLE_RATE * 2))...)"
4147
echo ""
4248
else
4349
echo "📋 FULL TEST MODE - Running all tests from each test file"
@@ -212,13 +218,17 @@ if [ "$DRY_RUN" == "true" ]; then
212218
TOTAL_IN_FILE=$(echo "$ALL_NODE_IDS" | wc -l)
213219
TOTAL_TEST_CASES=$((TOTAL_TEST_CASES + TOTAL_IN_FILE))
214220

215-
# Sample every Nth test
216-
SAMPLED_NODE_IDS=$(echo "$ALL_NODE_IDS" | awk "NR % $SAMPLE_RATE == 1")
221+
# Sample every Nth test with random offset
222+
SAMPLED_NODE_IDS=$(echo "$ALL_NODE_IDS" | awk "NR % $SAMPLE_RATE == $SAMPLE_OFFSET")
223+
# Fallback: if no tests sampled (offset missed all tests), take the first test
224+
if [ -z "$SAMPLED_NODE_IDS" ] || [ $(echo "$SAMPLED_NODE_IDS" | wc -l) -eq 0 ]; then
225+
SAMPLED_NODE_IDS=$(echo "$ALL_NODE_IDS" | head -1)
226+
fi
217227
SAMPLED_IN_FILE=$(echo "$SAMPLED_NODE_IDS" | wc -l)
218228
SAMPLED_TEST_CASES=$((SAMPLED_TEST_CASES + SAMPLED_IN_FILE))
219229

220230
echo " Total test cases: $TOTAL_IN_FILE"
221-
echo " Sampled test cases: $SAMPLED_IN_FILE (every ${SAMPLE_RATE}th test)"
231+
echo " Sampled test cases: $SAMPLED_IN_FILE (every ${SAMPLE_RATE}th test, offset ${SAMPLE_OFFSET})"
222232
echo " Sample of tests that would run:"
223233
echo "$SAMPLED_NODE_IDS" | head -5 | sed 's/^/ /' || true
224234
if [ "$SAMPLED_IN_FILE" -gt 5 ]; then
@@ -238,7 +248,10 @@ if [ "$DRY_RUN" == "true" ]; then
238248
else
239249
echo "Coverage: N/A (no tests collected)"
240250
fi
241-
echo "Sample rate: every ${SAMPLE_RATE}th test"
251+
echo "Sample rate: every ${SAMPLE_RATE}th test, offset ${SAMPLE_OFFSET}"
252+
echo ""
253+
echo "To reproduce this exact run:"
254+
echo " SAMPLE_RATE=${SAMPLE_RATE} SAMPLE_OFFSET=${SAMPLE_OFFSET} $0 --sanity-test"
242255
else
243256
# Full test mode
244257
for test_file in $TEST_FILES; do
@@ -257,8 +270,14 @@ if [ "$DRY_RUN" == "true" ]; then
257270

258271
echo ""
259272
echo "To actually run the tests, execute without --dry-run:"
260-
echo " $0 $([ "$SANITY_TEST" == "true" ] && echo "--sanity-test")"
261-
echo "Or set DRY_RUN=false $0"
273+
if [ "$SANITY_TEST" == "true" ]; then
274+
echo " $0 --sanity-test"
275+
echo ""
276+
echo "To reproduce this exact sampling pattern:"
277+
echo " SAMPLE_RATE=${SAMPLE_RATE} SAMPLE_OFFSET=${SAMPLE_OFFSET} $0 --sanity-test"
278+
else
279+
echo " $0"
280+
fi
262281
else
263282
mkdir -p "${JUNIT_DIR}"
264283

@@ -298,13 +317,17 @@ else
298317
TOTAL_IN_FILE=$(echo "$ALL_NODE_IDS" | wc -l)
299318
TOTAL_TEST_CASES=$((TOTAL_TEST_CASES + TOTAL_IN_FILE))
300319

301-
# Sample every Nth test
302-
SAMPLED_NODE_IDS=$(echo "$ALL_NODE_IDS" | awk "NR % $SAMPLE_RATE == 1")
320+
# Sample every Nth test with random offset
321+
SAMPLED_NODE_IDS=$(echo "$ALL_NODE_IDS" | awk "NR % $SAMPLE_RATE == $SAMPLE_OFFSET")
322+
# Fallback: if no tests sampled (offset missed all tests), take the first test
323+
if [ -z "$SAMPLED_NODE_IDS" ] || [ $(echo "$SAMPLED_NODE_IDS" | wc -l) -eq 0 ]; then
324+
SAMPLED_NODE_IDS=$(echo "$ALL_NODE_IDS" | head -1)
325+
fi
303326
SAMPLED_IN_FILE=$(echo "$SAMPLED_NODE_IDS" | wc -l)
304327
SAMPLED_TEST_CASES=$((SAMPLED_TEST_CASES + SAMPLED_IN_FILE))
305328

306329
echo "Total test cases in file: $TOTAL_IN_FILE"
307-
echo "Running sampled test cases: $SAMPLED_IN_FILE (every ${SAMPLE_RATE}th test)"
330+
echo "Running sampled test cases: $SAMPLED_IN_FILE (every ${SAMPLE_RATE}th test, offset ${SAMPLE_OFFSET})"
308331

309332
if [ "$SAMPLED_IN_FILE" -eq 0 ]; then
310333
echo "⚠️ No tests sampled from $test_file, skipping"
@@ -347,7 +370,10 @@ else
347370
else
348371
echo "Coverage: N/A (no tests collected)"
349372
fi
350-
echo "Sample rate: every ${SAMPLE_RATE}th test"
373+
echo "Sample rate: every ${SAMPLE_RATE}th test, offset ${SAMPLE_OFFSET}"
374+
echo ""
375+
echo "To reproduce this exact run:"
376+
echo " SAMPLE_RATE=${SAMPLE_RATE} SAMPLE_OFFSET=${SAMPLE_OFFSET} $0 --sanity-test"
351377

352378
if [ -n "$FAILED_TESTS" ]; then
353379
echo ""

0 commit comments

Comments
 (0)