File size: 4,659 Bytes
727757f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# ─── Qwen SpeedLab: Benchmark Harness ────────────────────
# Comparative benchmarks: Baseline vs MTP vs DFlash vs TurboQuant
# Uses llama-bench for standardized measurements

source "$(dirname "$0")/common.sh"

BENCH_OUT="${LOG_DIR}/benchmark-$(date +%Y%m%d-%H%M%S).txt"

log "═══════════════════════════════════════════════"
log "Qwen SpeedLab Benchmark Suite"
log "Results: ${BENCH_OUT}"
log "═══════════════════════════════════════════════"

{
    echo "=============================================="
    echo "Qwen SpeedLab Benchmarks"
    echo "Date: $(date)"
    echo "GPU: $(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null || echo 'Unknown')"
    echo "Model: Qwen 3.6 27B Q4_K_M"
    echo "=============================================="
    echo ""

    # ─── 1. Autoregressive Baseline ─────────────────────
    echo "─── Benchmark 1: Autoregressive Baseline ───"
    "${LLAMA_BENCH}" \
        -m "${TARGET_MODEL}" \
        -ngl "${GPU_LAYERS}" \
        -b "${BATCH_SIZE}" \
        -ub "${UBATCH_SIZE}" \
        -p 512 \
        -n 256 \
        -fa 1 \
        --cache-type-k q4_0 \
        --cache-type-v q4_0 \
        2>&1
    echo ""

    # ─── 2. MTP Self-Speculative ────────────────────────
    echo "─── Benchmark 2: MTP Self-Speculative (n_max=3) ───"
    "${LLAMA_BENCH}" \
        -m "${TARGET_MODEL}" \
        -ngl "${GPU_LAYERS}" \
        -b "${BATCH_SIZE}" \
        -ub "${UBATCH_SIZE}" \
        -p 512 \
        -n 256 \
        -fa 1 \
        --cache-type-k q4_0 \
        --cache-type-v q4_0 \
        --spec-type draft-mtp \
        --spec-draft-n-max 3 \
        2>&1
    echo ""

    # ─── 3. MTP with TurboQuant KV ──────────────────────
    echo "─── Benchmark 3: MTP + TurboQuant KV (turbo3) ───"
    "${LLAMA_BENCH}" \
        -m "${TARGET_MODEL}" \
        -ngl "${GPU_LAYERS}" \
        -b "${BATCH_SIZE}" \
        -ub "${UBATCH_SIZE}" \
        -p 512 \
        -n 256 \
        -fa 1 \
        --cache-type-k turbo3 \
        --cache-type-v turbo3 \
        --spec-type draft-mtp \
        --spec-draft-n-max 3 \
        2>&1
    echo ""

    # ─── 4. DFlash Speculative Decoding ─────────────────
    if [ -f "${DFLASH_DRAFT}" ]; then
        echo "─── Benchmark 4: DFlash Speculative Decoding ───"
        "${LLAMA_BENCH}" \
            -m "${TARGET_MODEL}" \
            -md "${DFLASH_DRAFT}" \
            -ngl "${GPU_LAYERS}" \
            -b "${BATCH_SIZE}" \
            -ub "${UBATCH_SIZE}" \
            -p 512 \
            -n 256 \
            -fa 1 \
            --cache-type-k q4_0 \
            --cache-type-v q4_0 \
            --spec-type dflash \
            --spec-dflash-cross-ctx 1024 \
            2>&1
        echo ""
    fi

    # ─── 5. Long context stress test ────────────────────
    echo "─── Benchmark 5: Long Context (32K prompt) ───"
    "${LLAMA_BENCH}" \
        -m "${TARGET_MODEL}" \
        -ngl "${GPU_LAYERS}" \
        -b "${BATCH_SIZE}" \
        -ub "${UBATCH_SIZE}" \
        -p 32768 \
        -n 128 \
        -fa 1 \
        --cache-type-k q4_0 \
        --cache-type-v q4_0 \
        --spec-type draft-mtp \
        --spec-draft-n-max 3 \
        2>&1
    echo ""

} | tee "${BENCH_OUT}"

log "Benchmarks complete! Results saved to ${BENCH_OUT}"

# ─── Summary ─────────────────────────────────────────────
echo ""
echo "═══════════════════════════════════════════════"
echo "Quick Reference: Expected tok/s on RTX 3090"
echo "═══════════════════════════════════════════════"
echo "Baseline (autoregressive):    ~35-45 tok/s"
echo "MTP (self-speculative):       ~55-70 tok/s  (1.5-2x)"
echo "MTP + TurboQuant KV:          ~60-80 tok/s  (1.7-2.2x)"
echo "DFlash (block diffusion):     ~78-130 tok/s (2.2-3.5x)"
echo ""
echo "Note: Speed varies by task type."
echo "Code/structured β†’ highest; prose/creative β†’ lower"