|
1 | 1 | """ |
2 | | -Command-line interface for converting LoRA weights to Nunchaku format. |
| 2 | +CLI tool to convert LoRA weights to Nunchaku format. |
3 | 3 |
|
4 | | -This module provides a command-line interface for converting LoRA weights from |
5 | | -various formats to Nunchaku format. It handles format detection, automatic |
6 | | -naming, and provides options for specifying quantization paths and output |
7 | | -locations. |
| 4 | +**Usage:** |
8 | 5 |
|
9 | | -The script supports: |
10 | | -- Automatic format detection and conversion |
11 | | -- Flexible output path specification |
12 | | -- Support for different quantization backends (int4/fp4) |
13 | | -- Integration with the Nunchaku conversion pipeline |
| 6 | +.. code-block:: bash |
| 7 | +
|
| 8 | + python -m nunchaku.lora.flux.convert \\ |
| 9 | + --lora-path composed_lora.safetensors \\ |
| 10 | + --quant-path mit-han-lab/svdq-int4-flux.1-dev/transformer_blocks.safetensors \\ |
| 11 | + --output-root ./converted \\ |
| 12 | + --dtype bfloat16 |
| 13 | +
|
| 14 | +**Arguments:** |
| 15 | +
|
| 16 | +- ``--lora-path``: Path to the LoRA weights safetensor file (required) |
| 17 | +- ``--quant-path``: Path to the quantized model safetensor file (default: ``mit-han-lab/svdq-int4-flux.1-dev/transformer_blocks.safetensors``) |
| 18 | +- ``--output-root``: Root directory for the output safetensor file (default: parent directory of the lora file) |
| 19 | +- ``--lora-name``: Name of the LoRA weights (optional, auto-generated if not provided) |
| 20 | +- ``--dtype``: Data type of the converted weights, either ``bfloat16`` or ``float16`` (default: ``bfloat16``) |
14 | 21 | """ |
15 | 22 |
|
16 | 23 | import argparse |
|
24 | 31 | parser.add_argument( |
25 | 32 | "--quant-path", |
26 | 33 | type=str, |
27 | | - help="path to the quantized model safetensor file", |
| 34 | + help="Path to the quantized model safetensors file.", |
28 | 35 | default="mit-han-lab/svdq-int4-flux.1-dev/transformer_blocks.safetensors", |
29 | 36 | ) |
30 | | - parser.add_argument("--lora-path", type=str, required=True, help="path to LoRA weights safetensor file") |
31 | | - parser.add_argument("--output-root", type=str, default="", help="root to the output safetensor file") |
32 | | - parser.add_argument("--lora-name", type=str, default=None, help="name of the LoRA weights") |
| 37 | + parser.add_argument("--lora-path", type=str, required=True, help="Path to LoRA weights safetensors file.") |
| 38 | + parser.add_argument("--output-root", type=str, default="", help="Root directory for output safetensors file.") |
| 39 | + parser.add_argument("--lora-name", type=str, default=None, help="Name for the output LoRA weights.") |
33 | 40 | parser.add_argument( |
34 | 41 | "--dtype", |
35 | 42 | type=str, |
36 | 43 | default="bfloat16", |
37 | 44 | choices=["bfloat16", "float16"], |
38 | | - help="data type of the converted weights", |
| 45 | + help="Data type of the converted weights.", |
39 | 46 | ) |
40 | 47 | args = parser.parse_args() |
41 | 48 |
|
42 | 49 | if is_nunchaku_format(args.lora_path): |
43 | | - print("Already in nunchaku format, no conversion needed.") |
| 50 | + print("Already in Nunchaku format, no conversion needed.") |
44 | 51 | exit(0) |
45 | 52 |
|
46 | 53 | if not args.output_root: |
47 | | - # output to the parent directory of the lora safetensors file |
48 | 54 | args.output_root = os.path.dirname(args.lora_path) |
49 | 55 | if args.lora_name is None: |
50 | 56 | base_name = os.path.basename(args.lora_path) |
|
0 commit comments