Repository navigation
Commit ab3198f
committed
[MLX] Avoid standalone target forwards between DFlash rounds
MLX DFlash decoding currently runs a standalone target forward before each draft and verification round. For eligible singleton token batches, draft directly from the uncommitted input token and let verification commit the anchor and accepted proposals. Preserve the existing path for mixed inputs, empty pending context, and context tails. This applies to both original DFlash and DFlash2.
Verify greedy proposals against the target sample already drawn for each absolute position. This keeps RNG selection stable across prompt chunking and batch composition when the shortcut is enabled, and removes retained vocabulary probability arrays. The original baseline passes the schedule test; the inconsistency occurs in the shortcut without this sampling change.
Native sampling, batching, and serialized DFlash suites pass, including temperature 0.8 distributions, top-k/top-p, cache lifecycle, shared-payload input offsets, and fallback paths. An input-sensitive original-DFlash fixture also exercises target-only/speculative parity, reset, clone, and rewind. A wrong-anchor mutation passes the old continuation test and fails the new slice checks for both draft formats. The same 96 schedule cases pass on the unchanged baseline, sampling-only control, and combined implementation; the shortcut before the sampling change fails for both draft formats. Lintrunner and git diff --check pass.
Measured actual serving through the unmodified loopback `/v1/chat/completions` endpoint on M5 Max (64 GB), with full Q4_K_M target/draft models and FP16 activations. Baseline is the parent stack (83884a8004); production workers differ only in the MLX executor. One active request, four short prompts, 64 generated tokens, three measured repetitions per prompt after excluded warmups (288 measured requests), seed 42, top-k 0/top-p 1, `ignore_eos=true`, greedy drafts and target temperature 0 or 0.8. Fresh sessions, no prefix reuse; variant order AB/BA/AB. Model startup and cooling pauses between groups are excluded. These rates describe warmed single requests under controlled starting temperatures; sustained server capacity was not measured.
Server effective decode uses `(output_tokens - 1) / native_decode_seconds`, from the native runner's first output batch to completion. Speculative bursts give multiple tokens the same timestamp, including any burst delivered with the first token. HTTP end-to-end throughput includes preparation, tokenization, scheduling, inference and streaming through `[DONE]`. Both are pooled token counts divided by pooled latency; SSE fragments are not counted as tokens.
| Drafter | Temperature | Proposals | Server effective decode tok/s, before → after | HTTP end-to-end tok/s, before → after |
|---|---:|---:|---:|---:|
| DFlash | 0 | 3 | 48.51 → 59.85 (+23.4%) | 42.65 → 50.88 (+19.3%) |
| DFlash | 0 | 7 | 60.49 → 80.53 (+33.1%) | 51.23 → 64.69 (+26.3%) |
| DFlash | 0 | 15 | 84.50 → 108.88 (+28.8%) | 66.90 → 81.14 (+21.3%) |
| DFlash | 0.8 | 3 | 47.33 → 59.24 (+25.2%) | 41.70 → 50.40 (+20.8%) |
| DFlash | 0.8 | 7 | 60.05 → 75.39 (+25.5%) | 50.78 → 61.31 (+20.7%) |
| DFlash | 0.8 | 15 | 64.43 → 91.26 (+41.6%) | 53.72 → 70.81 (+31.8%) |
| DFlash2 | 0 | 3 | 48.00 → 62.00 (+29.2%) | 41.82 → 51.99 (+24.3%) |
| DFlash2 | 0 | 7 | 67.08 → 94.85 (+41.4%) | 55.44 → 72.59 (+30.9%) |
| DFlash2 | 0 | 15 | 87.19 → 118.54 (+35.9%) | 67.97 → 85.07 (+25.2%) |
| DFlash2 | 0.8 | 3 | 45.88 → 59.07 (+28.8%) | 40.20 → 49.84 (+24.0%) |
| DFlash2 | 0.8 | 7 | 62.68 → 85.47 (+36.4%) | 52.27 → 66.85 (+27.9%) |
| DFlash2 | 0.8 | 15 | 86.35 → 94.84 (+9.8%) | 67.21 → 72.06 (+7.2%) |
GPU frequency/activity/temperature and macOS thermal state were sampled every 200 ms. All measured request-window samples reported nominal thermal pressure, AC power and low power mode disabled, with 100.0% telemetry coverage. Maximum measured GPU temperature was 81.6 C. Per-case GPU active-time-weighted clocks ranged 1.490–1.510 GHz for baseline and 1.601–1.610 GHz for candidate (+6.3% to +8.0% paired differences). Within a fixed case and variant, repetition-average clocks varied by at most 0.8%. Clocks were monitored, not locked, so these are whole-system serving gains. An exploratory warmer run triggered fair thermal pressure and clocks around 1.0 GHz; it is excluded in full. Each group started after two seconds of nominal thermal state with GPU <=60 C / CPU <=70 C. These are experimental starting conditions, not hardware throttling thresholds.
All greedy visible HTTP responses match baseline, and seeded visible-text replay is stable in each variant across all conditions. Sampled old/new responses can differ at the same seed because target RNG coupling changes, so sampled gains include different token streams and acceptance patterns. Per-prompt HTTP means below baseline in this corpus: DFlash2, T=0.8, N=15, explanation: -6.7%; DFlash2, T=0.8, N=15, planning: -4.0%. A separate earlier, unmonitored native DFlash2/N=15/T=0.8 matched-sampler control produces identical tokens and improves prefill-plus-generation throughput 24.3% (warm decode 31.6%); that control is not an HTTP measurement. These means cover a small corpus with three repetitions, and longer FP16 runs have existing near-tie differences across verification shapes. Concurrency was not benchmarked. CUDA code and interfaces are unchanged.
Follow-up to #24811, tracked in #23011. Stacked on #25336.
Authored with AI assistance from OpenAI Codex.
ghstack-source-id: ea265ca
ghstack-comment-id: 7033163531
Pull-Request: #253371 parent 120045c commit ab3198f
5 files changed
Lines changed: 256 additions & 71 deletions
File tree
- examples/models/muse-glimmer
- runtime
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
662 | | - | |
663 | 662 | | |
664 | 663 | | |
665 | 664 | | |
| |||
675 | 674 | | |
676 | 675 | | |
677 | 676 | | |
678 | | - | |
| 677 | + | |
679 | 678 | | |
680 | 679 | | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
| 680 | + | |
690 | 681 | | |
691 | 682 | | |
692 | 683 | | |
| |||
879 | 870 | | |
880 | 871 | | |
881 | 872 | | |
882 | | - | |
883 | | - | |
| 873 | + | |
| 874 | + | |
884 | 875 | | |
885 | 876 | | |
886 | 877 | | |
| |||
903 | 894 | | |
904 | 895 | | |
905 | 896 | | |
906 | | - | |
| 897 | + | |
| 898 | + | |
907 | 899 | | |
908 | 900 | | |
909 | 901 | | |
| |||
914 | 906 | | |
915 | 907 | | |
916 | 908 | | |
917 | | - | |
| 909 | + | |
| 910 | + | |
918 | 911 | | |
919 | 912 | | |
920 | 913 | | |
| |||
930 | 923 | | |
931 | 924 | | |
932 | 925 | | |
933 | | - | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
934 | 930 | | |
935 | 931 | | |
936 | 932 | | |
| |||
940 | 936 | | |
941 | 937 | | |
942 | 938 | | |
943 | | - | |
944 | 939 | | |
945 | | - | |
| 940 | + | |
946 | 941 | | |
947 | 942 | | |
948 | 943 | | |
| |||
951 | 946 | | |
952 | 947 | | |
953 | 948 | | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
963 | 952 | | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
974 | 960 | | |
975 | | - | |
976 | 961 | | |
977 | 962 | | |
978 | 963 | | |
| |||
987 | 972 | | |
988 | 973 | | |
989 | 974 | | |
990 | | - | |
| 975 | + | |
991 | 976 | | |
992 | 977 | | |
993 | 978 | | |
994 | 979 | | |
995 | 980 | | |
996 | | - | |
| 981 | + | |
997 | 982 | | |
998 | 983 | | |
999 | 984 | | |
| |||
1014 | 999 | | |
1015 | 1000 | | |
1016 | 1001 | | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1017 | 1038 | | |
1018 | 1039 | | |
1019 | 1040 | | |
| |||
1055 | 1076 | | |
1056 | 1077 | | |
1057 | 1078 | | |
1058 | | - | |
| 1079 | + | |
1059 | 1080 | | |
1060 | 1081 | | |
1061 | 1082 | | |
| |||
1119 | 1140 | | |
1120 | 1141 | | |
1121 | 1142 | | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
| 1143 | + | |
| 1144 | + | |
1128 | 1145 | | |
1129 | 1146 | | |
1130 | 1147 | | |
1131 | 1148 | | |
1132 | 1149 | | |
1133 | 1150 | | |
1134 | 1151 | | |
1135 | | - | |
| 1152 | + | |
1136 | 1153 | | |
1137 | 1154 | | |
1138 | 1155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
78 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
82 | | - | |
| 84 | + | |
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | | - | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
380 | | - | |
| 380 | + | |
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
416 | 417 | | |
417 | 418 | | |
418 | 419 | | |
| |||
0 commit comments