Elffuss BraidHub

kikocis/mlx-vlm public

main · 1.9 KiBRawPermalink
1# Copyright © 2023-2024 Apple Inc.
2
3import argparse
4
5from .utils import convert
6
7
8def configure_parser() -> argparse.ArgumentParser:
9 """
10 Configures and returns the argument parser for the script.
11
12 Returns:
13 argparse.ArgumentParser: Configured argument parser.
14 """
15 parser = argparse.ArgumentParser(
16 description="Convert Hugging Face model to MLX format"
17 )
18
19 parser.add_argument("--hf-path", type=str, help="Path to the Hugging Face model.")
20 parser.add_argument(
21 "--mlx-path", type=str, default="mlx_model", help="Path to save the MLX model."
22 )
23 parser.add_argument(
24 "-q", "--quantize", help="Generate a quantized model.", action="store_true"
25 )
26 parser.add_argument(
27 "--q-group-size", help="Group size for quantization.", type=int, default=64
28 )
29 parser.add_argument(
30 "--q-bits", help="Bits per weight for quantization.", type=int, default=4
31 )
32 parser.add_argument(
33 "--dtype",
34 help="Type to save the parameters, ignored if -q is given.",
35 type=str,
36 choices=["float16", "bfloat16", "float32"],
37 default="float16",
38 )
39 parser.add_argument(
40 "--upload-repo",
41 help="The Hugging Face repo to upload the model to.",
42 type=str,
43 default=None,
44 )
45 parser.add_argument(
46 "-d",
47 "--dequantize",
48 help="Dequantize a quantized model.",
49 action="store_true",
50 default=False,
51 )
52 parser.add_argument(
53 "--skip-vision",
54 help="Skip vision quantization.",
55 action="store_true",
56 default=False,
57 )
58 parser.add_argument(
59 "--skip-vision-non-divisible",
60 help="Skip layers that are not divisible by 64 in vision encoder.",
61 action="store_true",
62 default=False,
63 )
64 return parser
65
66
67def main():
68 parser = configure_parser()
69 args = parser.parse_args()
70 convert(**vars(args))
71
72
73if __name__ == "__main__":
74 main()