diff --git a/data/settings-register.json b/data/settings-register.json index be83a7181a..64b5d0c3f0 100644 --- a/data/settings-register.json +++ b/data/settings-register.json @@ -169,7 +169,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13977, + "line": 13990, "backend": "cuda-hip", "fn": "a_env" } @@ -202,7 +202,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13976, + "line": 13989, "backend": "cuda-hip", "fn": "a_env" } @@ -271,13 +271,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13640, + "line": 13653, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21374, + "line": 21558, "backend": "cuda-hip", "fn": "getenv" } @@ -378,13 +378,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13467, + "line": 13480, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21363, + "line": 21547, "backend": "cuda-hip", "fn": "getenv" } @@ -419,13 +419,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13466, + "line": 13479, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21362, + "line": 21546, "backend": "cuda-hip", "fn": "getenv" } @@ -460,7 +460,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21364, + "line": 21548, "backend": "cuda-hip", "fn": "getenv" } @@ -658,7 +658,7 @@ }, { "file": "src/program/generate.cpp", - "line": 13565, + "line": 13578, "backend": "cuda-hip", "fn": "getenv" } @@ -697,13 +697,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13515, + "line": 13528, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 13516, + "line": 13529, "backend": "cuda-hip", "fn": "getenv" } @@ -736,7 +736,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13810, + "line": 13823, "backend": "cuda-hip", "fn": "getenv" } @@ -769,7 +769,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13975, + "line": 13988, "backend": "cuda-hip", "fn": "a_env" } @@ -802,7 +802,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13531, + "line": 13544, "backend": "cuda-hip", "fn": "getenv" } @@ -1910,7 +1910,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 956, + "line": 970, "backend": "cuda-hip", "fn": "getenv" } @@ -2046,7 +2046,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18057, + "line": 18162, "backend": "cuda-hip", "fn": "getenv" } @@ -2080,7 +2080,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17901, + "line": 18006, "backend": "cuda-hip", "fn": "getenv" }, @@ -2159,7 +2159,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14927, + "line": 15020, "backend": "cuda-hip", "fn": "getenv" } @@ -2192,7 +2192,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14929, + "line": 15022, "backend": "cuda-hip", "fn": "getenv" } @@ -2225,7 +2225,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14928, + "line": 15021, "backend": "cuda-hip", "fn": "getenv" } @@ -2552,7 +2552,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14948, + "line": 15041, "backend": "cuda-hip", "fn": "getenv" } @@ -2604,7 +2604,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18121, + "line": 18226, "backend": "cuda-hip", "fn": "getenv" } @@ -2791,7 +2791,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18662, + "line": 18767, "backend": "cuda-hip", "fn": "getenv" }, @@ -3064,13 +3064,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17343, + "line": 17448, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17476, + "line": 17581, "backend": "cuda-hip", "fn": "getenv" }, @@ -3206,7 +3206,7 @@ }, { "file": "src/program/generate.cpp", - "line": 20737, + "line": 20921, "backend": "cuda-hip", "fn": "getenv" } @@ -3242,7 +3242,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3368, + "line": 3444, "backend": "cuda-hip", "fn": "getenv" } @@ -3602,7 +3602,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 809, + "line": 823, "backend": "cuda-hip", "fn": "getenv" }, @@ -3666,7 +3666,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6650, + "line": 6862, "backend": "cuda-hip", "fn": "getenv" }, @@ -3705,7 +3705,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5321, + "line": 5397, "backend": "cuda-hip", "fn": "getenv" } @@ -3771,13 +3771,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4977, + "line": 5053, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7123, + "line": 7344, "backend": "cuda-hip", "fn": "getenv" } @@ -3810,7 +3810,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4983, + "line": 5059, "backend": "cuda-hip", "fn": "getenv" } @@ -3844,7 +3844,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5102, + "line": 5178, "backend": "cuda-hip", "fn": "getenv" }, @@ -3938,19 +3938,19 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 5682, + "line": 5860, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6603, + "line": 6815, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6827, + "line": 7048, "backend": "cuda-hip", "fn": "getenv" }, @@ -4010,19 +4010,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4978, + "line": 5054, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 4993, + "line": 5069, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7123, + "line": 7344, "backend": "cuda-hip", "fn": "getenv" } @@ -4089,7 +4089,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18909, + "line": 19014, "backend": "cuda-hip", "fn": "getenv" }, @@ -4659,13 +4659,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20094, + "line": 20229, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 20094, + "line": 20229, "backend": "cuda-hip", "fn": "getenv" } @@ -5587,7 +5587,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21726, + "line": 21910, "backend": "cuda-hip", "fn": "getenv" } @@ -6033,7 +6033,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4592, + "line": 4594, "backend": "cuda-hip", "fn": "env_on" } @@ -6061,6 +6061,39 @@ "retire_after": "", "retired_in": "" }, + { + "name": "STRATA_DRAFT_COSTS_LEARN", + "backends": [ + "cuda-hip" + ], + "reads": [ + { + "file": "src/program/generate.cpp", + "line": 14780, + "backend": "cuda-hip", + "fn": "getenv" + } + ], + "parse": "flag", + "default_state": "off", + "code_default": null, + "engine_sets": [], + "engine_defaults": [], + "launch_files": [], + "launch_sets": [], + "launch_reads": [], + "doc_mentions": [], + "first_commit": null, + "first_date": null, + "since": null, + "last_commit": null, + "last_date": null, + "status": "", + "owner": "", + "note": "", + "retire_after": "", + "retired_in": "" + }, { "name": "STRATA_DRAFT_KEEP", "backends": [ @@ -6069,13 +6102,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14691, + "line": 14741, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14691, + "line": 14741, "backend": "cuda-hip", "fn": "getenv" } @@ -6108,7 +6141,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14690, + "line": 14740, "backend": "cuda-hip", "fn": "getenv" } @@ -6148,7 +6181,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 2627, + "line": 2699, "backend": "cuda-hip", "fn": "getenv" }, @@ -6221,13 +6254,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19966, + "line": 20101, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21943, + "line": 22127, "backend": "cuda-hip", "fn": "getenv" }, @@ -6268,12 +6301,12 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5479, + "line": 5555, "backend": "cuda-hip", "fn": "getenv" } ], - "parse": "int", + "parse": "string", "default_state": null, "code_default": null, "engine_sets": [], @@ -6304,18 +6337,24 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5481, + "line": 5559, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 5481, + "line": 5562, + "backend": "cuda-hip", + "fn": "getenv" + }, + { + "file": "src/prefill/prefill.cpp", + "line": 5562, "backend": "cuda-hip", "fn": "getenv" } ], - "parse": "string", + "parse": "int", "default_state": null, "code_default": null, "engine_sets": [], @@ -6327,8 +6366,8 @@ "first_commit": "e51b4379dc", "first_date": "2026-10-12", "since": "v0.1.44", - "last_commit": "e51b4379dc", - "last_date": "2026-10-12", + "last_commit": "10e3399f0d", + "last_date": "2026-11-12", "status": "research", "owner": "prefill", "note": "Research: the layer whose first-chunk MoE input STRATA_DUMP_MOE_INPUT writes; \"all\" writes every layer of the first chunk to .L (the rows for the bench's --real mode).", @@ -6484,7 +6523,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 608, + "line": 622, "backend": "cuda-hip", "fn": "getenv" } @@ -6699,7 +6738,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4082, + "line": 4084, "backend": "cuda-hip", "fn": "env_on" } @@ -6747,7 +6786,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4086, + "line": 4088, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6783,7 +6822,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4091, + "line": 4093, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6821,7 +6860,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4084, + "line": 4086, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6856,7 +6895,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4093, + "line": 4095, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6889,7 +6928,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4085, + "line": 4087, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6924,7 +6963,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4094, + "line": 4096, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6959,7 +6998,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4083, + "line": 4085, "backend": "cuda-hip", "fn": "env_int_or" } @@ -6994,7 +7033,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4092, + "line": 4094, "backend": "cuda-hip", "fn": "env_int_or" } @@ -7029,12 +7068,12 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6241, + "line": 6243, "backend": "cuda-hip", "fn": "getenv" } ], - "parse": "flag", + "parse": "string", "default_state": null, "code_default": null, "engine_sets": [], @@ -7043,11 +7082,11 @@ "launch_sets": [], "launch_reads": [], "doc_mentions": [], - "first_commit": "", - "first_date": "", - "since": "", - "last_commit": "", - "last_date": "", + "first_commit": "fe67f7fbeb", + "first_date": "2026-11-12", + "since": null, + "last_commit": "75d929ebf7", + "last_date": "2026-11-13", "status": "rollback", "owner": "kernels", "note": "CUDA / HIP, not a user setting. Unset: the HIP cards gfx1030 / gfx1031 / gfx1032 (RX 6000 series RDNA2, no matrix cores) run a prompt layer's expert groups on our own int8 dot-product kernels (native_expert_i8) for the gate/up formats IQ2_XXS, IQ2_XS, IQ3_XXS, IQ3_S and IQ2_S with an IQ4_NL or Q2_0 down, in the prompt path's MMQ groups of 256 entries or more (include/strata/kernels/i8_expert_rule.hpp); every other card is unchanged in a build with MMQ. In a build without llama.cpp's MMQ (-DSTRATA_MMQ=OFF, or HIP without STRATA_PREFILL_MMQ) unset means on for every card and every layer the kernel covers that the fused kernels and the staged group entry do not take (otherwise the layer would run on the per-expert FP16 path); on a Tesla P100 (compute capability 6.0, no dp4a) that default applies only to prompt chunks under the stream floor (stream_all_min, 1,024 tokens), the FP16 path from it up, as the build with MMQ does there. =0 goes back to the old kernels on that class, or to the FP16 path in a build without MMQ (the way back). =1 asks for the int8 kernels on any card (a layer the fused kernels take stays on them; on a card with fused kernels set STRATA_PF_FUSED=0 as well) and, as the only way, in native_expert_grouped (the Qwen3.6 engine's prompt). Goes away with MMQ (release C) or stays as the only path.", @@ -7241,7 +7280,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6293, + "line": 6450, "backend": "cuda-hip", "fn": "getenv" }, @@ -7300,7 +7339,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6311, + "line": 6468, "backend": "cuda-hip", "fn": "getenv" }, @@ -7350,13 +7389,13 @@ }, { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6169, + "line": 6171, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6215, + "line": 6217, "backend": "cuda-hip", "fn": "getenv" }, @@ -7409,13 +7448,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2284, + "line": 2351, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6889, + "line": 7110, "backend": "cuda-hip", "fn": "getenv" } @@ -7791,7 +7830,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18848, + "line": 18953, "backend": "cuda-hip", "fn": "getenv" }, @@ -7833,7 +7872,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18863, + "line": 18968, "backend": "cuda-hip", "fn": "getenv" }, @@ -8128,7 +8167,7 @@ }, { "file": "src/program/generate.cpp", - "line": 18192, + "line": 18297, "backend": "cuda-hip", "fn": "env_on" } @@ -9720,7 +9759,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6155, + "line": 6157, "backend": "cuda-hip", "fn": "getenv" } @@ -9867,7 +9906,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 637, + "line": 651, "backend": "hip", "fn": "getenv" } @@ -10153,7 +10192,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6236, + "line": 6238, "backend": "cuda-hip", "fn": "env_on" }, @@ -10193,7 +10232,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2207, + "line": 2274, "backend": "cuda-hip", "fn": "getenv" }, @@ -10851,7 +10890,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 835, + "line": 849, "backend": "cuda-hip", "fn": "getenv" }, @@ -11206,7 +11245,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4254, + "line": 4256, "backend": "cuda-hip", "fn": "getenv" } @@ -11249,7 +11288,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 687, + "line": 701, "backend": "cuda-hip", "fn": "getenv" } @@ -11284,7 +11323,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 704, + "line": 718, "backend": "cuda-hip", "fn": "getenv" } @@ -11318,7 +11357,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 791, + "line": 805, "backend": "cuda-hip", "fn": "getenv" }, @@ -11732,7 +11771,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 764, + "line": 778, "backend": "cuda-hip", "fn": "getenv" }, @@ -11804,7 +11843,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4516, + "line": 4592, "backend": "cuda-hip", "fn": "getenv" }, @@ -12394,7 +12433,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6467, + "line": 6624, "backend": "hip", "fn": "env_on" }, @@ -12668,25 +12707,25 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6291, + "line": 6373, "backend": "cuda-hip", - "fn": "getenv" + "fn": "i8_env_int" } ], - "parse": "int", + "parse": "string", "default_state": null, - "code_default": "0", + "code_default": null, "engine_sets": [], "engine_defaults": [], "launch_files": [], "launch_sets": [], "launch_reads": [], "doc_mentions": [], - "first_commit": "", - "first_date": "", - "since": "", - "last_commit": "", - "last_date": "", + "first_commit": "f123a0d000", + "first_date": "2026-11-12", + "since": null, + "last_commit": "79606603f0", + "last_date": "2026-11-13", "status": "research", "owner": "kernels", "note": "Debug only: STRATA_EXPERT_I8's kernels return at point n, uniform over the block (a fault hunt on HIP). 0: off.", @@ -12701,25 +12740,25 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1566, + "line": 1708, "backend": "cuda-hip", "fn": "getenv" } ], "parse": "int", "default_state": null, - "code_default": "0", + "code_default": null, "engine_sets": [], "engine_defaults": [], "launch_files": [], "launch_sets": [], "launch_reads": [], "doc_mentions": [], - "first_commit": "", - "first_date": "", - "since": "", - "last_commit": "", - "last_date": "", + "first_commit": "ab35aff9bc", + "first_date": "2026-11-12", + "since": null, + "last_commit": "ab35aff9bc", + "last_date": "2026-11-12", "status": "research", "owner": "kernels", "note": "Debug only: prints one line per prompt chunk with the routed entries that ran on native_expert_i8 and the ones that stayed on the group walk's own kernels. 0: off.", @@ -12753,8 +12792,8 @@ "first_commit": "2856a8045e", "first_date": "2026-10-18", "since": "v0.2.1", - "last_commit": "ebdfaacd1c", - "last_date": "2026-10-18", + "last_commit": "fe67f7fbeb", + "last_date": "2026-11-12", "status": "opt-in", "owner": "sycl/prefill", "note": "[auto] documented for users (docs/INTEL_INT8_EXPERTS.md:27)", @@ -12769,7 +12808,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6293, + "line": 6312, "backend": "cuda-hip", "fn": "getenv" } @@ -12783,11 +12822,11 @@ "launch_sets": [], "launch_reads": [], "doc_mentions": [], - "first_commit": null, - "first_date": null, + "first_commit": "65035696af", + "first_date": "2026-11-13", "since": null, - "last_commit": null, - "last_date": null, + "last_commit": "79606603f0", + "last_date": "2026-11-13", "status": "research", "owner": "kernels", "note": "Research: the few-rows route of STRATA_EXPERT_I8's prompt path: a layer whose experts average fewer routed rows than the limit runs on the grouped kernels instead of the int8 kernel. Not set: 6 on a Tesla P100, 7 elsewhere (8 and 10 with STRATA_I8_N8=0). 0: off (the int8 kernel keeps its 256-entry floor). N: a limit of N rows per expert.", @@ -12907,7 +12946,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6354, + "line": 6373, "backend": "cuda-hip", "fn": "getenv" } @@ -12934,6 +12973,11 @@ "launch_sets": [], "launch_reads": [], "doc_mentions": [], + "first_commit": "ab7da27849", + "first_date": "2026-11-13", + "since": null, + "last_commit": "79606603f0", + "last_date": "2026-11-13", "status": "research", "owner": "kernels", "note": "The 8-entry slices of the tile-2..4 int8 expert kernel (STRATA_EXPERT_I8's prompt path; two weight rows and one entry of each 8-entry slice per thread; output bit-identical). Not set: on for tile 2 (up to about 1,950 tokens at Flash-Next's shape), off for tiles 3 and above. 1: tiles 2 to 4. 0: off.", @@ -12948,25 +12992,42 @@ "reads": [ { "file": "src/kernels/cuda/i8_expert.cuh", - "line": 833, + "line": 1195, "backend": "cuda-hip", - "fn": "getenv" + "fn": "i8_env_int" } ], - "parse": "int", + "parse": "flag", "default_state": null, - "code_default": "0", - "engine_sets": [], + "code_default": null, + "engine_sets": [ + { + "file": "src/kernels/native_i8_parity.cpp", + "line": 206 + }, + { + "file": "src/kernels/native_i8_parity.cpp", + "line": 208 + }, + { + "file": "src/kernels/native_i8_parity.cpp", + "line": 234 + }, + { + "file": "src/kernels/native_i8_parity.cpp", + "line": 237 + } + ], "engine_defaults": [], "launch_files": [], "launch_sets": [], "launch_reads": [], "doc_mentions": [], - "first_commit": "", - "first_date": "", - "since": "", - "last_commit": "", - "last_date": "", + "first_commit": "ca38bf15df", + "first_date": "2026-11-12", + "since": null, + "last_commit": "c8461ce39e", + "last_date": "2026-11-12", "status": "research", "owner": "kernels", "note": "Test only: pretends the card has this many bytes of shared memory per block, so STRATA_EXPERT_I8's kernels fall to a smaller tile or answer 'not supported' (native_i8_parity uses it).", @@ -12981,25 +13042,34 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6281, + "line": 6363, "backend": "cuda-hip", - "fn": "getenv" + "fn": "i8_env_int" } ], - "parse": "int", + "parse": "flag", "default_state": null, - "code_default": "0", - "engine_sets": [], + "code_default": null, + "engine_sets": [ + { + "file": "src/kernels/native_i8_parity.cpp", + "line": 233 + }, + { + "file": "src/kernels/native_i8_parity.cpp", + "line": 236 + } + ], "engine_defaults": [], "launch_files": [], "launch_sets": [], "launch_reads": [], "doc_mentions": [], - "first_commit": "", - "first_date": "", - "since": "", - "last_commit": "", - "last_date": "", + "first_commit": "fe67f7fbeb", + "first_date": "2026-11-12", + "since": null, + "last_commit": "ca38bf15df", + "last_date": "2026-11-12", "status": "research", "owner": "kernels", "note": "Research: the tile of STRATA_EXPERT_I8's kernels, 2, 3 or 4 rows of 16 entries per thread (32, 48 or 64 entries a block), 8 = the 128-entry tile. Unset: chosen by the entries per expert.", @@ -13050,7 +13120,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4849, + "line": 4925, "backend": "cuda-hip", "fn": "getenv" }, @@ -13199,13 +13269,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4714, + "line": 4790, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8255, + "line": 8476, "backend": "cuda-hip", "fn": "getenv" }, @@ -13838,7 +13908,7 @@ }, { "file": "src/program/generate.cpp", - "line": 20737, + "line": 20921, "backend": "cuda-hip", "fn": "getenv" } @@ -14313,7 +14383,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3424, + "line": 3426, "backend": "cuda-hip", "fn": "getenv" }, @@ -14357,7 +14427,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3431, + "line": 3433, "backend": "cuda-hip", "fn": "getenv" }, @@ -14396,7 +14466,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3442, + "line": 3444, "backend": "cuda-hip", "fn": "getenv" } @@ -14583,7 +14653,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 912, + "line": 914, "backend": "cuda-hip", "fn": "getenv" }, @@ -14829,7 +14899,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4571, + "line": 4647, "backend": "cuda-hip", "fn": "getenv" } @@ -15296,7 +15366,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17317, + "line": 17422, "backend": "cuda-hip", "fn": "getenv" } @@ -15410,13 +15480,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4656, + "line": 4732, "backend": "hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8202, + "line": 8423, "backend": "hip", "fn": "getenv" }, @@ -15534,7 +15604,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3678, + "line": 3754, "backend": "cuda-hip", "fn": "getenv" }, @@ -15655,7 +15725,7 @@ }, { "file": "src/program/generate.cpp", - "line": 12637, + "line": 12639, "backend": "cuda-hip", "fn": "getenv" }, @@ -15705,7 +15775,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1519, + "line": 1536, "backend": "cuda-hip", "fn": "getenv" }, @@ -16090,7 +16160,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7090, + "line": 7311, "backend": "hip", "fn": "getenv" } @@ -16123,7 +16193,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7486, + "line": 7707, "backend": "cuda-hip", "fn": "getenv" } @@ -16201,19 +16271,19 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17631, + "line": 17736, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17671, + "line": 17776, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 18708, + "line": 18813, "backend": "cuda-hip", "fn": "getenv" }, @@ -16269,7 +16339,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17675, + "line": 17780, "backend": "cuda-hip", "fn": "getenv" }, @@ -16474,13 +16544,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18881, + "line": 18986, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21840, + "line": 22024, "backend": "cuda-hip", "fn": "getenv" }, @@ -19075,8 +19145,8 @@ "first_commit": "86f677b4a9", "first_date": "2026-10-14", "since": "v0.1.45", - "last_commit": "3feffd5970", - "last_date": "2026-11-11", + "last_commit": "3a4763217c", + "last_date": "2026-11-12", "status": "opt-in", "owner": "prefill", "note": "[reviewed] Documented opt-in needing STRATA_MMQ_TAB build; E23 rejected it as default but it is a user feature. [docs/DETAILS.md:1081]", @@ -19091,7 +19161,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 8532, + "line": 8753, "backend": "cuda-hip", "fn": "getenv" } @@ -20354,7 +20424,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2549, + "line": 2621, "backend": "cuda-hip", "fn": "getenv" }, @@ -20394,7 +20464,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2593, + "line": 2665, "backend": "cuda-hip", "fn": "getenv" }, @@ -20434,7 +20504,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2554, + "line": 2626, "backend": "cuda-hip", "fn": "getenv" }, @@ -21160,7 +21230,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 4941, + "line": 4943, "backend": "cuda-hip", "fn": "getenv" } @@ -22114,7 +22184,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3421, + "line": 3423, "backend": "cuda-hip", "fn": "env_on" }, @@ -22533,7 +22603,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3420, + "line": 3422, "backend": "cuda-hip", "fn": "env_on" }, @@ -22961,25 +23031,25 @@ }, { "file": "src/program/generate.cpp", - "line": 12572, + "line": 12574, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 12576, + "line": 12578, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 12582, + "line": 12584, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 12925, + "line": 12937, "backend": "cuda-hip", "fn": "getenv" } @@ -23679,7 +23749,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13326, + "line": 13339, "backend": "cuda-hip", "fn": "getenv" } @@ -23861,7 +23931,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18625, + "line": 18730, "backend": "cuda-hip", "fn": "getenv" }, @@ -23908,7 +23978,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 844, + "line": 858, "backend": "cuda-hip", "fn": "getenv" } @@ -23941,7 +24011,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 5150, + "line": 5226, "backend": "cuda-hip", "fn": "getenv" } @@ -24010,7 +24080,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 760, + "line": 774, "backend": "cuda-hip", "fn": "getenv" } @@ -24195,7 +24265,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6192, + "line": 6396, "backend": "cuda-hip", "fn": "getenv" } @@ -24345,7 +24415,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 285, + "line": 294, "backend": "cuda-hip", "fn": "getenv" }, @@ -24421,8 +24491,8 @@ "first_commit": "47de4a4d83", "first_date": "2026-10-02", "since": "v0.1.40.1", - "last_commit": "d1ec6f0397", - "last_date": "2026-11-12", + "last_commit": "c55e0f829d", + "last_date": "2026-11-13", "status": "default", "owner": "core", "note": "[auto] on by default for some GPU architectures only (gfx1151 (Windows) src/core/arch_defaults.cpp:196=1; gfx1103 / gfx1150 / gfx1151 (Linux, integrated) src/core/arch_defaults.cpp:376=1; sm_121 src/core/nv_defaults.cpp:66=1); opt-in elsewhere; the variable overrides it; =0 keeps MMQ", @@ -25136,7 +25206,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 817, + "line": 831, "backend": "cuda-hip", "fn": "getenv" }, @@ -25213,7 +25283,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1926, + "line": 1991, "backend": "cuda-hip", "fn": "getenv" } @@ -25246,7 +25316,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1906, + "line": 1971, "backend": "cuda-hip", "fn": "getenv" } @@ -25265,8 +25335,8 @@ "first_commit": "fbf6e1c753", "first_date": "2026-10-31", "since": "v0.2.10", - "last_commit": "3feffd5970", - "last_date": "2026-11-11", + "last_commit": "3a4763217c", + "last_date": "2026-11-12", "status": "opt-in", "owner": "prefill", "note": "[reviewed] Listed among opt-ins checked as off unless set. [gh-sweep-1031/INT-TRIAL2.md:95]", @@ -25315,7 +25385,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 783, + "line": 797, "backend": "cuda-hip", "fn": "getenv" }, @@ -25354,7 +25424,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1942, + "line": 2007, "backend": "cuda-hip", "fn": "getenv" } @@ -25616,7 +25686,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 817, + "line": 831, "backend": "cuda-hip", "fn": "getenv" }, @@ -25684,7 +25754,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2931, + "line": 3003, "backend": "cuda-hip", "fn": "getenv" }, @@ -25723,7 +25793,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 505, + "line": 519, "backend": "cuda-hip", "fn": "getenv" } @@ -25756,7 +25826,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2976, + "line": 3048, "backend": "cuda-hip", "fn": "getenv" } @@ -25789,7 +25859,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2979, + "line": 3051, "backend": "cuda-hip", "fn": "getenv" } @@ -25822,7 +25892,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2874, + "line": 2946, "backend": "cuda-hip", "fn": "getenv" } @@ -25856,7 +25926,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2915, + "line": 2987, "backend": "cuda-hip", "fn": "getenv" }, @@ -25896,7 +25966,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2949, + "line": 3021, "backend": "cuda-hip", "fn": "getenv" }, @@ -25936,7 +26006,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2945, + "line": 3017, "backend": "cuda-hip", "fn": "getenv" }, @@ -25975,7 +26045,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2972, + "line": 3044, "backend": "cuda-hip", "fn": "getenv" } @@ -26008,7 +26078,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2900, + "line": 2972, "backend": "cuda-hip", "fn": "getenv" } @@ -26146,7 +26216,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 385, + "line": 394, "backend": "cuda-hip", "fn": "getenv" } @@ -26165,8 +26235,8 @@ "first_commit": "37f0d8c688", "first_date": "2026-11-12", "since": null, - "last_commit": "75d91db5e2", - "last_date": "2026-11-12", + "last_commit": "ce414cb9e9", + "last_date": "2026-11-13", "status": "rollback", "owner": "prefill", "note": "[reviewed] The staged walk's fused group entry for a layer that has no MMQ tile but that the fused kernels cover (UD-Q4_K_XL on gfx1151 without STRATA_MMQ_KQ; every layer of a build without llama.cpp's MMQ): a prompt chunk below the long-prompt floor runs its routed experts on the fused kernels, streaming only the routed ones, instead of the dequantize + FP16 GEMM path. Unset: in a build without llama.cpp's MMQ on for every layer the fused kernels cover, on every card class (the build without MMQ takes the path the build with MMQ takes wherever that path does not need MMQ; the layers the fused kernels do not cover take the int8 kernels, then the FP16 path); in a build with MMQ on for Windows gfx1151 with a layer set that has no MMQ tile and the fused kernels on every layer, off elsewhere. =1 asks for it on any card (research), =0 turns it off (the long-prompt path from 64 tokens on the Windows gfx1151 class). src/prefill/prefill.cpp staged_fo_on, include/strata/prefill/staged_fo_rule.hpp.", @@ -26182,7 +26252,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4366, + "line": 4442, "backend": "cuda-hip", "fn": "getenv" }, @@ -26243,7 +26313,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 755, + "line": 769, "backend": "cuda-hip", "fn": "getenv" }, @@ -26378,7 +26448,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 1718, + "line": 1754, "backend": "cuda-hip", "fn": "getenv" } @@ -26415,7 +26485,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 7039, + "line": 7196, "backend": "cuda-hip", "fn": "getenv" } @@ -26763,7 +26833,7 @@ }, { "file": "src/program/generate.cpp", - "line": 18183, + "line": 18288, "backend": "cuda-hip", "fn": "getenv" } @@ -26800,7 +26870,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18209, + "line": 18314, "backend": "cuda-hip", "fn": "getenv" } @@ -26868,7 +26938,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18229, + "line": 18334, "backend": "cuda-hip", "fn": "getenv" } @@ -26901,7 +26971,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18447, + "line": 18552, "backend": "cuda-hip", "fn": "getenv" } @@ -26936,7 +27006,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18451, + "line": 18556, "backend": "cuda-hip", "fn": "getenv" } @@ -27016,7 +27086,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18443, + "line": 18548, "backend": "cuda-hip", "fn": "getenv" } @@ -27086,7 +27156,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19223, + "line": 19328, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27243,7 +27313,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19052, + "line": 19157, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27328,7 +27398,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17500, + "line": 17605, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27368,7 +27438,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18979, + "line": 19084, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27408,7 +27478,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19172, + "line": 19277, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27448,7 +27518,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19219, + "line": 19324, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27527,7 +27597,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19379, + "line": 19484, "backend": "cuda-hip", "fn": "pipe_dbg_env" } @@ -27561,7 +27631,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17503, + "line": 17608, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27601,7 +27671,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17496, + "line": 17601, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27641,7 +27711,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19036, + "line": 19141, "backend": "cuda-hip", "fn": "pipe_dbg_env" }, @@ -27686,7 +27756,7 @@ }, { "file": "src/program/generate.cpp", - "line": 15770, + "line": 15863, "backend": "cuda-hip", "fn": "getenv" } @@ -27883,7 +27953,7 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 83, + "line": 91, "backend": "cuda-hip", "fn": "getenv" }, @@ -27988,7 +28058,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 245, + "line": 254, "backend": "cuda-hip", "fn": "getenv" } @@ -28023,7 +28093,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 251, + "line": 260, "backend": "cuda-hip", "fn": "getenv" } @@ -28451,7 +28521,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 671, + "line": 685, "backend": "cuda-hip", "fn": "getenv" }, @@ -28533,7 +28603,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4171, + "line": 4247, "backend": "cuda-hip", "fn": "getenv" } @@ -28568,7 +28638,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4175, + "line": 4251, "backend": "cuda-hip", "fn": "getenv" } @@ -28603,7 +28673,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 486, + "line": 500, "backend": "cuda-hip", "fn": "getenv" }, @@ -28656,7 +28726,7 @@ }, { "file": "src/program/generate.cpp", - "line": 17921, + "line": 18026, "backend": "cuda-hip", "fn": "getenv" } @@ -28689,13 +28759,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 514, + "line": 528, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 517, + "line": 531, "backend": "cuda-hip", "fn": "getenv" } @@ -28714,8 +28784,8 @@ "first_commit": "92bce20e4b", "first_date": "2026-10-07", "since": "v0.1.41", - "last_commit": "2b9f05093d", - "last_date": "2026-11-06", + "last_commit": "bb0476d0aa", + "last_date": "2026-11-13", "status": "opt-in", "owner": "prefill", "note": "[reviewed] Documented CPU share extension, off by default. [release-v0.1.41.md:66]", @@ -28731,13 +28801,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6769, + "line": 6990, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8014, + "line": 8235, "backend": "cuda-hip", "fn": "getenv" }, @@ -28760,8 +28830,8 @@ "first_commit": "7cf709e5b1", "first_date": "2026-09-28", "since": "v0.1.40.1", - "last_commit": "ffe40c1695", - "last_date": "2026-10-26", + "last_commit": "bde9faeb9c", + "last_date": "2026-11-12", "status": "research", "owner": "prefill", "note": "[auto] diagnostic / trace / measurement switch by name or by code, not documented for users", @@ -28777,13 +28847,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6782, + "line": 7003, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 7123, + "line": 7344, "backend": "cuda-hip", "fn": "getenv" }, @@ -28901,13 +28971,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 293, + "line": 302, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6038, + "line": 5689, + "backend": "cuda-hip", + "fn": "getenv" + }, + { + "file": "src/prefill/prefill.cpp", + "line": 6218, "backend": "cuda-hip", "fn": "getenv" }, @@ -28932,8 +29008,8 @@ "first_commit": "e8de49ebc1", "first_date": "2026-10-02", "since": "v0.1.40.1", - "last_commit": "3feffd5970", - "last_date": "2026-11-11", + "last_commit": "3a4763217c", + "last_date": "2026-11-12", "status": "default", "owner": "prefill", "note": "[reviewed] Grouped gather is default; =0 turns it off with no gain measured. [docs/DETAILS.md:1117]", @@ -28949,13 +29025,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2725, + "line": 2797, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 18190, + "line": 18295, "backend": "cuda-hip", "fn": "env_on" }, @@ -29034,7 +29110,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2737, + "line": 2809, "backend": "cuda-hip", "fn": "getenv" }, @@ -29113,7 +29189,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4167, + "line": 4243, "backend": "cuda-hip", "fn": "getenv" }, @@ -29154,7 +29230,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7003, + "line": 7224, "backend": "cuda-hip", "fn": "getenv" }, @@ -29264,7 +29340,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7014, + "line": 7235, "backend": "cuda-hip", "fn": "getenv" } @@ -29297,7 +29373,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7009, + "line": 7230, "backend": "cuda-hip", "fn": "getenv" } @@ -29330,7 +29406,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7035, + "line": 7256, "backend": "cuda-hip", "fn": "getenv" } @@ -29363,7 +29439,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7024, + "line": 7245, "backend": "cuda-hip", "fn": "getenv" } @@ -29396,7 +29472,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 7019, + "line": 7240, "backend": "cuda-hip", "fn": "getenv" } @@ -29463,19 +29539,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 345, + "line": 354, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 1773, + "line": 1809, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6192, + "line": 6396, "backend": "cuda-hip", "fn": "getenv" }, @@ -29523,8 +29599,8 @@ "first_commit": "7cf709e5b1", "first_date": "2026-09-28", "since": "v0.1.40.1", - "last_commit": "6239e233a8", - "last_date": "2026-11-12", + "last_commit": "7f8c92f079", + "last_date": "2026-11-13", "status": "opt-in", "owner": "prefill", "note": "[auto] documented for users (docs/AMD_HIP.md:394), 15 more", @@ -29596,7 +29672,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3112, + "line": 3184, "backend": "cuda-hip", "fn": "getenv" } @@ -29665,7 +29741,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 622, + "line": 636, "backend": "cuda-hip", "fn": "getenv" }, @@ -29708,7 +29784,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4186, + "line": 4262, "backend": "cuda-hip", "fn": "getenv" } @@ -29743,7 +29819,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4187, + "line": 4263, "backend": "cuda-hip", "fn": "getenv" } @@ -29778,7 +29854,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 301, + "line": 310, "backend": "cuda-hip", "fn": "getenv" } @@ -29847,7 +29923,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 461, + "line": 475, "backend": "cuda-hip", "fn": "getenv" }, @@ -29959,13 +30035,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3434, + "line": 3510, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 3475, + "line": 3551, "backend": "cuda-hip", "fn": "getenv" }, @@ -30014,19 +30090,19 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2011, + "line": 2078, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 2025, + "line": 2092, "backend": "hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 2190, + "line": 2257, "backend": "cuda-hip", "fn": "getenv" } @@ -30207,13 +30283,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4925, + "line": 5001, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8286, + "line": 8507, "backend": "cuda-hip", "fn": "getenv" }, @@ -31932,7 +32008,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4897, + "line": 4973, "backend": "cuda-hip", "fn": "getenv" }, @@ -31972,13 +32048,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4898, + "line": 4974, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 4899, + "line": 4975, "backend": "cuda-hip", "fn": "getenv" }, @@ -32023,13 +32099,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4900, + "line": 4976, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 4900, + "line": 4976, "backend": "cuda-hip", "fn": "getenv" } @@ -32062,7 +32138,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4909, + "line": 4985, "backend": "cuda-hip", "fn": "getenv" } @@ -32153,7 +32229,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 801, + "line": 815, "backend": "cuda-hip", "fn": "getenv" } @@ -32186,7 +32262,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 805, + "line": 819, "backend": "cuda-hip", "fn": "getenv" } @@ -32519,7 +32595,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 19811, + "line": 19946, "backend": "cuda-hip", "fn": "getenv" } @@ -32908,7 +32984,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17710, + "line": 17815, "backend": "cuda-hip", "fn": "getenv" } @@ -32945,7 +33021,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17751, + "line": 17856, "backend": "cuda-hip", "fn": "getenv" }, @@ -33223,7 +33299,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 612, + "line": 626, "backend": "cuda-hip", "fn": "getenv" }, @@ -33807,31 +33883,31 @@ }, { "file": "src/program/generate.cpp", - "line": 13352, + "line": 13365, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14598, + "line": 14611, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14598, + "line": 14611, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14599, + "line": 14612, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14600, + "line": 14613, "backend": "cuda-hip", "fn": "getenv" } @@ -34432,13 +34508,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4763, + "line": 4839, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8274, + "line": 8495, "backend": "cuda-hip", "fn": "getenv" }, @@ -34547,13 +34623,13 @@ }, { "file": "src/prefill/prefill.cpp", - "line": 8458, + "line": 8679, "backend": "metal", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 8500, + "line": 8721, "backend": "cuda-hip", "fn": "getenv" }, @@ -34773,7 +34849,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 4827, + "line": 4903, "backend": "cuda-hip", "fn": "getenv" }, @@ -34812,7 +34888,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18872, + "line": 18977, "backend": "cuda-hip", "fn": "getenv" } @@ -34845,7 +34921,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18875, + "line": 18980, "backend": "cuda-hip", "fn": "getenv" } @@ -35080,19 +35156,19 @@ }, { "file": "serve/server.py", - "line": 4458, + "line": 4468, "value": "1" }, { "file": "serve/server.py", - "line": 4466, + "line": 4476, "value": "1" } ], "launch_reads": [ { "file": "serve/server.py", - "line": 4461 + "line": 4471 } ], "doc_mentions": [ @@ -35320,7 +35396,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14991, + "line": 15084, "backend": "cuda-hip", "fn": "getenv" } @@ -35412,7 +35488,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6196, + "line": 6198, "backend": "cuda-hip", "fn": "getenv" } @@ -35449,7 +35525,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6189, + "line": 6191, "backend": "cuda-hip", "fn": "getenv" }, @@ -35490,7 +35566,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6194, + "line": 6196, "backend": "cuda-hip", "fn": "getenv" }, @@ -35539,7 +35615,7 @@ }, { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6186, + "line": 6188, "backend": "cuda-hip", "fn": "getenv" }, @@ -35676,7 +35752,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 17284, + "line": 17389, "backend": "cuda-hip", "fn": "getenv" }, @@ -35718,13 +35794,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13218, + "line": 13231, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 17257, + "line": 17362, "backend": "cuda-hip", "fn": "getenv" }, @@ -35882,13 +35958,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14693, + "line": 14743, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21594, + "line": 21778, "backend": "cuda-hip", "fn": "getenv" } @@ -35932,7 +36008,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21642, + "line": 21826, "backend": "cuda-hip", "fn": "getenv" } @@ -36002,7 +36078,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20787, + "line": 20971, "backend": "cuda-hip", "fn": "getenv" } @@ -36281,13 +36357,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18819, + "line": 18924, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21597, + "line": 21781, "backend": "cuda-hip", "fn": "getenv" } @@ -36320,7 +36396,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18820, + "line": 18925, "backend": "cuda-hip", "fn": "getenv" } @@ -36353,7 +36429,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21582, + "line": 21766, "backend": "cuda-hip", "fn": "getenv" } @@ -36386,7 +36462,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21684, + "line": 21868, "backend": "cuda-hip", "fn": "getenv" } @@ -36803,13 +36879,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13182, + "line": 13195, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 18191, + "line": 18296, "backend": "cuda-hip", "fn": "env_on" } @@ -37208,7 +37284,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20758, + "line": 20942, "backend": "cuda-hip", "fn": "getenv" }, @@ -37432,7 +37508,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 22374, + "line": 22558, "backend": "hip", "fn": "getenv" } @@ -37467,7 +37543,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2181, + "line": 2248, "backend": "cuda-hip", "fn": "getenv" } @@ -37501,13 +37577,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 935, + "line": 949, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 2177, + "line": 2244, "backend": "cuda-hip", "fn": "getenv" }, @@ -37554,7 +37630,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 321, + "line": 330, "backend": "cuda-hip", "fn": "getenv" } @@ -37590,7 +37666,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2169, + "line": 2236, "backend": "cuda-hip", "fn": "getenv" } @@ -37626,7 +37702,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2157, + "line": 2224, "backend": "cuda-hip", "fn": "getenv" }, @@ -37874,7 +37950,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 20345, + "line": 20525, "backend": "cuda-hip", "fn": "getenv" }, @@ -37949,13 +38025,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 6966, + "line": 7187, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 20383, + "line": 20563, "backend": "cuda-hip", "fn": "getenv" }, @@ -38000,7 +38076,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 404, + "line": 418, "backend": "cuda-hip", "fn": "getenv" } @@ -38017,7 +38093,7 @@ "first_commit": "e84392acc0", "first_date": "2026-11-13", "since": null, - "last_commit": "9e59a89cc0", + "last_commit": "216af487d7", "last_date": "2026-11-13", "status": "rollback", "owner": "prefill", @@ -38141,7 +38217,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 13364, + "line": 13377, "backend": "cuda-hip", "fn": "getenv" } @@ -38242,7 +38318,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18316, + "line": 18421, "backend": "cuda-hip", "fn": "getenv" } @@ -38362,7 +38438,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 18233, + "line": 18338, "backend": "cuda-hip", "fn": "getenv" } @@ -38462,7 +38538,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 312, + "line": 321, "backend": "cuda-hip", "fn": "getenv" }, @@ -39223,7 +39299,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3492, + "line": 3494, "backend": "cuda-hip", "fn": "getenv" } @@ -39256,13 +39332,13 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3453, + "line": 3455, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3481, + "line": 3483, "backend": "cuda-hip", "fn": "getenv" } @@ -39299,7 +39375,7 @@ "reads": [ { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 3483, + "line": 3485, "backend": "cuda-hip", "fn": "getenv" } @@ -39336,13 +39412,13 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 3804, + "line": 3880, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/prefill/prefill.cpp", - "line": 6706, + "line": 6918, "backend": "cuda-hip", "fn": "getenv" }, @@ -39366,19 +39442,19 @@ }, { "file": "src/program/generate.cpp", - "line": 12999, + "line": 13011, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 14437, + "line": 14450, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 20930, + "line": 21114, "backend": "cuda-hip", "fn": "getenv" }, @@ -39434,13 +39510,13 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 21439, + "line": 21623, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/program/generate.cpp", - "line": 21476, + "line": 21660, "backend": "cuda-hip", "fn": "getenv" }, @@ -39504,13 +39580,13 @@ }, { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6296, + "line": 6453, "backend": "cuda-hip", "fn": "getenv" }, { "file": "src/kernels/cuda/iq_kernels.cu", - "line": 6335, + "line": 6492, "backend": "cuda-hip", "fn": "getenv" }, @@ -41030,7 +41106,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14615, + "line": 14628, "backend": "cuda-hip", "fn": "getenv" } @@ -41064,7 +41140,7 @@ "reads": [ { "file": "src/program/generate.cpp", - "line": 14611, + "line": 14624, "backend": "cuda-hip", "fn": "getenv" }, @@ -41172,6 +41248,39 @@ "retire_after": "", "retired_in": "" }, + { + "name": "STRATA_WINDOW_WARM", + "backends": [ + "cuda-hip" + ], + "reads": [ + { + "file": "src/program/generate.cpp", + "line": 14690, + "backend": "cuda-hip", + "fn": "getenv" + } + ], + "parse": "flag", + "default_state": null, + "code_default": null, + "engine_sets": [], + "engine_defaults": [], + "launch_files": [], + "launch_sets": [], + "launch_reads": [], + "doc_mentions": [], + "first_commit": null, + "first_date": null, + "since": null, + "last_commit": null, + "last_date": null, + "status": "", + "owner": "", + "note": "", + "retire_after": "", + "retired_in": "" + }, { "name": "STRATA_WMMA_BF16", "backends": [ @@ -41307,7 +41416,7 @@ "reads": [ { "file": "src/prefill/prefill.cpp", - "line": 2288, + "line": 2355, "backend": "cuda-hip", "fn": "getenv" } diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index d0e6353746..0178d1bddd 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -51,7 +51,7 @@ Off unless you set them. The last column says where each one is described. | `STRATA_DMA_BATCH` | number | NVIDIA and AMD | [BATCHED_DMA.md](BATCHED_DMA.md), [DETAILS.md](DETAILS.md) | | `STRATA_DOWN_WS` | on / off | NVIDIA and AMD | [OLDER_GPUS.md](OLDER_GPUS.md), [release-notes-0.2.7.md](release-notes-0.2.7.md) | | `STRATA_DUMP_FIRST_LOGITS` | on / off | NVIDIA and AMD, Intel Arc | [DGX_SPARK_LINUX.md](DGX_SPARK_LINUX.md) | -| `STRATA_DUMP_MOE_INPUT` | number | NVIDIA and AMD | [NVFP4.md](NVFP4.md) | +| `STRATA_DUMP_MOE_INPUT` | text | NVIDIA and AMD | [NVFP4.md](NVFP4.md) | | `STRATA_EMBED_VRAM` | on / off | NVIDIA and AMD | [DETAILS.md](DETAILS.md) | | `STRATA_EXCHANGE_ROTATE` | on / off | NVIDIA and AMD, Intel Arc, CPU | [DETAILS.md](DETAILS.md), [EXCHANGE_ROTATION.md](EXCHANGE_ROTATION.md) | | `STRATA_EXPDEC_MINB` | number | NVIDIA and AMD | [EXPERTDEC.md](EXPERTDEC.md) | @@ -303,7 +303,7 @@ version made it the default. | `STRATA_BATCH_MTP_SERIAL` | on / off | NVIDIA and AMD | v0.1.43.1 | [BATCHING.md](BATCHING.md) | | `STRATA_DEFAULTS` | text | NVIDIA and AMD | v0.2.7 | [BATCHING.md](BATCHING.md), [DETAILS.md](DETAILS.md), [DGX_SPARK_LINUX.md](DGX_SPARK_LINUX.md) | | `STRATA_DEQUANT_WIDE` | number | NVIDIA and AMD | v0.1.44 | [DETAILS.md](DETAILS.md), [OLDER_GPUS.md](OLDER_GPUS.md), [release-notes-0.2.7.md](release-notes-0.2.7.md) | -| `STRATA_EXPERT_I8` | on / off | NVIDIA and AMD | - | - | +| `STRATA_EXPERT_I8` | text | NVIDIA and AMD | - | - | | `STRATA_FILE_TIER_IDLE` | number | NVIDIA and AMD | v0.2.12 | [DETAILS.md](DETAILS.md) | | `STRATA_GFX1151_CHUNK` | text | AMD | v0.2.3 | [release-notes-0.2.3.md](release-notes-0.2.3.md), [STRIX_HALO.md](STRIX_HALO.md), [STRIX_HALO_WINDOWS.md](STRIX_HALO_WINDOWS.md) | | `STRATA_GFX1151_DEFAULTS` | on / off | NVIDIA and AMD | v0.1.40.1 | [STRIX_HALO.md](STRIX_HALO.md), [STRIX_HALO_WINDOWS.md](STRIX_HALO_WINDOWS.md) | diff --git a/include/strata/spec/draft_policy.hpp b/include/strata/spec/draft_policy.hpp index 29e37d7e6c..882f4fa5cd 100644 --- a/include/strata/spec/draft_policy.hpp +++ b/include/strata/spec/draft_policy.hpp @@ -35,25 +35,54 @@ namespace strata::spec { /// The round times of a learning stretch, by context bucket and window size, for a fixed cost table. Keeps up to kKeep /// samples per (bucket, size) in arrival order. +/// +/// Which rounds count (measured, phaseA-tests/par/RESULTS-DRAFT-COSTS.md): on an Apple M5 Max a GPU that has been busy for more than about 7 s runs +/// slower, and unevenly by window size (after 75 s of continuous load 5 rows cost 27 % more and 1 row 14 % more, so 5 rows against 3 rows read 1.38 +/// instead of 1.30), while a request that arrives after a pause of half a second runs in the fast state at once; the Radeon 780M shows no such +/// difference (round times within 1 % at any load time). The table is what requests after a pause cost. add() takes the busy age of the round +/// (`busy_age_s`: the seconds since the last pause of kIdleS or more) and keeps the rounds of the first kFreshS seconds ("fresh") apart from the later +/// ones ("late"); the table uses the fresh rounds only when the late ones differ from them by more than kStateTol in some size that has min_n of +/// both (a state effect), and all rounds otherwise (the engine does not need the split on a machine that has no such difference, and more rounds +/// measure the rare sizes better). class CostLearner { public: static constexpr int kMaxT = 16; static constexpr int kCtxBuckets = 3; static constexpr int kKeep = 4096; - void add(int bucket, int t, double ms); + static constexpr double kFreshS = 6.0; ///< a round is fresh when the engine has been busy for at most this long (M5 Max: flat to 7.5 s, +3 % at 7.5-10 s) + static constexpr double kIdleS = 0.5; ///< a pause of this length (no request running) starts a new busy run; the caller measures it (M5 Max: 0.5 s restores the fast state) + static constexpr double kStateTol = 0.02; ///< late against fresh round times beyond this in some size = a state effect + static constexpr int kFallbackFactor = 3; ///< with a state effect, a stretch with this many times min_rounds timed rounds of any age ends with the fresh ones ... + static constexpr int kFallbackShare = 5; ///< ... when they are at least 1 / kFallbackShare of min_rounds + /// `busy_age_s` < 0: unknown (counts as fresh). + void add(int bucket, int t, double ms, double busy_age_s = -1.0); void reset(); - int64_t rounds() const { return rounds_; } - int samples(int bucket, int t) const; - /// The table of `bucket` for windows 1..n (n = the largest size seen in that bucket; empty when the bucket has none): - /// the trimmed mean (the lowest and highest kTrim share dropped) of each size with at least `min_n` samples; the other - /// sizes are filled between measured neighbours (linear in the size) or, outside them, by the policy's prior shape. - std::vector table(int bucket, int min_n) const; + int64_t rounds() const { return rounds_; } ///< the fresh rounds + int64_t late_rounds() const { return late_; } ///< the rounds after the engine had been busy for more than kFreshS + int samples(int bucket, int t) const; ///< fresh samples of a size + /// A state effect in `bucket`: some size has at least `min_n` fresh and `min_n` late samples and their trimmed means differ by more than kStateTol. + bool state_effect(int bucket, int min_n) const; + /// Some size of `bucket` has at least `min_n` fresh and `min_n` late samples: state_effect() says something (a fresh-only machine is told apart from one without effect). + bool state_known(int bucket, int min_n) const; + /// The samples of size `t` that table() would use now: the fresh ones when there is a state effect, fresh + late otherwise. + int usable(int bucket, int t, int min_n) const; + /// The table of `bucket` for windows 1..n (n = the largest size seen in that bucket, or `upto` when that is larger; empty when the bucket has none): + /// the trimmed mean (the lowest and highest kTrim share dropped) of each size with at least `min_n` samples; a size with kWeakN to min_n - 1 + /// samples counts with its median when that is within [fill, kWeakMax x fill] (a rough measurement, never below the trend); a size in between two measured ones is linear in the size; a size above the + /// measured ones continues the straight line through them with the steeper of the last segment's slope and the slope over all measured sizes + /// (costs grow at least that fast: a fill never falls below the measured trend; one measured size: the policy's prior shape), below them the + /// prior shape; the table never falls from one size to the next. + std::vector table(int bucket, int min_n, int upto = 0) const; + static constexpr int kWeakN = 5; ///< samples from which a size below min_n counts by its median ... + static constexpr double kWeakMax = 1.5; ///< ... when that median is not below the fill and at most this many times it (a stalled handful is not a measurement) struct Verdict { bool ready = false; ///< enough rounds, and every bucket with data has a size with min_n samples bool disturbed = false; ///< the stretch looks disturbed: do not keep a table from it (start learning again) std::string why; ///< what was seen (for the log) }; - /// Ready after `min_rounds` timed rounds. Disturbed (each check per size with at least 2 x min_n samples): + /// Ready after `min_rounds` usable rounds (fresh and late ones when no bucket has a state effect, the fresh ones when one has), or, with a state + /// effect, after kFallbackFactor x `min_rounds` rounds of any age when at least `min_rounds` / kFallbackShare of them are fresh (one long burst + /// keeps only its first kFreshS seconds). Disturbed (each check per size with at least 2 x min_n samples, on the samples the table uses): /// (1) its trimmed means of the first and the second half of its samples differ by more than kDriftMax; /// (2) more than kSpikeMax of its samples are above twice its median; /// (3) a measured size is cheaper than a measured smaller one by more than kOrderSlack (a round of more rows cannot be cheaper). @@ -64,23 +93,45 @@ public: static constexpr double kOrderSlack = 0.10; private: - std::array, kMaxT + 1>, kCtxBuckets> s_{}; + /// The samples of every size of `bucket` that the table uses: the fresh ones, or fresh + late. + std::array, kMaxT + 1> sets(int bucket, bool pooled) const; + std::array, kMaxT + 1>, kCtxBuckets> s_{}; // fresh + std::array, kMaxT + 1>, kCtxBuckets> late_s_{}; // late int64_t rounds_ = 0; + int64_t late_ = 0; }; /// The per-machine table file of --draft-costs: text, one table per context bucket, valid only for the `key` it was learned under /// (card, driver, engine, model, drafter and the settings that move a round's cost; the engine builds it). -/// strata-draft-costs 1 +/// strata-draft-costs 2 (1: tables learned from every round of a stretch; they are learned again) /// key /// bucket <0..2> ,,... /// share <0..1> (optional: the CPU prompt share learned on this machine, src/prefill/prefill.cpp) /// pcie <0..1> (optional: the decode PCIe share PcieAuto settled on, src/program/generate.cpp) /// end +/// The real rounds of one size seen since the table was learned: n rounds, their sum in ms (each clamped to [kCalibLo, kCalibHi] x the learned cost), and the +/// rounds themselves (up to kVals): the size's real price is their MEDIAN (a cold or stalled round, a first use, another process, moves a mean but not a median). +/// A file line from before the values ("cal b t n sum" without them) has nv = 0: its price is the mean as before. +/// cal [ ... ] +struct CalAcc { + static constexpr int kVals = 16; + int n = 0; + double sum = 0.0; + int nv = 0; ///< how many of vals hold a round (== n when every round is kept) + std::array vals{}; +}; struct CostFile { std::string key; std::array, CostLearner::kCtxBuckets> tables{}; double cpu_share = -1.0; ///< < 0: none stored double pcie_frac = -1.0; ///< the decode PCIe share PcieAuto settled on; < 0: none stored (a file from before it: refined, then written) + /// Calibration against real requests (see DraftPolicy::start_calibration); a file without these lines has none done. + int reqs = 0; ///< requests that ran while the table was held back (DraftPolicy::kCalibReqs ends the holding) + bool fresh = false; ///< a file with no table yet: the real rounds of the sizes are being collected while live costs decide (DraftPolicy::start_passive); no "bucket" lines + bool state_effect = false; ///< the learning stretch showed a load-time effect: only fresh real rounds are counted + std::array real{}; ///< bit t-1: the cost of size t is a median of real rounds, no longer the learned one + std::array, CostLearner::kCtxBuckets> cal{}; ///< real rounds collected so far for the sizes not yet replaced + std::array, CostLearner::kCtxBuckets> real_cost{}; ///< the cost of a size marked real (the table lines keep the learned costs) }; /// false (with `why` for the log) when the file is missing, unreadable, malformed or truncated, or was learned under another key: the caller /// then learns a new table. Never throws. @@ -99,11 +150,16 @@ public: struct Pick { bool lookup = false; int t = 1; // window size (1 + drafts) + int pad = 0; // a learning stretch's window longer than the proposal: this many rows past it are filler (the caller fills them) }; /// `t_mtp`: the MTP's window; `lookup_k`: the lookup proposal's length (0 = none); `match`: its match length. - Pick choose(int t_mtp, int lookup_k, int match) const; + /// pad_cap > 0 (learning, a deterministic proposal): a window may be longer than the proposal, up to pad_cap drafts, its extra rows filler + /// that the verifier will most likely reject; only a learning stretch asks for one (see explore below). + Pick choose(int t_mtp, int lookup_k, int match, int pad_cap = 0) const; /// After the round: the window it used, the drafts accepted, and the round's time (verify + commit + draft). void observe(bool lookup, int t, int accepted, int match, double round_ms); + /// The round of a window run for its size's sake (Pick::pad > 0): its time goes to the learner and the cost of that size, its outcome to no statistic. + void observe_forced(int t, double round_ms); /// Gated proposals, inside one generation: a round's committed outcome only, never its time. `t` is the /// lookup window chosen before the draws, or the configured MTP window; both are fixed by the history. A /// lookup window counts as a probe of its size, so a size whose cost is still guessed is tried kProbes times, @@ -150,6 +206,65 @@ public: /// Learning a fixed table: every timed round also goes to learner() (raw round time, in its context bucket). Off by default. void set_learning(bool on) { learning_ = on; } bool learning() const { return learning_; } + /// Measuring the sizes the policy can pick (learning only): after kExploreAfter timed rounds, a lookup proposal (padded with filler rows up to + /// pad_cap when the caller allows it, else long enough as it is) takes the window of a size that has fewer than kExploreN samples in the + /// current context bucket instead (the smallest such size), at most kExplorePerSize times per size and kExploreBudget times in a stretch. The tokens of a learning stretch were never repeatable + /// (the windows follow the live costs); a window's size can change the batch the verifier runs, and with it the tokens. A size that + /// no proposal ever reaches keeps its filled-in cost (CostLearner::table). + static constexpr int kExploreAfter = 100; + static constexpr int kExploreN = 30; + static constexpr int kExplorePerSize = 40; + static constexpr int kExploreBudget = 300; + int forced_rounds() const { return forced_total_; } + /// The MTP / drafter window of a round that the caller has just decided (`t` rows, at most `cap` rows possible): the size to run instead when + /// a learning stretch wants to time one (rows past the drafts are the caller's filler), else 0. Same limits as for a lookup window. Forced + /// rounds happen only while they count: in the first kFreshS seconds of a busy run, or when the stretch has shown no state effect. + int explore_window(int t, int cap) const; + /// A round with no lookup proposal: the size of a lookup-type window (2..cap rows, every row after the first filler) a learning stretch wants to time, else 0. + int explore_lookup(int cap) const; + /// Start the learning stretch again: the learner's samples and the forced-round counts. + void reset_learning(); + /// The largest allowed window size (the table is written up to it). + int top_size() const { return fit(max_t_); } + /// How long the engine has been busy (seconds since its last pause of CostLearner::kIdleS), as the caller measures it, for the round + /// observe() is about to be given; < 0 (the default): unknown. Only the learner reads it. + void set_busy_age(double s) { busy_age_ = s; } + /// Calibration of a fixed table against real requests. The learned costs come from a learning stretch (forced windows with filler rows, a burst of + /// prose), and a real round of the same size can cost a little more (measured on an M5 Max: 2 % on 2, 3 and 5 rows) - enough to flip a close choice + /// between a 4 and a 5 row window (JSON decode 6 % slower than live costs). After a table is fixed, every real round (never a forced one) of a size + /// whose cost is still the learned one is kept (clamped to [kCalibLo, kCalibHi] x the learned cost; only the first kFreshS seconds of a busy run when + /// the machine has a load-time effect), across starts through the table file (CostFile::cal). At kCalibN rounds the size's cost becomes their mean + /// (a result outside [kCalibOkLo, kCalibOkHi] x the learned cost means a disturbed stretch: the rounds are dropped and collected again) and the size + /// is marked real (CostFile::real) for good: no later change, so the windows of a repeated start are the same. A size that real requests never reach + /// keeps its learned cost. real, cal and real_cost come from the file (CostFile). + /// Until every size of the table is real the table is not used: the policy decides with live costs, exactly as without a table (a half-calibrated + /// table priced a JSON request 5 % slower than live costs), and only collects the real rounds; once the last size is calibrated the table + /// (the real costs) decides for good. A size that real requests do not reach (the long lookup sizes of a big GPU) would hold it back for good, so after + /// kCalibReqs requests the table is used anyway: such a size is priced at its learned cost x the mean (real / learned) of the real + /// sizes of 2 or more rows (a size 1 at its learned cost) until it has its own kCalibN rounds. The count is kept in the file (CostFile::reqs). + static constexpr int kCalibN = 16; + static constexpr int kCalibReqs = 100; // requests that may run while the table is held back; then a size not reached keeps a scaled learned cost + static constexpr double kCalibLo = 0.85, kCalibHi = 1.30, kCalibOkLo = 0.86, kCalibOkHi = 1.29; + void start_calibration(bool state_effect, const std::array& real, + const std::array, kCtxBuckets>& cal, + const std::array, kCtxBuckets>& real_cost, int reqs = 0); + /// A machine without a table file builds one from the rounds its live-cost policy runs anyway, with no learning stretch and no forced window: from the + /// first request on the table is held back (live costs decide, exactly as without --draft-costs); only the first kFreshS seconds of a busy run are counted + /// (a machine without a load-time effect just gets fewer samples); a size is real at kCalibN own rounds (the file keeps the sums, so counts survive a + /// restart); when every size up to `n` is real, or after kCalibReqs requests, the table takes over: the real costs, and for a size never reached the live + /// cost at that moment (the policy's own prior when it never measured one); such a size keeps collecting like any size of a table that is in use. + /// cf: the file as read (or an empty one with only the key); n: the table length (top_size()). + void start_passive(const CostFile& cf, int n); + bool passive() const { return passive_; } + bool calibrating() const { return calib_on_; } + bool calib_dirty() const { return calib_dirty_; } + /// While a loaded table still has sizes that are not calibrated (calibrating()), the table is held back: the policy decides with live costs + /// exactly as without a table (fixed() is false), and the real rounds are collected meanwhile. Once the last size is calibrated (at a request's + /// end, calibrate()) the table takes over for good. table_held() is true in that stretch. + bool table_held() const { return held_table_; } + /// At a request's end: replaces the sizes that have kCalibN real rounds and puts the table, the real marks and the rounds collected so far into + /// cf (its other fields stay); report says which sizes changed (empty when none). True when cf should be written (something changed). + bool calibrate(CostFile& cf, std::string& report); CostLearner& learner() { return learner_; } const CostLearner& learner() const { return learner_; } @@ -197,6 +312,27 @@ private: bool robust_ = false; bool fixed_ = false; // set_fixed_costs: no round time changes a cost bool learning_ = false; // set_learning: round times also go to learner_ + double busy_age_ = -1.0; // set_busy_age + bool calib_on_ = false, calib_dirty_ = false, calib_fresh_only_ = false; + std::array fixed_n_{}; // the length of each bucket's fixed table + std::array real_{}; + std::array, kCtxBuckets> cal_{}; + std::array, kCtxBuckets> learned_{}, real_cost_{}; // the table as fixed (learned); the cost of each real size + int reqs_ = 0; // requests that ran while the table was held back (the file keeps it) + bool passive_ = false; // start_passive: no learned table until the take-over (learned_ is zero before it) + void take_over_passive(); // the learned cost of every size not real: the live cost now (a real one keeps its own); then use_table() + bool held_table_ = false; // a table is loaded but not used yet: live costs decide (see table_held()) + bool live_saved_ = false; + std::array, kCtxBuckets> live_cost_{}, live_n_{}; // the live costs as they were when the table was set + void calib_add(int bucket, int t, double ms, double age); + void apply_table(); + void hold_table(); // back to the live costs (fixed_ off) for the buckets that have a table + void use_table(); // all sizes calibrated: the table (real costs) decides, fixed_ on + int explore_size(int lookup_k, int pad_cap) const; // the size a learning stretch measures next, 0 = none (choose() counts it) + int explore_next(int reach, int skip) const; // the smallest size 2..reach (not `skip`) that still needs rounds; counts it; 0 = none + bool explore_ok() const; // a forced round counts now (fresh phase, or no state effect) + mutable int forced_total_ = 0; // windows taken for their size's sake, this stretch + mutable std::array forced_{}; // ... by size CostLearner learner_; double clamp_sample(int t, double ms) const; static constexpr int kPBuckets = 8; @@ -205,7 +341,7 @@ private: // Gated proposals (observe_committed / defer_cost / apply_costs); all zero or empty on any other path. std::array, kCtxBuckets> tried_{}; // lookup windows of that size run with no time yet std::array, kCtxBuckets> delayed_n_{}; // of cost_n_: times applied by apply_costs (not new probes) - struct HeldCost { int64_t end; int bucket; int t; double ms; }; + struct HeldCost { int64_t end; int bucket; int t; double ms; double age; }; std::vector held_; // defer_cost, oldest first }; diff --git a/serve/server.py b/serve/server.py index 79d4a1b87b..be8227e51b 100644 --- a/serve/server.py +++ b/serve/server.py @@ -4063,7 +4063,17 @@ def learned_profile_args(cfg: dict, args: list[str]) -> list[str]: return args -DRAFT_COSTS_DEFAULT = True # repeatable output: on by default (owner decision); "draft_costs": false in a config turns it off +DRAFT_COSTS_DEFAULT_PLATFORMS = ("darwin",) # Metal: the taken-over table measured above live costs there (M5 Max: Q2_0 code +2.6 %, chat +2.4 %, JSON +0.2 %; IQ3_S +0.2 / +0.6 / +0.7 %) + + +def draft_costs_default(platform: str | None = None) -> bool: + """Repeatable output (owner decision) is the default only where the table was measured at or above live costs: Metal. On CUDA (RTX PRO 5000, IQ3_S: code + -1.5 %, chat -1.5 %, JSON +1.9 % against live costs) and HIP the engine keeps live costs, as an engine started without --draft-costs does. `"draft_costs": true` + in a config turns the table on anywhere (tests and A/Bs), `"draft_costs": false` turns it off.""" + return (platform or sys.platform) in DRAFT_COSTS_DEFAULT_PLATFORMS + + +DRAFT_COSTS_DEFAULT = draft_costs_default() # "draft_costs": true / false in a config overrides it _engine_texts: dict = {} diff --git a/serve/test_server.py b/serve/test_server.py index 131d46de3a..1fe7879dab 100644 --- a/serve/test_server.py +++ b/serve/test_server.py @@ -2564,6 +2564,25 @@ class DraftCosts(unittest.TestCase): self.assertEqual(server.draft_costs_args({"model_name": "m"}, list(args)), args) self.assertEqual(server.draft_costs_args({"model_name": "m"}, list(args), str(self.tmp / "missing")), args) + def test_default_is_on_only_on_metal(self): + # the taken-over table measured above live costs on Metal and below them on CUDA (l620, 11-13): live costs stay the default there and on HIP + self.assertTrue(server.draft_costs_default("darwin")) + for platform in ("linux", "win32", "cygwin", "freebsd14", "android"): + self.assertFalse(server.draft_costs_default(platform), platform) + self.assertEqual(server.DRAFT_COSTS_DEFAULT, sys.platform == "darwin") + + def test_table_off_by_default_gives_no_flag_unless_the_config_asks(self): + args = ["--native", "x", "--spec", "6"] + new = self.tmp / "new-engine" + new.write_bytes(b"\x7fELF strata --spec --serve --draft-costs --draft-costs-key") + with mock.patch.object(server, "DRAFT_COSTS_DEFAULT", False): # CUDA / HIP class + self.assertEqual(server.draft_costs_args({"model_name": "m"}, list(args), str(new)), args) + self.assertIn("--draft-costs", server.draft_costs_args({"model_name": "m", "draft_costs": True}, list(args), str(new))) # the test switch + self.assertEqual(server.draft_costs_args({"model_name": "m", "draft_costs": False}, list(args), str(new)), args) + with mock.patch.object(server, "DRAFT_COSTS_DEFAULT", True): # Metal class + self.assertIn("--draft-costs", server.draft_costs_args({"model_name": "m"}, list(args), str(new))) + self.assertEqual(server.draft_costs_args({"model_name": "m", "draft_costs": False}, list(args), str(new)), args) + def test_on_gives_a_file_in_the_redirected_folder(self): args = ["--native", "x", "--spec", "6"] got = server.draft_costs_args({"model_name": "qwen3.8-flash-next-iq3_s", "draft_costs": True}, list(args)) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 52f809d2a7..8828407e50 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -14680,6 +14680,43 @@ int main(int argc, char** argv) { strata::core::pin_reserve_release_hard(); // the load is over: nothing else needs the headroom strata::core::kfd_settle::settle_before_ready(); // integrated gfx11 under Linux: until the kernel has stopped moving the registered arena (nothing elsewhere) strata::core::manifest::instance().write("ready"); // STRATA_MANIFEST (a no-op unless it is set) + // ---- window warm-up (lane DRAFT-COSTS): the first run of a window width builds its graph / pipeline (srv118 CUDA: a capture; Metal: the first execution), so a + // width that the policy first picks inside a long request pays it there (M5 Max, IQ3_S: +60 ms on the first five-row lookup round, in the timed code request in 5 of 8 launches + // with a table, because the release and the live costs happen to pay it in request 1). One dummy window per allowed width 1..S, once, before the first request is read; it + // changes nothing a request can see: the windows write K/V cells 0..T-1 and the recurrent state of the session, and session_zero() below zeroes the session exactly as a request + // that reuses nothing does (the engine's state after session_init); no checkpoint, conversation entry, RNG draw, policy sample or statistic is touched (the policy's observe_* + // calls live in the decode loop); the expert cache may page in what the dummy token routes to (speed only). STRATA_WINDOW_WARM=0: off (research switch). + { + static const bool warm_off = [] { const char* v = std::getenv("STRATA_WINDOW_WARM"); return v != nullptr && v[0] == '0'; }(); + if (!warm_off && o.spec >= 2 && n_stages == 1 && o.batch <= 0) { + const Clock::time_point w0 = Clock::now(); + std::vector wtok((size_t) o.spec, 1), wout((size_t) o.spec + 1, 0); + std::string werr, wlist; + bool wok = true; + for (int t = 1; t <= o.spec && wok; ++t) { + if (!((lookup_size_mask(o) >> t) & 1u)) continue; + bool no_vram = false; + if (!ver.prepare(t, no_vram, werr)) { if (no_vram) continue; wok = false; break; } // CUDA / HIP: the graph now (a size that finds no VRAM is left to the runtime rule); Metal: nothing to do + const Clock::time_point t0 = Clock::now(); + drive.d.layers = 0; + drive.d.experts = 0; + drive.d.failed = false; + wok = ver.run(t, wtok.data(), 0, win_pool_fn, win_pool_user, wout.data(), werr) && !drive.d.failed; + char wb[48]; + std::snprintf(wb, sizeof wb, "%s%d:%.0f", wlist.empty() ? "" : " ", t, + std::chrono::duration(Clock::now() - t0).count()); + wlist += wb; + } + strata::core::session_zero(ss, g, nullptr, main_cs); + cudaStreamSynchronize(main_stream); + drive.d.layers = 0; + drive.d.experts = 0; + drive.d.failed = false; + std::fprintf(stderr, "strata serve: window warm-up: ms per width %s, total %.0f ms%s%s\n", wlist.c_str(), + std::chrono::duration(Clock::now() - w0).count(), wok ? "" : "; a window failed: ", + wok ? "" : werr.c_str()); + } + } g_gpu_pause_idle.idle(gpu_pause_now()); // AMD on Linux: the gap before the first request starts here (the start-up's own pauses are not a "between") std::printf("READY %lld stop hold holdb\n", (long long) o.max_context); // "stop": this engine honours STOP; "hold": GEN hold=N:ID; "holdb": the --batch slots end at the hold too (BDONE hold) std::fflush(stdout); @@ -14721,31 +14758,74 @@ int main(int argc, char** argv) { constexpr int kDraftCostMinN = 20; // a window size needs this many rounds to be measured (fewer: filled in) std::string dc_key; bool dc_learning = false; + bool dc_calib = false; // a table is used and its sizes are being calibrated against real rounds (DraftPolicy::start_calibration) + // how long the engine has been busy: the learner keeps only the rounds of the first seconds of a busy run (CostLearner::kFreshS); a busy run + // starts at a request that begins CostLearner::kIdleS or more after the last one ended (the GPU runs slower and steeper after a long load) + Clock::time_point dc_busy_since = Clock::now(), dc_last_end = Clock::now(); + bool dc_seen_request = false; bool dc_pcie_pending = false; // a loaded table without a PCIe share: written into it once PcieAuto has settled strata::spec::CostFile dc_file; // that table, as loaded + bool dc_shares_due = false; // the table is held back (live costs): its stored CPU prompt share / PCIe share are fixed when it takes over + auto dc_apply_shares = [&](const strata::spec::CostFile& cf) { + if (cf.cpu_share >= 0.0) strata::prefill::Prefill::fix_cpu_share(cf.cpu_share); + if (dc_pcie_ok && cf.pcie_frac >= 0.0) fix_pcie_share(cf.pcie_frac); + }; if (!o.draft_costs.empty() && !policy.fixed()) { dc_key = draft_costs_key(argc, argv, o.draft_costs_key, spec_cost); strata::spec::CostFile cf; std::string why; - if (strata::spec::read_cost_file(o.draft_costs, dc_key, cf, why)) { + // a machine with no table (a new engine, driver, model or setting discards the file) builds one from the rounds of its normal requests, with live + // costs deciding meanwhile: no learning stretch. The old one-start stretch (forced filler windows, a burst of requests) runs only for the test + // harnesses that set STRATA_DRAFT_COSTS_LEARN=1; the server and the launcher never do. + const char* dc_lv = std::getenv("STRATA_DRAFT_COSTS_LEARN"); + const bool dc_force_learn = dc_lv != nullptr && dc_lv[0] == '1'; + const bool dc_read_ok = strata::spec::read_cost_file(o.draft_costs, dc_key, cf, why); + if (dc_read_ok && cf.fresh) { // a file of the passive stretch: the real rounds collected so far + dc_file = cf; + policy.start_passive(cf, policy.top_size()); + dc_calib = true; + std::fprintf(stderr, "strata serve: draft costs: this machine's table is being built from real requests (%s; %d requests so far): live costs " + "decide until every window size has %d own rounds or %d requests have run\n", + o.draft_costs.c_str(), cf.reqs, strata::spec::DraftPolicy::kCalibN, strata::spec::DraftPolicy::kCalibReqs); + } else if (!dc_read_ok && !dc_force_learn) { // no table yet + cf.key = dc_key; + cf.fresh = true; + dc_file = cf; + policy.start_passive(cf, policy.top_size()); + dc_calib = true; + std::fprintf(stderr, "strata serve: draft costs: no table for this machine yet (%s: %s): it is built from real requests, live costs decide " + "until every window size has %d own rounds or %d requests have run\n", + o.draft_costs.c_str(), why.c_str(), strata::spec::DraftPolicy::kCalibN, strata::spec::DraftPolicy::kCalibReqs); + } else if (dc_read_ok) { std::string sizes; for (int k = 0; k < strata::spec::CostLearner::kCtxBuckets; ++k) if (!cf.tables[(size_t) k].empty()) { policy.set_fixed_costs(cf.tables[(size_t) k].data(), (int) cf.tables[(size_t) k].size(), k); sizes += (sizes.empty() ? "" : ", ") + std::to_string(cf.tables[(size_t) k].size()); } - if (cf.cpu_share >= 0.0) strata::prefill::Prefill::fix_cpu_share(cf.cpu_share); + dc_file = cf; + policy.start_calibration(cf.state_effect, cf.real, cf.cal, cf.real_cost, cf.reqs); + dc_calib = policy.calibrating(); + if (policy.table_held()) dc_shares_due = true; // a held table leaves the shares live too: they are fixed when the table takes over + else dc_apply_shares(cf); std::string extra = cf.cpu_share >= 0.0 ? "; CPU prompt share " + std::to_string(cf.cpu_share).substr(0, 4) : ""; if (dc_pcie_ok && cf.pcie_frac >= 0.0) { // PcieAuto's settled share: fixed, no refinement in this run - fix_pcie_share(cf.pcie_frac); extra += "; PCIe share " + std::to_string(cf.pcie_frac).substr(0, 4); } else if (dc_pcie_ok) { // a file from before the stored PCIe share: refined as before, then written into the file dc_pcie_pending = true; - dc_file = cf; extra += "; PCIe share: refined in this run, then stored"; } - std::fprintf(stderr, "strata serve: draft costs: this machine's table is used (%s; window sizes %s%s): the same request " - "gives the same tokens on every start\n", o.draft_costs.c_str(), sizes.c_str(), extra.c_str()); + if (dc_calib && policy.table_held()) + std::fprintf(stderr, "strata serve: draft costs: this machine's table is loaded (%s; window sizes %s%s), not used yet: the " + "windows follow live costs until every size is calibrated against real requests (or 100 requests have run)\n", + o.draft_costs.c_str(), sizes.c_str(), extra.c_str()); + else if (dc_calib) + std::fprintf(stderr, "strata serve: draft costs: this machine's table is used (%s; window sizes %s%s); sizes real requests have not " + "reached yet keep collecting rounds and change the table once when they have their own\n", + o.draft_costs.c_str(), sizes.c_str(), extra.c_str()); + else + std::fprintf(stderr, "strata serve: draft costs: this machine's table is used (%s; window sizes %s%s): the same request " + "gives the same tokens on every start\n", o.draft_costs.c_str(), sizes.c_str(), extra.c_str()); } else { policy.set_learning(true); dc_learning = true; @@ -16446,7 +16526,14 @@ int main(int argc, char** argv) { continue; } const bool geni = line.rfind("GENI ", 0) == 0; - if (geni || line.rfind("GEN ", 0) == 0) refresh_file_tier(); + if (geni || line.rfind("GEN ", 0) == 0) { + refresh_file_tier(); + if (dc_learning || dc_calib) { // the request's arrival, before its prompt is read: a pause since the last one ended starts a new busy run + const Clock::time_point dc_now = Clock::now(); + if (!dc_seen_request || std::chrono::duration(dc_now - dc_last_end).count() >= strata::spec::CostLearner::kIdleS) dc_busy_since = dc_now; + dc_seen_request = true; + } + } if (!geni && line.rfind("GEN ", 0) != 0) { std::printf("ERR expected: GEN or GENI \n"); continue; @@ -19682,6 +19769,7 @@ int main(int argc, char** argv) { policy.set_context(p); const bool merged = first_window && merge_T > 0; // the prompt's last tokens and the first token bool from_sfx = false; + int sfx_pad = 0; // a learning stretch's lookup window longer than the proposal: the filler rows (DraftPolicy::Pick::pad) int sfx_match = 0; bool dfr_lookup = false; int dfr_T = 0, dfr_match = 0; @@ -19737,14 +19825,35 @@ int main(int argc, char** argv) { // chooses, and the lookup is taken without asking whether the MTP's first guess agrees const bool probabilistic = use_mtp && !req_df2 && mtp.prob(); // DFlash2's candidates are not draws from the MTP's q if (k > 0 && (probabilistic || !draft_on || sbuf[0] == drafts[0])) { + // a learning stretch may run a longer window than the proposal to time that size: the extra rows repeat the proposal's last + // token, which the verifier rejects (a deterministic proposal only: a probabilistic window keeps its own draws) const strata::spec::DraftPolicy::Pick pk = probabilistic - ? source_policy.choose(S_mtp, k, sfx_match) : policy.choose(T, k, sfx_match); - if (pk.lookup && !trace_nopick) { T = pk.t; from_sfx = true; } + ? source_policy.choose(S_mtp, k, sfx_match) : policy.choose(T, k, sfx_match, dc_learning ? S_look - 1 : 0); + if (pk.lookup && !trace_nopick && pk.t - 1 <= (int) sbuf.size()) { + T = pk.t; from_sfx = true; + if (pk.pad > 0) { + sfx_pad = pk.pad; + for (int i = k; i < k + pk.pad; ++i) sbuf[(size_t) i] = sbuf[(size_t) k - 1]; + } + } if (pk.lookup && !trace_nopick && o.lookup_max_t > 0) { // --lookup-max-t: a size whose window graph fits const int t = graph_fits(T); if (t < 0) { std::printf("ERR %s\n", err.c_str()); return 1; } T = t; } + } else if (k == 0 && dc_learning && draft_on && !probabilistic && !trace_nopick) { + // no proposal at all: a learning stretch may still time a lookup-type window size (every row after the first is filler, + // the MTP's own first guess repeated; the verifier rejects them), so that sizes only lookups reach get measured + const int s = policy.explore_lookup(std::min(S_look, (int) sbuf.size() + 1)); + if (s > 0) { + T = s; from_sfx = true; sfx_pad = s - 1; sfx_match = 0; + for (int i = 0; i < s - 1; ++i) sbuf[(size_t) i] = drafts[0]; + if (o.lookup_max_t > 0) { // --lookup-max-t: a size whose window graph fits + const int t = graph_fits(T); + if (t < 0) { std::printf("ERR %s\n", err.c_str()); return 1; } + T = t; + } + } } } } @@ -19779,6 +19888,14 @@ int main(int argc, char** argv) { chain_n = std::max(0, t - T); } } + // a learning stretch times the window sizes the round's own rule does not reach: the MTP / drafter window of a round with no lookup and no + // chain is run at another size (the rows past the real drafts are whatever the drafts array holds: valid ids that the verifier rejects); + // a deterministic window only, and only the learning stretch (DraftPolicy::explore_window) + bool win_forced = false; + if (dc_learning && draft_on && !first_window && !merged && !from_sfx && chain_n == 0 && !gated_proposal && !(use_mtp && !req_df2 && mtp.prob())) { + const int sx = policy.explore_window(T, std::min(S_mtp, (int) drafts.size() + 1)); + if (sx > 0 && p + sx <= o.max_context) { T = sx; win_forced = true; } + } const int T_mtp = T; T += chain_n; const bool timed_round = !first_window; @@ -20182,8 +20299,11 @@ int main(int argc, char** argv) { std::fprintf(df2_trace, "\n"); tr_k = 0; } - if (spec_cost && use_mtp && timed_round && !from_sfx) policy.observe_probs(dwin_s.data(), T_mtp - 1, a); - if (timed_round && !eos && chain_n == 0) + if (spec_cost && use_mtp && timed_round && !from_sfx && !win_forced) policy.observe_probs(dwin_s.data(), T_mtp - 1, a); + if (dc_learning || dc_calib) policy.set_busy_age(std::chrono::duration(Clock::now() - dc_busy_since).count()); + if (timed_round && !eos && chain_n == 0 && ((sfx_pad > 0 && from_sfx) || win_forced)) // a window run for its size's sake: its time only + policy.observe_forced(T, std::chrono::duration(Clock::now() - round0).count()); + else if (timed_round && !eos && chain_n == 0) policy.observe(from_sfx, T, a, sfx_match, std::chrono::duration(Clock::now() - round0).count()); else if (timed_round && !eos) // a chained window: its MTP part, its chain, its cost @@ -20199,6 +20319,7 @@ int main(int argc, char** argv) { if (hold_on && std::strcmp(finish, "length") == 0 && produced_n >= req_hold_n && (produced_n < max_new || admit_slot >= 0)) finish = "hold"; if (!keep_sync()) { std::printf("ERR %s\n", err.c_str()); return 1; } const double decode_ms = std::chrono::duration(Clock::now() - d0).count(); + dc_last_end = Clock::now(); // the busy run goes on when the next request starts within CostLearner::kIdleS of this if (use_df2 && o.draft_auto && bandit_key != 0 && produced_n >= 48 && decode_ms > 0.0) { DraftBandit& b = bandit[bandit_key]; const int w = req_df2 ? 1 : 0; @@ -20216,12 +20337,13 @@ int main(int argc, char** argv) { const strata::spec::CostLearner::Verdict v = policy.learner().check(kDraftCostRounds, kDraftCostMinN); if (v.ready && v.disturbed) { std::fprintf(stderr, "strata serve: draft costs: the learning stretch looks disturbed (%s): it is learned again\n", v.why.c_str()); - policy.learner().reset(); + policy.reset_learning(); } else if (v.ready) { strata::spec::CostFile cf; cf.key = dc_key; for (int k = 0; k < strata::spec::CostLearner::kCtxBuckets; ++k) - cf.tables[(size_t) k] = policy.learner().table(k, kDraftCostMinN); + cf.tables[(size_t) k] = policy.learner().table(k, kDraftCostMinN, policy.top_size()); + cf.state_effect = policy.learner().state_effect(0, kDraftCostMinN); // real rounds are counted by the same rule (fresh only, or all) // the CPU prompt share, when it is on and balancing from measured times: its balance as measured so far, to a 0.05 // step (0.5 when no short prompt has measured it yet: on an RTX A6000 a fixed 0.5 read a 981-token chunk as fast as the // balancing share, 1,001-1,009 against 995-997 ms); fixed from now on like the table @@ -20235,14 +20357,17 @@ int main(int argc, char** argv) { if (dc_pcie_ok) cf.pcie_frac = o.pcie_frac; std::string why; const bool saved = strata::spec::write_cost_file(o.draft_costs, cf, why); - if (cf.cpu_share >= 0.0) strata::prefill::Prefill::fix_cpu_share(cf.cpu_share); - if (cf.pcie_frac >= 0.0) fix_pcie_share(cf.pcie_frac); for (int k = 0; k < strata::spec::CostLearner::kCtxBuckets; ++k) if (!cf.tables[(size_t) k].empty()) policy.set_fixed_costs(cf.tables[(size_t) k].data(), (int) cf.tables[(size_t) k].size(), k); policy.set_learning(false); - policy.learner().reset(); + policy.reset_learning(); dc_learning = false; + dc_file = cf; + policy.start_calibration(cf.state_effect, cf.real, cf.cal, cf.real_cost, cf.reqs); + dc_calib = policy.calibrating(); + if (policy.table_held()) dc_shares_due = true; // the shares stay live until the table takes over + else dc_apply_shares(cf); std::string t0; char b[24]; for (size_t i = 0; i < cf.tables[0].size(); ++i) { @@ -20257,8 +20382,42 @@ int main(int argc, char** argv) { std::snprintf(b, sizeof b, "; PCIe share %.2f", cf.pcie_frac); t0 += b; } - std::fprintf(stderr, "strata serve: draft costs: this machine's table is learned (%s); it is fixed from the next request " - "on%s%s\n", t0.c_str(), saved ? "" : " (not saved: ", saved ? "" : (why + "; the next start learns again)").c_str()); + std::fprintf(stderr, "strata serve: draft costs: this machine's table is learned (%s); %s%s%s\n", t0.c_str(), + dc_calib ? "live costs decide until every size is calibrated against real requests (or 100 requests have run), then it is fixed" + : "it is fixed from the next request on", + saved ? "" : " (not saved: ", saved ? "" : (why + "; the next start learns again)").c_str()); + } + } + // --draft-costs, calibration: the real rounds of this request that the sizes still at their learned cost have collected; a size with + // kCalibN of them takes their mean (the file is rewritten whole, the new cost applies from the next request on, no later change) + if (dc_calib && (policy.calib_dirty() || policy.table_held())) { + const bool dc_was_held = policy.table_held(), dc_was_passive = policy.passive(); + strata::spec::CostFile cc = dc_file; + std::string rep, why; + if (policy.calibrate(cc, rep)) { + if (dc_was_passive && !policy.passive()) { // the table is made: the shares go in with it, the CPU share only when a short prompt has measured it + if (strata::prefill::Prefill::cpu_share_balancing() && sp.stats().cpu_share_readings > 0) + cc.cpu_share = std::clamp(std::round(sp.stats().cpu_share_balanced * 20.0) / 20.0, 0.05, 0.9); + if (dc_pcie_ok) { + if (!pcie_auto.on) cc.pcie_frac = o.pcie_frac; + else dc_pcie_pending = true; + } + dc_shares_due = true; + } + const bool saved = strata::spec::write_cost_file(o.draft_costs, cc, why); + dc_file = cc; + if (!rep.empty()) + std::fprintf(stderr, "strata serve: draft costs: calibrated against real requests: %s%s\n", rep.c_str(), + saved ? "" : (" (not saved: " + why + ")").c_str()); + } + dc_calib = policy.calibrating(); + if (dc_was_held && policy.fixed()) { // the table takes over: the stored shares are fixed with it + if (dc_shares_due) dc_apply_shares(dc_file); + dc_shares_due = false; + std::fprintf(stderr, "strata serve: draft costs: %s; this machine's table decides the windows from the next request on%s\n", + dc_calib ? "100 requests have run, sizes real requests did not reach keep a scaled learned cost until they have their own rounds" + : "every size is calibrated", + dc_file.cpu_share >= 0.0 || dc_file.pcie_frac >= 0.0 ? " (the stored shares are fixed with it)" : ""); } } // --draft-costs with a table from before the stored PCIe share: once PcieAuto has settled (three readings, or it gave up), its @@ -20270,9 +20429,12 @@ int main(int argc, char** argv) { cf.pcie_frac = o.pcie_frac; std::string why; const bool saved = strata::spec::write_cost_file(o.draft_costs, cf, why); - fix_pcie_share(cf.pcie_frac); - std::fprintf(stderr, "strata serve: draft costs: the PCIe share settled at %.2f; it is %s and fixed from the next request on\n", - cf.pcie_frac, saved ? "stored with this machine's table" : ("not stored (" + why + ")").c_str()); + dc_file = cf; + if (policy.table_held()) dc_shares_due = true; // held back: fixed when the table takes over + else fix_pcie_share(cf.pcie_frac); + std::fprintf(stderr, "strata serve: draft costs: the PCIe share settled at %.2f; it is %s and fixed %s\n", + cf.pcie_frac, saved ? "stored with this machine's table" : ("not stored (" + why + ")").c_str(), + policy.table_held() ? "when the table takes over" : "from the next request on"); } // the last commit (set_commit_async): the session is complete before anything reads or copies it if (!ver.wait_commit(err)) { diff --git a/src/spec/draft_policy.cpp b/src/spec/draft_policy.cpp index 6c26a697fe..48efeefc98 100644 --- a/src/spec/draft_policy.cpp +++ b/src/spec/draft_policy.cpp @@ -79,19 +79,60 @@ double median_of(std::vector v) { static_assert(CostLearner::kMaxT == DraftPolicy::kMaxT && CostLearner::kCtxBuckets == DraftPolicy::kCtxBuckets, "one table shape"); -void CostLearner::add(int bucket, int t, double ms) { +void CostLearner::add(int bucket, int t, double ms, double busy_age_s) { if (!(ms > 0.0) || !std::isfinite(ms)) return; bucket = std::clamp(bucket, 0, kCtxBuckets - 1); t = std::clamp(t, 1, kMaxT); - ++rounds_; - auto& v = s_[(size_t) bucket][(size_t) t]; + const bool late = busy_age_s > kFreshS; // a GPU that has been busy for long can run in another state than a request after a pause finds it + ++(late ? late_ : rounds_); + auto& v = (late ? late_s_ : s_)[(size_t) bucket][(size_t) t]; if ((int) v.size() < kKeep) v.push_back((float) ms); } void CostLearner::reset() { for (auto& b : s_) for (auto& v : b) v.clear(); + for (auto& b : late_s_) + for (auto& v : b) v.clear(); rounds_ = 0; + late_ = 0; +} + +bool CostLearner::state_effect(int bucket, int min_n) const { + if (bucket < 0 || bucket >= kCtxBuckets) return false; + const int need = std::max(1, min_n); + for (int t = 1; t <= kMaxT; ++t) { + const auto& f = s_[(size_t) bucket][(size_t) t]; + const auto& l = late_s_[(size_t) bucket][(size_t) t]; + if ((int) f.size() < need || (int) l.size() < need) continue; + const double tf = trimmed_mean(f), tl = trimmed_mean(l); + if (tf > 0.0 && std::fabs(tl - tf) / tf > kStateTol) return true; + } + return false; +} + +std::array, CostLearner::kMaxT + 1> CostLearner::sets(int bucket, bool pooled) const { + std::array, kMaxT + 1> out; + for (int t = 1; t <= kMaxT; ++t) { + out[(size_t) t] = s_[(size_t) bucket][(size_t) t]; + if (pooled) out[(size_t) t].insert(out[(size_t) t].end(), late_s_[(size_t) bucket][(size_t) t].begin(), late_s_[(size_t) bucket][(size_t) t].end()); + } + return out; +} + +bool CostLearner::state_known(int bucket, int min_n) const { + if (bucket < 0 || bucket >= kCtxBuckets) return false; + const int need = std::max(1, min_n); + for (int t = 1; t <= kMaxT; ++t) + if ((int) s_[(size_t) bucket][(size_t) t].size() >= need && (int) late_s_[(size_t) bucket][(size_t) t].size() >= need) return true; + return false; +} + +int CostLearner::usable(int bucket, int t, int min_n) const { + if (bucket < 0 || bucket >= kCtxBuckets || t < 1 || t > kMaxT) return 0; + int n = (int) s_[(size_t) bucket][(size_t) t].size(); + if (!state_effect(bucket, min_n)) n += (int) late_s_[(size_t) bucket][(size_t) t].size(); + return n; } int CostLearner::samples(int bucket, int t) const { @@ -99,13 +140,13 @@ int CostLearner::samples(int bucket, int t) const { return (int) s_[(size_t) bucket][(size_t) t].size(); } -std::vector CostLearner::table(int bucket, int min_n) const { +std::vector CostLearner::table(int bucket, int min_n, int upto) const { std::vector out; if (bucket < 0 || bucket >= kCtxBuckets) return out; - const auto& b = s_[(size_t) bucket]; + const std::array, kMaxT + 1> b = sets(bucket, !state_effect(bucket, min_n)); int top = 0; std::array got{}; - std::vector seen; + std::vector seen; // the measured sizes (min_n samples), ascending; a rough one (kWeakN samples) joins when it is accepted below for (int t = 1; t <= kMaxT; ++t) { if (!b[(size_t) t].empty()) top = t; if ((int) b[(size_t) t].size() >= std::max(1, min_n)) { @@ -114,35 +155,58 @@ std::vector CostLearner::table(int bucket, int min_n) const { } } if (top == 0 || seen.empty()) return out; - for (int t = 1; t <= top; ++t) { - if (got[(size_t) t] > 0.0) { - out.push_back(got[(size_t) t]); - continue; - } + top = std::max(top, std::min(upto, kMaxT)); + // the cost of an unmeasured size from the measured ones: linear between two, the prior shape below them, above them the straight line with the + // steeper of the last segment's slope and the slope over all measured sizes (never flatter than the measured trend) + const auto fill = [&](int t) { int lo = 0, hi = 0; for (const int u : seen) { if (u < t) lo = u; if (u > t && hi == 0) hi = u; } - if (lo > 0 && hi > 0) out.push_back(got[(size_t) lo] + (got[(size_t) hi] - got[(size_t) lo]) * (t - lo) / (double) (hi - lo)); - else { - const int u = hi > 0 ? hi : lo; - out.push_back(got[(size_t) u] * kShape[t] / kShape[u]); + if (lo > 0 && hi > 0) return got[(size_t) lo] + (got[(size_t) hi] - got[(size_t) lo]) * (t - lo) / (double) (hi - lo); + if (hi > 0) return got[(size_t) hi] * kShape[t] / kShape[hi]; + if (seen.size() < 2) return got[(size_t) lo] * kShape[t] / kShape[lo]; + const int u2 = seen.back(), u1 = seen[seen.size() - 2], u0 = seen.front(); + const double slope = std::max({0.0, (got[(size_t) u2] - got[(size_t) u1]) / (double) (u2 - u1), (got[(size_t) u2] - got[(size_t) u0]) / (double) (u2 - u0)}); + return got[(size_t) u2] + slope * (t - u2); + }; + for (int t = 1; t <= top; ++t) { + if (got[(size_t) t] > 0.0) { + out.push_back(got[(size_t) t]); + continue; } + double v = fill(t); + const int n = (int) b[(size_t) t].size(); + if (n >= kWeakN) { // a few rounds: their median counts when it is not below the trend and not far above it (a stalled handful does not) + std::vector s = b[(size_t) t]; + std::sort(s.begin(), s.end()); + const double med = n % 2 ? (double) s[(size_t) n / 2] : 0.5 * ((double) s[(size_t) n / 2 - 1] + (double) s[(size_t) n / 2]); + if (med >= v && med <= kWeakMax * v) { + v = med; + got[(size_t) t] = med; + seen.insert(std::upper_bound(seen.begin(), seen.end(), t), t); + } + } + out.push_back(v); } + for (size_t i = 1; i < out.size(); ++i) out[i] = std::max(out[i], out[i - 1]); // more rows never cost less return out; } CostLearner::Verdict CostLearner::check(int64_t min_rounds, int min_n) const { Verdict v; char b[160]; - bool any = false, every_bucket_ok = true; + bool any = false, every_bucket_ok = true, effect = false; for (int k = 0; k < kCtxBuckets; ++k) { bool has = false, measured = false; double prev_ms = 0.0; int prev_t = 0; + const bool eff = state_effect(k, min_n); + effect = effect || eff; + const std::array, kMaxT + 1> use = sets(k, !eff); for (int t = 1; t <= kMaxT; ++t) { - const auto& s = s_[(size_t) k][(size_t) t]; + const auto& s = use[(size_t) t]; has = has || !s.empty(); if ((int) s.size() < std::max(1, min_n)) continue; measured = true; @@ -175,14 +239,18 @@ CostLearner::Verdict CostLearner::check(int64_t min_rounds, int min_n) const { any = any || measured; if (has && !measured) every_bucket_ok = false; } - v.ready = rounds_ >= min_rounds && any && every_bucket_ok; + // no state effect: every round counts. With one: the fresh rounds, or, for a stretch that never paused (one long burst keeps only its first kFreshS + // seconds), kFallbackFactor x the quota in rounds of any age when the fresh ones are at least 1 / kFallbackShare of the quota + const bool enough = effect ? (rounds_ >= min_rounds || (rounds_ + late_ >= kFallbackFactor * min_rounds && rounds_ * kFallbackShare >= min_rounds)) + : rounds_ + late_ >= min_rounds; + v.ready = enough && any && every_bucket_ok; return v; } // ---------------------------------------------------------------------------------------------------- the table file namespace { -constexpr const char* kCostFileHead = "strata-draft-costs 1"; +constexpr const char* kCostFileHead = "strata-draft-costs 2"; // 2: learned from the rounds of the first seconds of a busy run; a version 1 file is learned again // the path as UTF-8 (the server passes it so); on Windows a plain std::string would be read in the ANSI code page std::filesystem::path utf8_path(const std::string& s) { return std::filesystem::path(std::u8string(s.begin(), s.end())); } std::string one_line(std::string s) { @@ -217,6 +285,63 @@ bool read_cost_file(const std::string& path, const std::string& key, CostFile& o out.pcie_frac = s; continue; } + if (line.rfind("state ", 0) == 0) { // calibration lines (DraftPolicy::start_calibration); a file without them has no calibration done + if (line != "state 0" && line != "state 1") { why = "a malformed state"; return false; } + out.state_effect = line == "state 1"; + continue; + } + if (line == "fresh 1") { out.fresh = true; continue; } + if (line.rfind("reqs ", 0) == 0) { + int rq = -1; + if (std::sscanf(line.c_str(), "reqs %d", &rq) != 1 || rq < 0 || rq > 1000000) { why = "a malformed request count"; return false; } + out.reqs = rq; + continue; + } + if (line.rfind("real ", 0) == 0) { + int rb = -1; + unsigned m = 0; + if (std::sscanf(line.c_str(), "real %d %u", &rb, &m) != 2 || rb < 0 || rb >= CostLearner::kCtxBuckets) { why = "a malformed real mark"; return false; } + out.real[(size_t) rb] = m; + continue; + } + if (line.rfind("cal ", 0) == 0) { + int cb = -1, ct = -1, cn = -1, used = 0; + double cs = -1.0; + if (std::sscanf(line.c_str(), "cal %d %d %d %lf%n", &cb, &ct, &cn, &cs, &used) != 4 || cb < 0 || cb >= CostLearner::kCtxBuckets || ct < 1 || ct > CostLearner::kMaxT + || cn < 0 || cn > 100000 || !(cs >= 0.0) || !(cs < 1e9)) { + why = "a malformed calibration line"; + return false; + } + CalAcc ca; + ca.n = cn; + ca.sum = cs; + { // the rounds themselves (a line from before them: none, the mean decides as it did) + const char* p = line.c_str() + used; + int k = 0; + bool ok = true; + while (k < CalAcc::kVals) { + char* e = nullptr; + const double v = std::strtod(p, &e); + if (e == p) break; + if (!(v > 0.0) || !(v < 1e6)) { ok = false; break; } + ca.vals[(size_t) k++] = v; + p = e; + } + ca.nv = ok && k == cn && cn <= CalAcc::kVals ? k : 0; + } + out.cal[(size_t) cb][(size_t) ct] = ca; + continue; + } + if (line.rfind("rc ", 0) == 0) { + int rb = -1, rt = -1; + double rv = -1.0; + if (std::sscanf(line.c_str(), "rc %d %d %lf", &rb, &rt, &rv) != 3 || rb < 0 || rb >= CostLearner::kCtxBuckets || rt < 1 || rt > CostLearner::kMaxT || !(rv > 0.0) || !(rv < 1e5)) { + why = "a malformed real cost"; + return false; + } + out.real_cost[(size_t) rb][(size_t) rt] = rv; + continue; + } int b = -1, used = 0; if (std::sscanf(line.c_str(), "bucket %d %n", &b, &used) < 1 || used == 0 || b < 0 || b >= CostLearner::kCtxBuckets) { why = "a malformed line"; @@ -237,7 +362,7 @@ bool read_cost_file(const std::string& path, const std::string& key, CostFile& o out.tables[(size_t) b] = std::move(v); any = true; } - if (!ended || !any) { why = "the file is cut short"; return false; } + if (!ended || (!any && !out.fresh) || (any && out.fresh)) { why = "the file is cut short"; return false; } out.key = key; return true; } @@ -264,6 +389,29 @@ bool write_cost_file(const std::string& path, const CostFile& c, std::string& wh } f << "\n"; } + if (c.state_effect) f << "state 1\n"; + if (c.reqs > 0) f << "reqs " << c.reqs << "\n"; + if (c.fresh) f << "fresh 1\n"; + for (int k = 0; k < CostLearner::kCtxBuckets; ++k) { + if (c.real[(size_t) k] != 0u) f << "real " << k << " " << c.real[(size_t) k] << "\n"; + for (int t = 1; t <= CostLearner::kMaxT; ++t) + if ((c.real[(size_t) k] >> (t - 1) & 1u) && c.real_cost[(size_t) k][(size_t) t] > 0.0) { + std::snprintf(b, sizeof b, "%.4f", c.real_cost[(size_t) k][(size_t) t]); + f << "rc " << k << " " << t << " " << b << "\n"; + } + for (int t = 1; t <= CostLearner::kMaxT; ++t) { + const CalAcc& a = c.cal[(size_t) k][(size_t) t]; + if (a.n <= 0 || (c.real[(size_t) k] >> (t - 1) & 1u)) continue; + std::snprintf(b, sizeof b, "%.4f", a.sum); + f << "cal " << k << " " << t << " " << a.n << " " << b; + if (a.nv == a.n) + for (int i = 0; i < a.nv; ++i) { + std::snprintf(b, sizeof b, "%.4f", (double) a.vals[(size_t) i]); + f << " " << b; + } + f << "\n"; + } + } if (c.cpu_share >= 0.0) { std::snprintf(b, sizeof b, "share %.3f\n", std::min(c.cpu_share, 1.0)); f << b; @@ -291,14 +439,22 @@ DraftPolicy::DraftPolicy(int max_t, double margin) } void DraftPolicy::set_fixed_costs(const double* ms, int n, int bucket) { + if (!fixed_ && !live_saved_) { // the live costs at this point: start_calibration() may hand them back + live_cost_ = cost_; + live_n_ = cost_n_; + live_saved_ = true; + } fixed_ = true; + held_table_ = false; held_.clear(); if (ms == nullptr || n <= 0) return; bucket = std::clamp(bucket, 0, kCtxBuckets - 1); + fixed_n_[(size_t) bucket] = std::min(n, kMaxT); for (int t = 1; t <= kMaxT; ++t) { // the table replaces what was measured; sizes past its end scale from it (cost_ms) const bool in = t <= n && ms[t - 1] > 0.0; cost_[bucket][t] = in ? ms[t - 1] : 0.0; cost_n_[bucket][t] = in ? 1e6 : 0.0; + learned_[(size_t) bucket][(size_t) t] = cost_[bucket][t]; } } @@ -405,10 +561,19 @@ double DraftPolicy::mtp_tokens(int t) const { return 1.0 + 0.7 * (t - 1); // before any MTP window of this size: a typical acceptance } -DraftPolicy::Pick DraftPolicy::choose(int t_mtp, int lookup_k, int match) const { +DraftPolicy::Pick DraftPolicy::choose(int t_mtp, int lookup_k, int match, int pad_cap) const { Pick p; p.t = std::clamp(t_mtp, 1, max_t_); if (lookup_k <= 0) return p; + if (learning_ && !fixed_) { // a learning stretch measures the sizes it has too few rounds of, when a proposal is long enough for one + const int s = explore_size(lookup_k, pad_cap); + if (s > 0) { + p.lookup = true; + p.t = s; + p.pad = std::max(0, s - 1 - lookup_k); + return p; + } + } const double base = mtp_tokens(p.t) / cost_ms(p.t); const double q = lookup_rate(match); double e = 1.0, qi = 1.0, best = 0.0; @@ -437,9 +602,60 @@ DraftPolicy::Pick DraftPolicy::choose(int t_mtp, int lookup_k, int match) const return p; } +bool DraftPolicy::explore_ok() const { + const double age = busy_age_ < 0.0 ? 0.0 : busy_age_; + if (age <= CostLearner::kFreshS) return true; // a fresh round: it counts on every machine + return learner_.state_known(bk_, 20) && !learner_.state_effect(bk_, 20); // a late round counts only where the stretch has shown no state effect +} + +int DraftPolicy::explore_next(int reach, int skip) const { + if (learner_.rounds() + learner_.late_rounds() < kExploreAfter || forced_total_ >= kExploreBudget || !explore_ok()) return 0; + for (int s = 2; s <= std::min(reach, max_t_); ++s) { + if (s == skip || !allowed(s) || forced_[(size_t) s] >= kExplorePerSize || learner_.usable(bk_, s, 20) >= kExploreN) continue; + ++forced_[(size_t) s]; + ++forced_total_; + return s; + } + return 0; +} + +int DraftPolicy::explore_size(int lookup_k, int pad_cap) const { + return explore_next(std::max(lookup_k, pad_cap) + 1, 0); +} + +int DraftPolicy::explore_lookup(int cap) const { + if (!learning_ || fixed_) return 0; + return explore_next(cap, 0); +} + +int DraftPolicy::explore_window(int t, int cap) const { + if (!learning_ || fixed_) return 0; + return explore_next(cap, t); +} + +void DraftPolicy::observe_forced(int t, double round_ms) { + t = std::clamp(t, 1, kMaxT); + if (learning_ && round_ms > 0) learner_.add(bk_, t, round_ms, busy_age_); + if (round_ms > 0 && !fixed_) { + round_ms = clamp_sample(t, round_ms); + const double alpha = robust_ ? std::max(kCostAlpha, 1.0 / (cost_n_[bk_][t] + 1.0)) : kCostAlpha; + cost_[bk_][t] = cost_n_[bk_][t] > 0 ? (1.0 - alpha) * cost_[bk_][t] + alpha * round_ms : round_ms; + cost_n_[bk_][t] += 1.0; + last_[bk_][t] = rounds_; + } + rounds_ += 1.0; +} + +void DraftPolicy::reset_learning() { + learner_.reset(); + forced_total_ = 0; + forced_.fill(0); +} + void DraftPolicy::observe(bool lookup, int t, int accepted, int match, double round_ms) { t = std::clamp(t, 1, kMaxT); - if (learning_ && round_ms > 0) learner_.add(bk_, t, round_ms); + if (learning_ && round_ms > 0) learner_.add(bk_, t, round_ms, busy_age_); + if (calib_on_ && round_ms > 0) calib_add(bk_, t, round_ms, busy_age_); if (round_ms > 0 && !fixed_) { round_ms = clamp_sample(t, round_ms); const double alpha = robust_ ? std::max(kCostAlpha, 1.0 / (cost_n_[bk_][t] + 1.0)) : kCostAlpha; // a running mean for the first samples @@ -459,6 +675,226 @@ void DraftPolicy::observe(bool lookup, int t, int accepted, int match, double ro } } +// ---- calibration of a fixed table against real requests (see the header) + +void DraftPolicy::apply_table() { + if (!fixed_) return; // a held table: cost_ is the live cost, not touched + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + if (n <= 0) continue; + // a size that is not real (real requests never reached it in kCalibReqs requests): its learned cost x the mean (real / learned) of the real sizes of + // 2 or more rows, so it is not left at a price that the sizes next to it have left (size 1 stays); no real size of 2+ rows: its learned cost + double sum = 0.0; + int cnt = 0; + for (int t = 2; t <= n; ++t) + if ((real_[(size_t) k] >> (t - 1) & 1u) && learned_[(size_t) k][(size_t) t] > 0.0) { + sum += real_cost_[(size_t) k][(size_t) t] / learned_[(size_t) k][(size_t) t]; + ++cnt; + } + const double r = cnt > 0 ? sum / cnt : 1.0; + for (int t = 1; t <= n; ++t) { + if (real_[(size_t) k] >> (t - 1) & 1u) cost_[(size_t) k][(size_t) t] = real_cost_[(size_t) k][(size_t) t]; + else cost_[(size_t) k][(size_t) t] = learned_[(size_t) k][(size_t) t] * (t >= 2 ? r : 1.0); + } + // more rows never cost less. An inversion is repaired from the trusted side: a size that is only guessed (not real), or that sits below another real size, is + // LOWERED to the price of the next larger size first (a cold first-use round or a live value taken at take-over made it too high; raising every larger size to it, + // as a forward pass alone does, made one 20 ms 2-row price of the srv118 table the price of every size from 2 to 7 rows and the policy took 12-row windows); + // a real size above an unreached next size is left, and the forward pass then lifts that guess to it + for (int t = n - 1; t >= 1; --t) { + const bool real_t = real_[(size_t) k] >> (t - 1) & 1u, real_next = real_[(size_t) k] >> t & 1u; + if (cost_[(size_t) k][(size_t) t] > cost_[(size_t) k][(size_t) t + 1] && (!real_t || real_next)) + cost_[(size_t) k][(size_t) t] = cost_[(size_t) k][(size_t) t + 1]; + } + for (int t = 2; t <= n; ++t) + if (cost_[(size_t) k][(size_t) t] < cost_[(size_t) k][(size_t) t - 1]) cost_[(size_t) k][(size_t) t] = cost_[(size_t) k][(size_t) t - 1]; + } +} + +void DraftPolicy::start_calibration(bool state_effect, const std::array& real, + const std::array, kCtxBuckets>& cal, + const std::array, kCtxBuckets>& real_cost, int reqs) { + reqs_ = std::max(reqs, 0); + calib_fresh_only_ = state_effect; + real_ = real; + cal_ = cal; + real_cost_ = real_cost; + for (int k = 0; k < kCtxBuckets; ++k) // a mark without a cost (a damaged file) is no mark + for (int t = 1; t <= kMaxT; ++t) + if ((real_[(size_t) k] >> (t - 1) & 1u) && !(real_cost_[(size_t) k][(size_t) t] > 0.0)) real_[(size_t) k] &= ~(1u << (t - 1)); + apply_table(); + calib_dirty_ = false; + calib_on_ = false; + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + for (int t = 1; t <= n; ++t) + if (!(real_[(size_t) k] >> (t - 1) & 1u)) calib_on_ = true; + } + // not calibrated: live costs decide, as without a table, until kCalibReqs requests have collected real rounds (a size real requests do not reach + // would hold the table back for good) + if (calib_on_ && reqs_ < kCalibReqs && fixed_ && live_saved_) hold_table(); +} + +void DraftPolicy::start_passive(const CostFile& cf, int n) { + passive_ = true; + calib_fresh_only_ = true; // see the header: only the first seconds of a busy run count, no detection of a load-time effect + real_ = {}; + real_[0] = cf.real[0]; + cal_ = {}; + cal_[0] = cf.cal[0]; + real_cost_ = {}; + real_cost_[0] = cf.real_cost[0]; + learned_ = {}; + fixed_n_ = {}; + fixed_n_[0] = std::clamp(n, 1, kMaxT); + for (int t = 1; t <= kMaxT; ++t) // a mark without a cost (a damaged file) is no mark; a size past the table length is none + if ((real_[0] >> (t - 1) & 1u) && (!(real_cost_[0][(size_t) t] > 0.0) || t > fixed_n_[0])) real_[0] &= ~(1u << (t - 1)); + reqs_ = std::max(cf.reqs, 0); + held_table_ = true; + fixed_ = false; + calib_on_ = true; + calib_dirty_ = false; +} + +void DraftPolicy::take_over_passive() { + const int bk_was = bk_; + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + for (int t = 1; t <= n; ++t) { + double v; + if (real_[(size_t) k] >> (t - 1) & 1u) v = real_cost_[(size_t) k][(size_t) t]; // a real size: its own cost + else if (cost_n_[k][t] > 0 && cost_[k][t] > 0.0) v = cost_[k][t]; // a size never reached 16 rounds: what the live estimator has now + else { + bk_ = k; + v = cost_ms(t); // never measured: the policy's own prior, as without a table + bk_ = bk_was; + } + if (!(v > 0.0)) v = t > 1 ? learned_[(size_t) k][(size_t) t - 1] : 1.0; + learned_[(size_t) k][(size_t) t] = v; + } + } + passive_ = false; +} + +void DraftPolicy::hold_table() { + for (int k = 0; k < kCtxBuckets; ++k) { + if (fixed_n_[(size_t) k] <= 0) continue; + cost_[(size_t) k] = live_cost_[(size_t) k]; + cost_n_[(size_t) k] = live_n_[(size_t) k]; + } + fixed_ = false; + held_table_ = true; + held_.clear(); +} + +void DraftPolicy::use_table() { + fixed_ = true; + apply_table(); // every size is real: its real cost + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + if (n <= 0) continue; + for (int t = 1; t <= kMaxT; ++t) { + const bool in = t <= n && cost_[(size_t) k][(size_t) t] > 0.0; + if (!in) cost_[(size_t) k][(size_t) t] = 0.0; + cost_n_[(size_t) k][(size_t) t] = in ? 1e6 : 0.0; + } + } + fixed_ = true; + held_table_ = false; + held_.clear(); +} + +void DraftPolicy::calib_add(int bucket, int t, double ms, double age) { + static_assert(kCalibN <= CalAcc::kVals, "a size's rounds are all kept for the median"); + if (bucket < 0 || bucket >= kCtxBuckets || t < 1 || t > fixed_n_[(size_t) bucket]) return; + if (real_[(size_t) bucket] >> (t - 1) & 1u) return; + if (calib_fresh_only_ && age > CostLearner::kFreshS) return; // the table is what rounds of the first seconds of a busy run cost + double base = learned_[(size_t) bucket][(size_t) t]; + if (!(base > 0.0) && passive_) base = cost_n_[bucket][t] > 0 ? cost_[bucket][t] : 0.0; // no learned table: the live cost of the size is the reference + if (!(base > 0.0)) return; + CalAcc& a = cal_[(size_t) bucket][(size_t) t]; + if (a.n >= kCalibN) return; + const double r = std::clamp(ms, kCalibLo * base, kCalibHi * base); // one stalled round moves the mean by at most (kCalibHi - 1) / kCalibN + a.sum += r; + if (a.nv == a.n && a.n < CalAcc::kVals) a.vals[(size_t) a.nv++] = r; // the rounds are kept: the price is their median + a.n += 1; + calib_dirty_ = true; +} + +bool DraftPolicy::calibrate(CostFile& cf, std::string& report) { + report.clear(); + if (!calib_on_ && !calib_dirty_) return false; + if (held_table_) ++reqs_; // a request that ran while the table is held back + char b[96]; + bool changed = calib_dirty_ || held_table_, replaced = false; // a held table: the request count changed + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + for (int t = 1; t <= n; ++t) { + if (real_[(size_t) k] >> (t - 1) & 1u) continue; + CalAcc& a = cal_[(size_t) k][(size_t) t]; + if (a.n < kCalibN) continue; + double v = a.sum / a.n; // a file from before the kept rounds: the mean + if (a.nv == a.n && a.n > 0) { // the median of the rounds: a cold first use, a stall, another process move a mean, not a median + std::array s = a.vals; + std::sort(s.begin(), s.begin() + a.nv); + v = a.nv % 2 == 1 ? s[(size_t) a.nv / 2] : 0.5 * (s[(size_t) a.nv / 2 - 1] + s[(size_t) a.nv / 2]); + } + const double base = learned_[(size_t) k][(size_t) t]; + if (!(base > 0.0) || (v >= kCalibOkLo * base && v <= kCalibOkHi * base)) { // no learned cost (passive): the clamped rounds are taken as they are + if (base > 0.0) std::snprintf(b, sizeof b, "%s%d rows %.2f -> %.2f", report.empty() ? "" : ", ", t, base, v); + else std::snprintf(b, sizeof b, "%s%d rows real %.2f", report.empty() ? "" : ", ", t, v); + report += b; + real_cost_[(size_t) k][(size_t) t] = v; + real_[(size_t) k] |= 1u << (t - 1); + replaced = true; + } + a = CalAcc{}; // replaced, or disturbed (rounds dropped, collected again) + } + } + if (replaced && fixed_) { // the table is in use with sizes that were not reached: their scaled costs follow the real sizes + std::array, kCtxBuckets> before = cost_; + apply_table(); + for (int k = 0; k < kCtxBuckets; ++k) + for (int t = 1; t <= fixed_n_[(size_t) k]; ++t) + if (!(real_[(size_t) k] >> (t - 1) & 1u) && std::fabs(cost_[(size_t) k][(size_t) t] - before[(size_t) k][(size_t) t]) > 0.005) { + std::snprintf(b, sizeof b, "%s%d rows (not real yet) %.2f -> %.2f", report.empty() ? "" : ", ", t, before[(size_t) k][(size_t) t], cost_[(size_t) k][(size_t) t]); + report += b; + } + } + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + if (n <= 0) continue; + if (!(passive_ && !fixed_)) cf.tables[(size_t) k].assign(learned_[(size_t) k].begin() + 1, learned_[(size_t) k].begin() + 1 + n); // the file keeps the learned costs + cf.real[(size_t) k] = real_[(size_t) k]; + for (int t = 0; t <= kMaxT; ++t) { + cf.cal[(size_t) k][(size_t) t] = cal_[(size_t) k][(size_t) t]; + cf.real_cost[(size_t) k][(size_t) t] = real_cost_[(size_t) k][(size_t) t]; + } + } + cf.state_effect = calib_fresh_only_; + cf.reqs = reqs_; + cf.fresh = passive_; + calib_dirty_ = false; + calib_on_ = false; + for (int k = 0; k < kCtxBuckets; ++k) + for (int t = 1; t <= fixed_n_[(size_t) k]; ++t) + if (!(real_[(size_t) k] >> (t - 1) & 1u)) calib_on_ = true; + // the last size is calibrated, or kCalibReqs requests have not reached the rest: the table decides from the next round on + if (held_table_ && (!calib_on_ || reqs_ >= kCalibReqs)) { + if (passive_) { + take_over_passive(); + for (int k = 0; k < kCtxBuckets; ++k) { + const int n = fixed_n_[(size_t) k]; + if (n > 0) cf.tables[(size_t) k].assign(learned_[(size_t) k].begin() + 1, learned_[(size_t) k].begin() + 1 + n); + } + cf.fresh = false; + changed = true; + } + use_table(); + if (calib_on_) report += std::string(report.empty() ? "" : ", ") + "table in use, sizes real requests did not reach keep a scaled learned cost"; + } + return changed || replaced; +} + void DraftPolicy::observe_committed(bool lookup, int t, int accepted, int match) { t = std::clamp(t, 1, kMaxT); rounds_ += 1.0; @@ -476,7 +912,7 @@ void DraftPolicy::observe_committed(bool lookup, int t, int accepted, int match) } void DraftPolicy::defer_cost(int64_t end, int t, double round_ms) { - if (round_ms > 0 && (learning_ || !fixed_)) held_.push_back({end, bk_, std::clamp(t, 1, kMaxT), round_ms}); + if (round_ms > 0 && (learning_ || calib_on_ || !fixed_)) held_.push_back({end, bk_, std::clamp(t, 1, kMaxT), round_ms, busy_age_}); } void DraftPolicy::apply_costs(int64_t committed) { @@ -484,7 +920,8 @@ void DraftPolicy::apply_costs(int64_t committed) { const int bucket_now = bk_; for (; n < held_.size() && held_[n].end < committed; ++n) { const HeldCost& h = held_[n]; - if (learning_) learner_.add(h.bucket, h.t, h.ms); + if (learning_) learner_.add(h.bucket, h.t, h.ms, h.age); + if (calib_on_) calib_add(h.bucket, h.t, h.ms, h.age); if (fixed_) continue; bk_ = h.bucket; // observe()'s update, in the bucket the round ran in const double ms = clamp_sample(h.t, h.ms); @@ -584,7 +1021,7 @@ int DraftPolicy::chain(int t_mtp, double p_mtp, int k_avail, int match) const { void DraftPolicy::observe_chain(int t_mtp, int k, int accepted, int match, double round_ms) { const int t = std::clamp(t_mtp + k, 1, kMaxT); - if (learning_ && round_ms > 0) learner_.add(bk_, t, round_ms); + if (learning_ && round_ms > 0) learner_.add(bk_, t, round_ms, busy_age_); if (round_ms > 0 && !fixed_) { round_ms = clamp_sample(t, round_ms); const double alpha = robust_ ? std::max(kCostAlpha, 1.0 / (cost_n_[bk_][t] + 1.0)) : kCostAlpha; // a running mean for the first samples diff --git a/src/spec/draft_policy_test.cpp b/src/spec/draft_policy_test.cpp index bb425d597f..3fe54645d4 100644 --- a/src/spec/draft_policy_test.cpp +++ b/src/spec/draft_policy_test.cpp @@ -8,6 +8,7 @@ // 5. the policy never proposes a window beyond its cap. #include "strata/spec/draft_policy.hpp" +#include #include #include #include @@ -279,6 +280,89 @@ int main() { check(p.learner().rounds() == 3 && p.learner().samples(0, 4) == 2 && p.learner().samples(0, 2) == 1, "learning on: observe, observe_chain and held times are collected"); } + { + // The fixture of the Mac lane's fresh learning run (M5 Max, Q2_0, 30 requests of 256 tokens): sample counts and mean round ms per window size. + // 4 rows had 2 samples: its value comes from its neighbours, not from the two samples. + using strata::spec::CostLearner; + const auto fill = [](CostLearner& L, int t, int n, double ms, double age) { // n samples around ms (+-1 %, mean ms) + for (int i = 0; i < n; ++i) L.add(0, t, ms * (1.0 + 0.005 * ((i % 5) - 2)), age); + }; + CostLearner M; + fill(M, 1, 1193, 13.50, 2.0); fill(M, 2, 894, 15.74, 2.0); fill(M, 3, 1834, 18.40, 2.0); fill(M, 4, 2, 22.62, 2.0); fill(M, 5, 83, 24.95, 2.0); + const std::vector t = M.table(0, 20); + check(t.size() == 5 && std::fabs(t[0] - 13.50) < 0.05 && std::fabs(t[2] - 18.40) < 0.05 && std::fabs(t[4] - 24.95) < 0.05, "fit: the well-sampled sizes are their trimmed means"); + check(t.size() == 5 && std::fabs(t[3] - (18.40 + 24.95) / 2.0) < 0.05, "fit: 4 rows (2 samples) lie between its neighbours, not at its own 22.62"); + check(M.rounds() == 4006 && M.late_rounds() == 0, "fit: all 4,006 rounds of the fixture were fresh"); + // a size above the measured ones (5 rows with 8 samples): the straight line through the two largest measured sizes + CostLearner E; + fill(E, 1, 600, 12.5, 2.0); fill(E, 2, 400, 14.2, 2.0); fill(E, 3, 700, 16.2, 2.0); fill(E, 5, 8, 99.0, 2.0); + const std::vector e = E.table(0, 20); + check(e.size() == 5 && std::fabs(e[3] - (16.2 + 2.0)) < 0.05 && std::fabs(e[4] - (16.2 + 4.0)) < 0.05, + "fit: 4 and 5 rows above the measured sizes continue the line through 2 and 3 rows (8 samples of 5 rows are not trusted)"); + bool mono = true; + for (size_t i = 1; i < e.size(); ++i) mono &= e[i] >= e[i - 1]; + CostLearner Dn; // a size measured cheaper than the one before it (noise): the table does not fall + fill(Dn, 1, 100, 20.0, 2.0); fill(Dn, 2, 100, 19.0, 2.0); fill(Dn, 3, 100, 25.0, 2.0); + const std::vector d = Dn.table(0, 20); + mono &= d.size() == 3 && d[1] >= d[0] && d[2] >= d[1]; + check(mono, "fit: the table never falls from one size to the next"); + // busy age: a fast state for the first seconds of a run, a slow and steeper one later; only the first is kept + CostLearner B; + for (int i = 0; i < 1400; ++i) { + B.add(0, 1, 12.5, 4.0); B.add(0, 2, 14.2, 4.0); B.add(0, 3, 16.2, 4.0); // fresh (the first seconds of a run) + B.add(0, 1, 14.5, 60.0); B.add(0, 2, 17.1, 60.0); B.add(0, 3, 20.2, 60.0); // the same machine after a minute of load + if (i % 25 == 0) { B.add(0, 5, 21.3, 4.0); B.add(0, 5, 27.7, 60.0); } + } + const std::vector b = B.table(0, 20); + check(B.rounds() == 4200 + 56 && B.late_rounds() == 4200 + 56, "busy age: late rounds are counted and not kept"); + check(b.size() == 5 && std::fabs(b[2] - 16.2) < 0.05 && std::fabs(b[4] / b[2] - 21.3 / 16.2) < 0.01, + "busy age: the table is the fast state (5 rows against 3 rows 1.31, not 1.37 of the late rounds)"); + CostLearner U; // an age that is not known counts as fresh + U.add(0, 3, 16.0); + check(U.rounds() == 1 && U.late_rounds() == 0, "busy age: an unknown age (none given) is kept"); + // readiness: a stretch that never paused ends with its first seconds after 3 x the quota; one that is mid-way is not ready + CostLearner Bur; + for (int i = 0; i < 300; ++i) { Bur.add(0, 1, 12.5, 2.0); Bur.add(0, 2, 14.2, 2.0); Bur.add(0, 3, 16.2, 2.0); } // 900 fresh rounds + check(!Bur.check(1000, 20).ready, "ready: 900 fresh rounds and nothing else is not ready"); + for (int i = 0; i < 700; ++i) Bur.add(0, 3, 20.2, 90.0); + check(!Bur.check(1000, 20).ready, "ready: late rounds below 3 x the quota do not end a short stretch"); + CostLearner Bur2; // one long burst: 330 fresh rounds, then 2,700 late ones + for (int i = 0; i < 110; ++i) { Bur2.add(0, 1, 12.5, 2.0); Bur2.add(0, 2, 14.2, 2.0); Bur2.add(0, 3, 16.2, 2.0); } + for (int i = 0; i < 2000; ++i) Bur2.add(0, 3, 20.2, 90.0); + check(!Bur2.check(1000, 20).ready, "ready: 330 fresh + 2,000 late rounds (under 3 x the quota) is not ready"); + for (int i = 0; i < 700; ++i) Bur2.add(0, 3, 20.2, 90.0); + const CostLearner::Verdict bv = Bur2.check(1000, 20); + const std::vector bt = Bur2.table(0, 20); + check(bv.ready && !bv.disturbed && bt.size() == 3 && std::fabs(bt[2] - 16.2) < 0.05, + "ready: one burst that never paused ends after 3 x the quota, with the table of its first seconds"); + CostLearner Few; // 150 fresh rounds only: not enough even after a very long burst + for (int i = 0; i < 50; ++i) { Few.add(0, 1, 12.5, 2.0); Few.add(0, 2, 14.2, 2.0); Few.add(0, 3, 16.2, 2.0); } + for (int i = 0; i < 5000; ++i) Few.add(0, 3, 20.2, 90.0); + check(!Few.check(1000, 20).ready, "ready: under a fifth of the quota kept is never ready"); + // a machine without a state effect (the Radeon 780M: 75.5 ms for one row early, 76.0 late; windows of 1, 3 and 6 rows): every round counts, the rare sizes + // get all their samples (3 rows: 8 fresh + 100 late) + CostLearner R; + fill(R, 1, 80, 75.5, 2.0); fill(R, 3, 8, 111.0, 2.0); fill(R, 6, 3, 178.0, 2.0); + fill(R, 1, 1200, 76.0, 40.0); fill(R, 3, 100, 111.2, 40.0); fill(R, 6, 14, 178.1, 40.0); + const std::vector rt = R.table(0, 20); + check(!R.state_effect(0, 20), "pooled: 0.7 % between early and late rounds is no state effect"); + check(rt.size() == 6 && std::fabs(rt[2] - 111.1) < 0.2 && std::fabs(rt[0] - 76.0) < 0.2, "pooled: the table uses every round (3 rows from 108 samples)"); + check(R.check(1000, 20).ready, "pooled: ready after the quota of rounds of any age"); + check(B.state_effect(0, 20), "state effect: 16 % between early and late rounds is one"); + // the policy hands the age to the learner, and a held (gated) time keeps the age it had + DraftPolicy pa(6); + pa.set_learning(true); + pa.set_busy_age(30.0); + pa.observe(false, 3, 1, 0, 20.0); + pa.set_busy_age(2.0); + pa.observe(false, 3, 1, 0, 16.0); + check(pa.learner().rounds() == 1 && pa.learner().late_rounds() == 1 && pa.learner().samples(0, 3) == 1, "policy: a round is kept by the busy age it ran at"); + pa.set_busy_age(40.0); + pa.defer_cost(5, 3, 21.0); + pa.set_busy_age(1.0); + pa.apply_costs(100); + check(pa.learner().rounds() == 1 && pa.learner().late_rounds() == 2, "policy: a held time keeps the busy age of its round"); + } { // The table file: a round trip, another key, a cut-short file, a missing file, a folder that does not exist yet. namespace fs = std::filesystem; @@ -298,9 +382,9 @@ int main() { "file: read back with its key, every bucket as written"); check(!strata::spec::read_cost_file(path, "card B|engine 1|model m spec 6", r, why) && !why.empty(), "file: another key is not loaded"); check(!strata::spec::read_cost_file((dir / "none.costs").string(), c.key, r, why), "file: a missing file is not loaded"); - { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,18"; } + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,18"; } check(!strata::spec::read_cost_file(path, "x", r, why), "file: a cut-short file (no end line) is not loaded"); - { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,abc\nend\n"; } + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,abc\nend\n"; } check(!strata::spec::read_cost_file(path, "x", r, why), "file: a malformed table is not loaded"); check(strata::spec::write_cost_file(path, c, why) && strata::spec::read_cost_file(path, c.key, r, why), "file: a bad file is replaced whole"); check(!fs::exists(fs::path(path + ".tmp"), ec), "file: no temporary file is left"); @@ -308,23 +392,506 @@ int main() { c.cpu_share = 0.45; check(strata::spec::write_cost_file(path, c, why) && strata::spec::read_cost_file(path, c.key, r, why) && r.cpu_share == 0.45, "file: the CPU prompt share is stored and read back with the table"); - { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,18\nshare 1.7\nend\n"; } + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,18\nshare 1.7\nend\n"; } check(!strata::spec::read_cost_file(path, "x", r, why), "file: a share outside 0..1 is not loaded"); // the decode PCIe share PcieAuto settled on (repeatable output): stored and read back; a file written before it has none, and // still loads (the engine then refines the share as before and writes it) - { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,18\nshare 0.900\nend\n"; } + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,18\nshare 0.900\nend\n"; } check(strata::spec::read_cost_file(path, "x", r, why) && r.cpu_share == 0.9 && r.pcie_frac < 0.0, "file: a file from before the PCIe share loads, with no PCIe share"); c.pcie_frac = 0.15; check(strata::spec::write_cost_file(path, c, why) && strata::spec::read_cost_file(path, c.key, r, why) && r.pcie_frac == 0.15 && r.cpu_share == 0.45 && r.tables[0].size() == 4, "file: the PCIe share is stored and read back with the table and the prompt share"); - { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,18\npcie -0.2\nend\n"; } + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,18\npcie -0.2\nend\n"; } check(!strata::spec::read_cost_file(path, "x", r, why), "file: a PCIe share outside 0..1 is not loaded"); - { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,18\npcie 0.15x\nend\n"; } + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,18\npcie 0.15x\nend\n"; } check(!strata::spec::read_cost_file(path, "x", r, why), "file: a malformed PCIe share is not loaded"); + // version 1 (learned from every round, so from the slow state of a long burst): not loaded, learned again + { std::ofstream f(path, std::ios::binary | std::ios::trunc); f << "strata-draft-costs 1\nkey x\nbucket 0 15.1,18\nend\n"; } + check(!strata::spec::read_cost_file(path, "x", r, why) && why.find("format") != std::string::npos, "file: a version 1 table is not loaded (learned again)"); + // a start closed in the middle of learning leaves no table: nothing is written before the stretch is ready, and a half-written temporary file + // (the process died while writing) is never read as the table + fs::remove(fs::path(path), ec); + { std::ofstream f(path + ".tmp", std::ios::binary | std::ios::trunc); f << "strata-draft-costs 2\nkey x\nbucket 0 15.1,18"; } + check(!strata::spec::read_cost_file(path, "x", r, why), "file: a half-written temporary file beside a missing table is not a table"); + check(strata::spec::write_cost_file(path, c, why) && strata::spec::read_cost_file(path, c.key, r, why) && !fs::exists(fs::path(path + ".tmp"), ec), + "file: the next write replaces the leftover temporary file and the table loads"); fs::remove_all(dir, ec); } + { + // sizes with too few samples: a rough measurement counts when it is not below the trend, a stalled handful does not, and a fill above the + // measured sizes never flattens the measured trend (Radeon 780M, 11-13: sizes 1 / 3 measured at 76.2 / 111.6 ms, size 4 with 6 rounds at 143) + using strata::spec::CostLearner; + const auto fill = [](CostLearner& L, int t, int n, double ms) { + for (int i = 0; i < n; ++i) L.add(0, t, ms * (1.0 + 0.004 * ((i % 5) - 2))); + }; + CostLearner R; + fill(R, 1, 1279, 76.2); fill(R, 2, 2, 97.0); fill(R, 3, 126, 111.6); fill(R, 4, 6, 143.0); + const std::vector t = R.table(0, 20); + check(t.size() == 4 && std::fabs(t[3] - 143.0) < 0.5, "sizes: 6 rounds of 4 rows (143 ms, above the line's 129) count by their median"); + check(t.size() == 4 && std::fabs(t[1] - (76.2 + 111.6) / 2.0) < 0.2, "sizes: 2 rounds of 2 rows are filled in linearly"); + const std::vector u = R.table(0, 20, 6); + bool mono = u.size() == 6; + for (size_t i = 1; i < u.size(); ++i) mono &= u[i] >= u[i - 1]; + check(u.size() == 6 && mono && u[4] >= 143.0 + 0.9 * (143.0 - 111.6) && u[5] > u[4], "sizes: 5 and 6 rows continue the steeper measured slope (32 ms a row), not the first segment's 18"); + CostLearner S; + fill(S, 1, 600, 12.5); fill(S, 2, 400, 14.2); fill(S, 3, 700, 16.2); fill(S, 4, 6, 99.0); + const std::vector s = S.table(0, 20); + check(s.size() == 4 && std::fabs(s[3] - 18.2) < 0.05, "sizes: a handful of rounds 5x above the trend (a stall) is not a measurement"); + CostLearner Q; // costs 10 / 20 / 35: the fill goes on at 15 ms a row, not at 10 + fill(Q, 1, 100, 10.0); fill(Q, 2, 100, 20.0); fill(Q, 3, 100, 35.0); + const std::vector q = Q.table(0, 20, 5); + check(q.size() == 5 && q[3] >= 35.0 + 15.0 - 0.1 && q[4] >= 35.0 + 30.0 - 0.1, "sizes: a size above the measured ones never costs less than the last slope says"); + check(Q.table(0, 20, 3).size() == 3 && Q.table(1, 20, 5).empty(), "sizes: upto adds nothing below the largest size seen, and an empty bucket stays empty"); + // the learning stretch measures the sizes it has too few rounds of + const auto feed = [](DraftPolicy& p, int n) { + for (int i = 0; i < n; ++i) { p.observe(false, 1, 0, 0, 76.0); if (i % 4 == 0) p.observe(false, 3, 2, 0, 111.0); } + }; + DraftPolicy y(8); + y.set_learning(true); + feed(y, 40); + y.choose(1, 5, 3); + check(y.forced_rounds() == 0, "explore: nothing is forced in the first rounds of a stretch"); + feed(y, 300); + const DraftPolicy::Pick f1 = y.choose(1, 5, 3); + check(f1.lookup && f1.t == 2 && y.forced_rounds() == 1, "explore: after the first rounds the smallest size with few samples is taken, if a proposal reaches it"); + const DraftPolicy::Pick f2 = y.choose(1, 1, 3); + check(y.forced_rounds() == 2 && f2.lookup && f2.t == 2, "explore: a proposal of one draft reaches 2 rows only"); + DraftPolicy y16(16); // the budget: 14 sizes that need 30 rounds each are more than the stretch's budget + y16.set_learning(true); + feed(y16, 400); + for (int i = 0; i < 1200; ++i) { + const DraftPolicy::Pick pk = y16.choose(1, 15, 3); + y16.observe(pk.lookup, pk.t, pk.t > 1 ? pk.t - 1 : 0, 3, 76.0 + 17.0 * (pk.t - 1)); + } + check(y16.forced_rounds() == DraftPolicy::kExploreBudget, "explore: the forced rounds stop at the stretch's budget"); + const int before = y16.forced_rounds(); + for (int i = 0; i < 50; ++i) y16.choose(1, 15, 3); + check(y16.forced_rounds() == before, "explore: nothing is forced once the budget is spent"); + DraftPolicy z(8); // the cap per size: with a budget left over, one size is still not forced more than kExplorePerSize times + z.set_learning(true); + feed(z, 400); + for (int i = 0; i < 200; ++i) { const DraftPolicy::Pick pk = z.choose(1, 1, 3); z.observe(pk.lookup, pk.t, 0, 3, 0.0); } // no time, so no sample ever arrives + check(z.forced_rounds() == DraftPolicy::kExplorePerSize, "explore: a size is forced at most kExplorePerSize times"); + z.reset_learning(); + check(z.forced_rounds() == 0 && z.learner().rounds() == 0, "explore: a new stretch starts with a new budget"); + DraftPolicy n(8); // not learning, or fixed: the policy never takes a window for its size's sake + feed(n, 400); + n.choose(1, 5, 3); + DraftPolicy x(8); + x.set_learning(true); + feed(x, 400); + const double ms[3] = {76.0, 95.0, 111.0}; + x.set_fixed_costs(ms, 3); + for (int i = 0; i < 20; ++i) x.choose(1, 5, 3); + check(n.forced_rounds() == 0 && x.forced_rounds() == 0, "explore: not while learning is off, and not once the costs are fixed"); + DraftPolicy w(8); // a size no proposal reaches stays filled in + w.set_learning(true); + feed(w, 600); + for (int i = 0; i < 100; ++i) { const DraftPolicy::Pick pk = w.choose(1, 1, 3); w.observe(pk.lookup, pk.t, 1, 3, 95.0); } + const std::vector wt = w.learner().table(0, 20, 6); + check(w.learner().samples(0, 4) == 0 && wt.size() == 6 && wt[3] > wt[2] && wt[5] > wt[3], "explore: a size no proposal reaches is filled in above the measured ones"); + // the window of a round that has no proposal: any undersampled size up to the cap, but not the size it already is + DraftPolicy m(8); + m.set_learning(true); + feed(m, 400); + check(m.explore_window(3, 6) == 2 && m.forced_rounds() == 1, "window: the smallest unmeasured size is run, not the one the round already has"); + check(m.explore_window(2, 6) == 4, "window: a size with samples (3 rows) is skipped, the next unmeasured one is run"); + check(m.explore_window(1, 1) == 0, "window: a cap of one row leaves nothing to run"); + DraftPolicy m0(8); + feed(m0, 400); + check(m0.explore_window(3, 6) == 0, "window: nothing while learning is off"); + DraftPolicy lk(8); // a round with no proposal at all: a lookup-type window of an unmeasured size + lk.set_learning(true); + feed(lk, 400); + check(lk.explore_lookup(5) == 2 && lk.explore_lookup(1) == 0 && m0.explore_lookup(5) == 0, "window: a round without a proposal can time a lookup-type size, only while learning"); + // a late round counts only where the stretch has shown no state effect + DraftPolicy e1(8); // fresh 76 ms, late 80 ms: a state effect + e1.set_learning(true); + e1.set_busy_age(2.0); + for (int i = 0; i < 60; ++i) e1.observe(false, 1, 0, 0, 76.0); + e1.set_busy_age(100.0); + for (int i = 0; i < 60; ++i) e1.observe(false, 1, 0, 0, 80.0); + check(e1.explore_window(3, 6) == 0, "gate: a late round is not forced when the stretch has a state effect"); + e1.set_busy_age(2.0); + check(e1.explore_window(3, 6) == 2, "gate: a fresh round is"); + DraftPolicy e2(8); // fresh and late alike: no state effect + e2.set_learning(true); + e2.set_busy_age(2.0); + for (int i = 0; i < 60; ++i) e2.observe(false, 1, 0, 0, 76.0); + e2.set_busy_age(100.0); + for (int i = 0; i < 60; ++i) e2.observe(false, 1, 0, 0, 76.2); + check(e2.explore_window(3, 6) == 2, "gate: a late round is forced when the stretch shows no state effect"); + DraftPolicy e3(8); // late rounds only so far: unknown, so not forced + e3.set_learning(true); + e3.set_busy_age(100.0); + for (int i = 0; i < 150; ++i) e3.observe(false, 1, 0, 0, 76.0); + check(e3.explore_window(3, 6) == 0, "gate: a late round is not forced while the stretch cannot tell yet"); + // a padded window: a short proposal, a size past it that has no samples, the caller allows filler rows + DraftPolicy g(8); + g.set_learning(true); + feed(g, 400); + for (int i = 0; i < 40; ++i) g.observe_forced(2, 95.0); // size 2 measured (3 is fed already) + const DraftPolicy::Pick np = g.choose(1, 1, 3); + check(g.forced_rounds() == 0 || !np.lookup || np.pad == 0, "pad: without pad_cap a proposal of one draft never makes a longer window"); + const DraftPolicy::Pick gp = g.choose(1, 1, 3, 7); + check(gp.lookup && gp.t == 4 && gp.pad == 2 && g.forced_rounds() == 1, "pad: with pad_cap the smallest unmeasured size is run, 2 filler rows past the proposal"); + const double q0 = g.lookup_rate(3); + for (int i = 0; i < 30; ++i) g.observe_forced(4, 143.0); + check(g.lookup_rate(3) == q0 && g.learner().samples(0, 4) == 30, "pad: a forced round feeds the learner and no lookup statistic"); + const DraftPolicy::Pick g5 = g.choose(1, 1, 3, 7); + check(g5.lookup && g5.t == 5 && g5.pad == 3, "pad: the next unmeasured size follows once one has its samples"); + check(g.choose(1, 1, 3, 1).pad == 0, "pad: a pad_cap of one draft makes no filler"); + } + { // DRAFT-COSTS-5: a real price is the MEDIAN of its 16 rounds; the monotone guard repairs an inversion from the trusted side + namespace fs = std::filesystem; + using strata::spec::CalAcc; + using strata::spec::CostFile; + using strata::spec::CostLearner; + using Cal = std::array, CostLearner::kCtxBuckets>; + using Rc = std::array, CostLearner::kCtxBuckets>; + using Real = std::array; + const double tab[5] = {12.68, 14.30, 16.41, 18.57, 20.90}; + const Cal cal0{}; + const Rc rc0{}; + { // one cold round among 16 (the first use of a width): the real price is the median, a mean would be moved by it + DraftPolicy m(8); + m.set_fixed_costs(tab, 5, 0); + m.start_calibration(false, Real{}, cal0, rc0); + for (int i = 0; i < 15; ++i) m.observe(false, 2, 1, 0, 14.5); + m.observe(false, 2, 1, 0, 40.0); + CostFile cf; + std::string rep; + check(m.calibrate(cf, rep) && (cf.real[0] & 2u), "median: the 16th round marks the size real"); + check(std::fabs(cf.real_cost[0][2] - 14.5) < 1e-9, "median: one cold round among 16 does not move the real price"); + } + { // eight slow rounds in the first request, eight normal ones after: the median sits between (even count: mean of the two middle rounds) + DraftPolicy m(8); + m.set_fixed_costs(tab, 5, 0); + m.start_calibration(false, Real{}, cal0, rc0); + for (int i = 0; i < 8; ++i) m.observe(false, 2, 1, 0, 15.0); + for (int i = 0; i < 8; ++i) m.observe(false, 2, 1, 0, 14.0); + CostFile cf; + std::string rep; + check(m.calibrate(cf, rep) && std::fabs(cf.real_cost[0][2] - 14.5) < 1e-9, "median: sixteen rounds of two values: the mean of the two middle ones"); + } + { // the rounds survive the file (a start collects part of them, the next start the rest) and a file line without them still loads (mean as before) + const fs::path dir = fs::temp_directory_path() / ("strata-dpt-med-" + std::to_string((unsigned long long) (uintptr_t) &tab)); + const std::string path = (dir / "m.costs").string(); + CostFile c; + c.key = "k"; + c.tables[0] = {12.68, 14.30, 16.41}; + c.cal[0][2] = CalAcc{}; + c.cal[0][2].n = 3; + c.cal[0][2].sum = 43.5; + c.cal[0][2].nv = 3; + c.cal[0][2].vals = {14.5, 14.0, 15.0}; + c.cal[0][3].n = 2; // no rounds kept (a file of an older build): only the sum + c.cal[0][3].sum = 33.0; + std::string why; + check(strata::spec::write_cost_file(path, c, why), "median file: written"); + CostFile r; + check(strata::spec::read_cost_file(path, c.key, r, why), "median file: read back"); + check(r.cal[0][2].n == 3 && r.cal[0][2].nv == 3 && std::fabs((double) r.cal[0][2].vals[1] - 14.0) < 1e-6 && std::fabs(r.cal[0][2].sum - 43.5) < 1e-3, + "median file: the kept rounds come back with their count and sum"); + check(r.cal[0][3].n == 2 && r.cal[0][3].nv == 0 && std::fabs(r.cal[0][3].sum - 33.0) < 1e-3, "median file: a line without rounds keeps only n and sum (the mean decides)"); + std::error_code ec; + fs::remove_all(dir, ec); + } + { // fixture 1: the srv118 table as taken over (a real 2-row price of 20.08 ms, the sizes above it real or unreached): the outlier is lowered, 3-6 rows keep their prices + const double t12[12] = {7.928, 20.085, 9.577, 10.524, 12.136, 13.270, 19.223, 21.293, 23.659, 26.024, 28.390, 30.756}; + Real real0{}; + real0[0] = 63u; + Cal cal1{}; + Rc rc1{}; + const double rcv[7] = {0.0, 7.9276, 20.0847, 9.5771, 10.5245, 12.1355, 13.2695}; + for (int t = 1; t <= 6; ++t) rc1[0][(size_t) t] = rcv[t]; + DraftPolicy p(12); + p.set_fixed_costs(t12, 12, 0); + p.start_calibration(false, real0, cal1, rc1, 100); + bool mono = true; + for (int t = 2; t <= 12; ++t) mono = mono && p.cost_ms(t) >= p.cost_ms(t - 1) - 1e-12; + check(mono, "guard: the used table never costs less for more rows"); + check(std::fabs(p.cost_ms(2) - 9.5771) < 1e-9 && std::fabs(p.cost_ms(3) - 9.5771) < 1e-9 && std::fabs(p.cost_ms(4) - 10.5245) < 1e-9 && std::fabs(p.cost_ms(6) - 13.2695) < 1e-9, + "guard: the 20 ms 2-row outlier is lowered to the next real price, not raised into every larger size"); + check(std::fabs(p.cost_ms(1) - 7.9276) < 1e-9, "guard: the 1-row price is untouched"); + } + { // fixture 2: the Q2_0 table at take-over: 4 rows an unreached live value above the real 5 rows + const double q[5] = {12.966, 14.482, 17.042, 21.796, 21.361}; + Real real0{}; + real0[0] = 23u; // sizes 1, 2, 3, 5 + Cal cal1{}; + Rc rc1{}; + rc1[0][1] = 12.9665; + rc1[0][2] = 14.4821; + rc1[0][3] = 17.0419; + rc1[0][5] = 21.3610; + DraftPolicy p(8); + p.set_fixed_costs(q, 5, 0); + p.start_calibration(false, real0, cal1, rc1, 100); + check(std::fabs(p.cost_ms(4) - 21.3610) < 1e-9 && std::fabs(p.cost_ms(5) - 21.3610) < 1e-9 && std::fabs(p.cost_ms(3) - 17.0419) < 1e-9, + "guard: an unreached 4 rows above the real 5 rows is lowered to it"); + } + { // fixture 3: the IQ3_S table at take-over: 4 rows 28.31 (a live value) above the real 5 rows 25.00 + const double q[5] = {14.734, 16.967, 20.096, 28.312, 25.005}; + Real real0{}; + real0[0] = 23u; + Cal cal1{}; + Rc rc1{}; + rc1[0][1] = 14.7341; + rc1[0][2] = 16.9669; + rc1[0][3] = 20.0959; + rc1[0][5] = 25.0046; + DraftPolicy p(8); + p.set_fixed_costs(q, 5, 0); + p.start_calibration(false, real0, cal1, rc1, 100); + check(std::fabs(p.cost_ms(4) - 25.0046) < 1e-9 && std::fabs(p.cost_ms(5) - 25.0046) < 1e-9 && std::fabs(p.cost_ms(2) - 16.9669) < 1e-9, + "guard: IQ3_S 4 rows 28.31 is lowered to the real 5 rows 25.00"); + } + { // a real size above an unreached next size is not lowered by the guess: the guess is lifted to it + const double q[5] = {12.0, 14.0, 20.0, 15.0, 16.0}; + Real real0{}; + real0[0] = 4u; // size 3 real at 20.0 + Cal cal1{}; + Rc rc1{}; + rc1[0][3] = 20.0; + DraftPolicy p(8); + p.set_fixed_costs(q, 5, 0); + p.start_calibration(false, real0, cal1, rc1, 100); + check(std::fabs(p.cost_ms(3) - 20.0) < 1e-9 && p.cost_ms(4) >= 20.0 - 1e-9 && p.cost_ms(5) >= p.cost_ms(4) - 1e-12 && std::fabs(p.cost_ms(2) - 14.0) < 1e-9, + "guard: a real price is kept against a guessed larger size, which is lifted to it"); + } + } + { // calibration against real rounds + using strata::spec::CalAcc; + using strata::spec::CostFile; + using strata::spec::CostLearner; + using strata::spec::read_cost_file; + using strata::spec::write_cost_file; + using Cal = std::array, CostLearner::kCtxBuckets>; + using Rc = std::array, CostLearner::kCtxBuckets>; + using Real = std::array; + const double tab[5] = {12.68, 14.30, 16.41, 18.57, 20.90}; + const Cal cal0{}; + const Rc rc0{}; + DraftPolicy c(8), live(8); // `live` has no table: a held table must decide exactly like it + c.set_fixed_costs(tab, 5, 0); + c.start_calibration(false, Real{}, cal0, rc0); + check(c.calibrating() && !c.calib_dirty() && c.table_held() && !c.fixed(), "calib: a table with uncalibrated sizes is held back: live costs, nothing collected yet"); + bool same = true; + for (int i = 0; i < 15; ++i) { + const DraftPolicy::Pick pa = c.choose(i % 3 + 1, 5, 2), pb = live.choose(i % 3 + 1, 5, 2); + same = same && pa.lookup == pb.lookup && pa.t == pb.t && std::fabs(c.cost_ms(3) - live.cost_ms(3)) < 1e-12; + c.observe(false, 3, 2, 0, 16.70); + live.observe(false, 3, 2, 0, 16.70); + } + CostFile cf; + std::string rep; + check(same && std::fabs(c.cost_ms(3) - 16.70) < 1e-9 && std::fabs(c.cost_ms(4) - live.cost_ms(4)) < 1e-12, + "calib: while held back, picks and costs equal those of a policy without a table (the live cost follows the rounds)"); + check(c.calibrate(cf, rep) && rep.empty() && cf.cal[0][3].n == 15, "calib: 15 real rounds are kept, nothing replaced"); + c.observe(false, 3, 2, 0, 16.70); + check(c.calibrate(cf, rep) && !rep.empty() && (cf.real[0] & 4u) && std::fabs(cf.real_cost[0][3] - 16.70) < 1e-9 && std::fabs(cf.tables[0][2] - 16.41) < 1e-9, + "calib: the 16th real round marks the size real; the file keeps the learned cost beside it"); + check(c.table_held() && !c.fixed() && c.calibrating(), "calib: one real size is not enough: the table stays held back"); + // the other four sizes get their 16 rounds: the table takes over at that request's end, at the real costs + const double rt[5] = {12.90, 14.60, 16.70, 19.90, 21.30}; + for (int t = 1; t <= 5; ++t) + if (t != 3) + for (int i = 0; i < 16; ++i) c.observe(t == 4 || t == 5, t, 1, 0, rt[t - 1]); + check(c.calibrate(cf, rep) && c.fixed() && !c.table_held() && !c.calibrating(), "calib: with the last size calibrated the table is used"); + check(std::fabs(c.cost_ms(1) - 12.90) < 1e-9 && std::fabs(c.cost_ms(3) - 16.70) < 1e-9 && std::fabs(c.cost_ms(4) - 19.90) < 1e-9 && std::fabs(c.cost_ms(5) - 21.30) < 1e-9, + "calib: the real costs decide"); + for (int i = 0; i < 40; ++i) c.observe(false, 3, 2, 0, 15.0); + check(!c.calib_dirty() && std::fabs(c.cost_ms(3) - 16.70) < 1e-9, "calib: a real size never changes again"); + // a lookup size reached once per request: its rounds come across starts through the file + CostFile cd; + cd.key = "k"; + Cal cal1 = cal0; + Real real1{}; + Rc rc1 = rc0; + for (int start = 0; start < 16; ++start) { + DraftPolicy e(8); + e.set_fixed_costs(tab, 5, 0); + e.start_calibration(false, real1, cal1, rc1); + e.observe(true, 4, 2, 0, 18.9); + std::string r2; + check(e.calibrate(cd, r2), "calib: a start with one real round of a size writes the file"); + cal1 = cd.cal; + real1 = cd.real; + rc1 = cd.real_cost; + } + check((cd.real[0] & 8u) != 0 && std::fabs(cd.real_cost[0][4] - 18.9) < 1e-9 && cd.cal[0][4].n == 0 && std::fabs(cd.tables[0][3] - 18.57) < 1e-9, + "calib: 16 starts of one round each calibrate the size"); + DraftPolicy again(8); // a start from that file: size 4 real, the others not: the table is held back + again.set_fixed_costs(tab, 5, 0); + again.start_calibration(false, real1, cal1, rc1); + check(again.table_held() && !again.fixed() && again.calibrating(), "calib: a restart with sizes still uncalibrated keeps the table held back"); + { // a file with every size real: the table is used from the first round, at the real costs + Real all{}; + all[0] = 31u; + Rc rcall = rc0; + for (int t = 1; t <= 5; ++t) rcall[0][(size_t) t] = tab[t - 1] * 1.03; + DraftPolicy u(8); + u.set_fixed_costs(tab, 5, 0); + u.start_calibration(false, all, cal0, rcall); + check(u.fixed() && !u.table_held() && !u.calibrating() && std::fabs(u.cost_ms(4) - 18.57 * 1.03) < 1e-9 && std::fabs(u.cost_ms(1) - 12.68 * 1.03) < 1e-9, + "calib: a start from a fully calibrated file uses the table at the real costs"); + } + { // sizes that real requests never reach: after kCalibReqs requests the table is used anyway, those sizes at a scaled learned cost + DraftPolicy bd(8); + bd.set_fixed_costs(tab, 5, 0); + bd.start_calibration(false, Real{}, cal0, rc0, 0); + CostFile cb; + std::string rb; + for (int i = 0; i < 16; ++i) bd.observe(false, 2, 1, 0, 14.60); + bd.calibrate(cb, rb); + for (int rq = 2; rq < DraftPolicy::kCalibReqs; ++rq) { + bd.observe(false, 3, 2, 0, 16.70); + bd.calibrate(cb, rb); + } + check(bd.table_held() && !bd.fixed() && cb.reqs == DraftPolicy::kCalibReqs - 1, "budget: held back before the last request of the budget"); + bd.observe(false, 3, 2, 0, 16.70); + const bool wr = bd.calibrate(cb, rb); + const double rr = (14.60 / 14.30 + 16.70 / 16.41) / 2.0; + check(wr && bd.fixed() && !bd.table_held() && cb.reqs == DraftPolicy::kCalibReqs && bd.calibrating(), "budget: after kCalibReqs requests the table is used, calibration goes on"); + check(std::fabs(bd.cost_ms(2) - 14.60) < 1e-9 && std::fabs(bd.cost_ms(3) - 16.70) < 1e-9 && std::fabs(bd.cost_ms(1) - 12.68) < 1e-9 && + std::fabs(bd.cost_ms(4) - 18.57 * rr) < 1e-6 && std::fabs(bd.cost_ms(5) - 20.90 * rr) < 1e-6, + "budget: real sizes at their real cost, sizes not reached at learned x the mean ratio, size 1 at its learned cost"); + DraftPolicy bs(8); // a start from that file: used at once + bs.set_fixed_costs(tab, 5, 0); + bs.start_calibration(false, cb.real, cb.cal, cb.real_cost, cb.reqs); + check(bs.fixed() && !bs.table_held() && std::fabs(bs.cost_ms(4) - 18.57 * rr) < 1e-6, "budget: a start after the budget uses the table at once, same prices"); + for (int i = 0; i < 16; ++i) bd.observe(true, 4, 2, 0, 19.90); // a size the policy now chooses collects its own rounds while the table is in use + check(bd.calibrate(cb, rb) && bd.fixed() && (cb.real[0] & 8u) && std::fabs(bd.cost_ms(4) - 19.90) < 1e-9 && cb.reqs == DraftPolicy::kCalibReqs, + "budget: in use, a size with its own kCalibN rounds becomes real"); + } + { // a machine with no table: built from the real rounds, no learning stretch, live costs decide until the take-over + CostFile c0; + c0.key = "k"; + c0.fresh = true; + DraftPolicy p(8), lv(8); + p.start_passive(c0, 5); + check(p.passive() && p.table_held() && !p.fixed() && p.calibrating() && !p.learning(), "passive: held from the first request, no learning"); + bool same = true; + for (int i = 0; i < 40; ++i) { + const DraftPolicy::Pick pa = p.choose(i % 3 + 1, 5, 2), pb = lv.choose(i % 3 + 1, 5, 2); + same = same && pa.lookup == pb.lookup && pa.t == pb.t && pa.pad == 0 && std::fabs(p.cost_ms(3) - lv.cost_ms(3)) < 1e-12; + p.set_busy_age(2.0); + p.observe(i % 3 == 0, i % 3 + 1, 1, 0, 12.7 + 2.0 * (i % 3)); + lv.observe(i % 3 == 0, i % 3 + 1, 1, 0, 12.7 + 2.0 * (i % 3)); + } + check(same && p.forced_rounds() == 0, "passive: picks and costs equal a policy without a table, no forced window"); + CostFile cp; + std::string rp; + check(p.calibrate(cp, rp) && cp.fresh && cp.tables[0].empty() && cp.reqs == 1, "passive: the file has no table yet, one request counted"); + // only the first seconds of a busy run are counted + DraftPolicy q(8); + q.start_passive(c0, 5); + q.set_busy_age(2.0); + for (int i = 0; i < 10; ++i) q.observe(false, 2, 1, 0, 14.6); + q.set_busy_age(50.0); + for (int i = 0; i < 10; ++i) q.observe(false, 2, 1, 0, 14.6); + CostFile cq; + q.calibrate(cq, rp); + check(cq.cal[0][2].n == 9 && cq.fresh, "passive: rounds late in a busy run are not counted; the first round of a size has no live cost to clamp to"); + // the sums survive a restart: 9 + 7 more = 16 own rounds make the size real + cq.key = "k"; + std::string wpath = "dp_passive_test.costs", wwhy; + check(write_cost_file(wpath, cq, wwhy), "passive: file written"); + CostFile cr; + check(read_cost_file(wpath, "k", cr, wwhy) && cr.fresh && cr.tables[0].empty() && cr.cal[0][2].n == 9, "passive: a file with no table reads back"); + std::remove(wpath.c_str()); + DraftPolicy r(8); + r.start_passive(cr, 5); + r.set_busy_age(1.0); + for (int i = 0; i < 8; ++i) r.observe(false, 2, 1, 0, 14.6); + CostFile cs; + check(r.calibrate(cs, rp) && (cs.real[0] & 2u) && std::fabs(cs.real_cost[0][2] - 14.6) < 1e-9 && r.passive(), "passive: the size is real after 16 own rounds across a restart"); + // take-over by every size real: the real costs, a table in the file + DraftPolicy a(8); + a.start_passive(c0, 5); + a.set_busy_age(1.0); + const double rt[5] = {12.9, 14.6, 16.7, 19.9, 21.3}; + for (int t = 1; t <= 5; ++t) + for (int i = 0; i < 17; ++i) a.observe(t >= 4, t, 1, 0, rt[t - 1]); + CostFile ca; + check(a.calibrate(ca, rp) && a.fixed() && !a.passive() && !a.table_held() && !a.calibrating() && !ca.fresh && ca.tables[0].size() == 5, "passive: every size real: the table takes over, the file has a table"); + check(std::fabs(a.cost_ms(1) - 12.9) < 1e-9 && std::fabs(a.cost_ms(4) - 19.9) < 1e-9 && std::fabs(ca.tables[0][2] - 16.7) < 1e-9, "passive: the real costs decide, the file keeps them as the table"); + // take-over after kCalibReqs requests: a size never reached takes the live cost, a never measured one the policy's prior + DraftPolicy b(8), lb(8); + b.start_passive(c0, 5); + b.set_busy_age(1.0); + for (int i = 0; i < 17; ++i) { + b.observe(false, 2, 1, 0, 14.6); + lb.observe(false, 2, 1, 0, 14.6); + } + for (int i = 0; i < 6; ++i) { + b.observe(true, 4, 2, 0, 19.9); + lb.observe(true, 4, 2, 0, 19.9); + } + CostFile cb2; + for (int rq = 0; rq < DraftPolicy::kCalibReqs; ++rq) { + b.observe(false, 2, 1, 0, 14.6); + b.calibrate(cb2, rp); + } + check(b.fixed() && !b.passive() && cb2.reqs == DraftPolicy::kCalibReqs && cb2.tables[0].size() == 5, "passive: after kCalibReqs requests the table takes over"); + check(std::fabs(cb2.tables[0][1] - 14.6) < 1e-9 && std::fabs(cb2.tables[0][3] - 19.9) < 1e-9 && std::fabs(cb2.tables[0][2] - lb.cost_ms(3)) < 0.1 && std::fabs(b.cost_ms(4) - 19.9) < 1e-9, + "passive: real size 2 at its real cost, size 4 at its live cost, size 3 (never measured) at the policy's prior"); + for (int i = 0; i < 17; ++i) b.observe(true, 4, 2, 0, 20.1); // the unreached size keeps collecting + CostFile cb3 = cb2; + check(b.calibrate(cb3, rp) && (cb3.real[0] & 8u) && std::fabs(b.cost_ms(4) - 20.1) < 1e-9, "passive: after the take-over a size still collects and becomes real at 16 own rounds (its price the median: 5 rounds of 19.9, 11 of 20.1)"); + } + // the file round trip: state, real, real cost, cal + CostFile w; + w.key = "k2"; + w.tables[0].assign(tab, tab + 5); + w.state_effect = true; + w.reqs = 7; + w.real[0] = 6u; + w.real_cost[0][2] = 14.6; + w.real_cost[0][3] = 16.7; + w.cal[0][4] = CalAcc{7, 131.0}; + const std::string path = "dp_calib_test.costs"; + std::string why; + check(write_cost_file(path, w, why), "calib file: written"); + CostFile r; + check(read_cost_file(path, "k2", r, why) && r.state_effect && r.reqs == 7 && r.real[0] == 6u && r.cal[0][4].n == 7 && std::fabs(r.cal[0][4].sum - 131.0) < 1e-3 && r.cal[0][2].n == 0 && + std::fabs(r.real_cost[0][2] - 14.6) < 1e-9 && std::fabs(r.real_cost[0][3] - 16.7) < 1e-9, + "calib file: state, real marks, real costs and collected rounds come back"); + std::remove(path.c_str()); + // a machine with a load-time effect counts only the first kFreshS seconds of a busy run + DraftPolicy f(8); + f.set_fixed_costs(tab, 5, 0); + f.start_calibration(true, Real{}, cal0, rc0); + f.set_busy_age(2.0); + for (int i = 0; i < 10; ++i) f.observe(false, 2, 1, 0, 14.6); + f.set_busy_age(50.0); + for (int i = 0; i < 10; ++i) f.observe(false, 2, 1, 0, 17.0); + CostFile cfz; + std::string rz; + f.calibrate(cfz, rz); + check(cfz.cal[0][2].n == 10, "calib: with a state effect only fresh rounds are counted"); + // a disturbed stretch (a stalled machine) is dropped, not taken + DraftPolicy g(8); + g.set_fixed_costs(tab, 5, 0); + g.start_calibration(false, Real{}, cal0, rc0); + for (int i = 0; i < 16; ++i) g.observe(false, 2, 0, 0, 40.0); + CostFile cg; + std::string rg; + g.calibrate(cg, rg); + check(rg.empty() && g.table_held() && cg.cal[0][2].n == 0 && (cg.real[0] & 2u) == 0, "calib: rounds far above the learned cost are dropped"); + // a size that real requests never reach, and a machine whose real sizes are all 1 row: nothing is scaled + DraftPolicy h(8); + h.set_fixed_costs(tab, 5, 0); + h.start_calibration(false, Real{}, cal0, rc0); + for (int i = 0; i < 16; ++i) h.observe(false, 1, 0, 0, 13.0); + CostFile ch; + std::string rh; + h.calibrate(ch, rh); + check((ch.real[0] & 1u) != 0 && h.table_held() && !h.fixed(), "calib: one real size does not bring the table into use"); + } std::printf(g_fail ? "FAIL\n" : "PASS\n"); return g_fail ? 1 : 0; }