SPB Git

spb/zyquo-mlx Public MIT

The local MLX foundry for your Mac — run, fine-tune, quantize, and ship models. Nothing leaves your machine.

Swift 93.4% Python 3.8% Makefile 2.2% Shell 0.5%
1.7 KB · 64 lines python
Raw Blame History
1#2#  zyquo_fuse.py3#  Zyquo MLX4#5#  Author: Simon-Pierre Boucher6#  Mail: contact@spboucher.ai7#8#  Adapter-fuse driver: fuses a LoRA adapter into its base model and saves a9#  standalone MLX model directory (mlx_lm.fuse semantics —10#  docs/TRAINING-RESEARCH.md §2.2). JSON-lines protocol on stdout.11#12#  Usage: zyquo_fuse.py --model <base> --adapter-path <dir> --save-path <dir>13#         [--dequantize]1415import argparse16import json17import sys18import time192021def emit(obj):22    sys.stdout.write(json.dumps(obj) + "\n")23    sys.stdout.flush()242526def main():27    parser = argparse.ArgumentParser()28    parser.add_argument("--model", required=True)29    parser.add_argument("--adapter-path", required=True)30    parser.add_argument("--save-path", required=True)31    parser.add_argument("--dequantize", action="store_true")32    args = parser.parse_args()3334    try:35        emit({"event": "start", "stage": "fuse", "model": args.model, "ts": time.time()})3637        # mlx_lm.fuse exposes only a CLI main(); call it with argv to stay38        # on the supported surface of the pinned version.39        from mlx_lm import fuse4041        argv = [42            "--model", args.model,43            "--adapter-path", args.adapter_path,44            "--save-path", args.save_path,45        ]46        if args.dequantize:47            argv.append("--dequantize")  # exact flag name in mlx-lm 0.31.34849        old_argv = sys.argv50        sys.argv = ["mlx_lm.fuse"] + argv51        try:52            fuse.main()53        finally:54            sys.argv = old_argv5556        emit({"event": "done", "save_path": args.save_path})57    except Exception as exc:  # noqa: BLE00158        emit({"event": "error", "message": str(exc), "type": type(exc).__name__})59        sys.exit(1)606162if __name__ == "__main__":63    main()64