"""Apply HyperQwen's two asymmetric INT4/INT8 Marlin guards idempotently. Reference: https://github.com/syv-ai/HyperQwen/blob/main/patches/marlin-int8-asym-zp.patch Backups and before/after hashes are recorded. No kernels are replaced. """ import importlib.util import shutil from common import RUN, write_json, sha256 from pathlib import Path def main(): root = Path(importlib.util.find_spec("vllm").origin).parent changes = [ ("model_executor/kernels/linear/mixed_precision/marlin.py", 'assert c.weight_type == scalar_types.uint4b8, (\n "W8A8 is not supported', 'assert c.weight_type in (scalar_types.uint4b8, scalar_types.uint4), (\n "W8A8 is not supported'), ("model_executor/layers/quantization/utils/marlin_utils.py", 'assert wtype == scalar_types.uint4b8, (\n "W8A8-INT8 is not supported', 'assert wtype in (scalar_types.uint4b8, scalar_types.uint4), (\n "W8A8-INT8 is not supported')] plan = [] for relative, old, new in changes: path = root / relative text = path.read_text() assert text.count(old) == 1 or text.count(new) == 1, f"Unexpected installed code: {path}" plan.append((path, old, new, text)) report = [] for path, old, new, text in plan: before = sha256(path) backup = path.with_name(path.name + ".swift15-before") if old in text: assert not backup.exists(), f"Backup exists but patch is absent: {backup}" shutil.copy2(path, backup) path.write_text(text.replace(old, new)) report.append({"path": str(path), "before": before, "after": sha256(path), "backup": str(backup)}) write_json(RUN / "runtime-compatibility.json", report) print("Asymmetric INT4 + INT8-activation guards installed") if __name__ == "__main__": main()