from build import match_models, parse_config_name, pick_kernel, tags assert parse_config_name("E=8,N=14336,device_name=NVIDIA_H100_80GB_HBM3,dtype=fp8_w8a8,block_shape=[128, 128].json") == { "E": "8", "N": "14336", "device_name": "NVIDIA_H100_80GB_HBM3", "dtype": "fp8_w8a8", "block_shape": "[128, 128]"} shapes = {"Mixtral-8x7B-v0.1": (8, 14336), "DeepSeek-V3": (256, 2048)} assert match_models(8, 7168, shapes) == ["Mixtral-8x7B-v0.1 (TP2)"] assert match_models(32, 2048, shapes) == ["DeepSeek-V3 (EP8)"] assert match_models(8, 1000, shapes) == [] moe = "vllm/model_executor/layers/fused_moe/configs/" assert pick_kernel("vllm", moe, "int4_w4a16", None)[1] == "fused_moe_kernel_gptq_awq" assert pick_kernel("vllm", moe, "fp8_w8a8", "[128,128]")[1] == "fused_moe_kernel" gemm = "python/sglang/kernels/ops/gemm/configs/" assert pick_kernel("sglang", gemm, "int8_w8a8", "[128,128]")[1] == "_w8a8_block_int8_matmul" assert pick_kernel("sglang", gemm, "fp8_w8a8_channelwise", None) is None assert pick_kernel("vllm", "vllm/model_executor/layers/quantization/utils/configs/", "int8_w8a8", "[128,128]") is None models, hw, speed = tags("[Perf] DeepSeek-V3 MLA decode 1.8x faster on H200 / B200 (#123)") assert models == ["deepseek"] and hw == ["B200", "H200"] and speed == ["1.8x"], (models, hw, speed) assert tags("sm_100a and SM100 kernels for revision 2")[:2] == ([], ["SM100"]) from build import gain_at, same_gpu from gains import speedup assert same_gpu("H100", "NVIDIA_H100_80GB_HBM3") and same_gpu("NVIDIA H20-3e", "NVIDIA_H20-3e") assert not same_gpu("H20", "NVIDIA_H200") and not same_gpu(None, "NVIDIA_H200") assert speedup({"baseline": 10, "optimized": 5, "higher_is_better": False}) == 2.0 # latency halves assert speedup({"baseline": 800, "optimized": 1000, "higher_is_better": True}) == 1.25 # throughput up assert speedup({"baseline": None, "optimized": None, "stated_speedup": 1.3}) == 1.3 ms = [{"scope": "kernel", "batch_size": 8, "hardware": "H200", "speedup": 1.2}, {"scope": "kernel", "batch_size": 8, "hardware": "H20", "speedup": 1.5}] assert gain_at(ms, 8, "NVIDIA_H20", {}, n_files=2) == 1.5 # multi-file PR: GPU must match assert gain_at(ms, 8, "NVIDIA_H20", {}, n_files=1) is None # 1.2 vs 1.5 disagree -> ambiguous assert gain_at(ms, 16, "NVIDIA_H20", {}, n_files=1) is None shaped = [{"scope": "kernel", "batch_size": 8, "shape": "N=7168,K=2048", "speedup": 1.1}, {"scope": "kernel", "batch_size": 8, "shape": "N=4096,K=2048", "speedup": 2.0}] assert gain_at(shaped, 8, "NVIDIA_H20", {"N": "7168", "K": "2048"}, n_files=1) == 1.1 # shape disambiguates from gains import CHUNK, chunks table = "| M | before | after |\n|---|---|---|\n" + "\n".join(f"| {i} | 10 | 5 |" for i in range(1000)) parts = chunks("intro\n\n" + table) assert len(parts) > 1 and all(len(p) <= CHUNK + 200 for p in parts) assert all("| M | before | after |" in p for p in parts[1:]) # header repeated on every table piece assert sum(p.count("| 10 | 5 |") for p in parts) == 1000 # no rows lost or duplicated assert chunks("short body") == ["short body\n\n"] from build import file_license, permissive assert file_license("// SPDX-License-Identifier: Apache-2.0\nint x;") == "Apache-2.0" assert file_license("/* SPDX-License-Identifier: BSD-3-Clause */") == "BSD-3-Clause" assert file_license("int x; // no header") == "Apache-2.0" assert not permissive(file_license("// SPDX-License-Identifier: NVIDIA TensorRT Source Code License Agreement")) assert not permissive(file_license("NVIDIA CORPORATION and its licensors retain all intellectual property and proprietary rights")) from reward import patch_reward before, after = "a\nb = slow(x)\nc\n", "a\nb = fast(x)\nc\n" ok = "<<<<<<< SEARCH\nb = slow(x)\n=======\nb = fast(x)\n>>>>>>> REPLACE" assert patch_reward(ok, before, after) == 1.0 assert patch_reward(ok.replace("slow", "missing"), before, after) == -1.0 # SEARCH not in file assert patch_reward("just rewrite it", before, after) == -1.0 assert 0 <= patch_reward(ok.replace("fast(x)", "faster(y)"), before, after) < 1 assert tags("[ROCm][Perf] paged MXFP4 indexer (#60834)")[1] == ["ROCM"] print("ok")