Skip to content

Commit 0e3f30e

Browse files
committed
caching done
1 parent 2303706 commit 0e3f30e

2 files changed

Lines changed: 39 additions & 25 deletions

File tree

nunchaku/lora/flux/compose.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
"""
2-
Compose (merge) multiple LoRA weights into a single LoRA for Flux models.
2+
Compose multiple LoRA weights into a single LoRA for FLUX models.
33
4-
Command-line usage::
4+
This script merges several LoRA safetensors files into one, applying individual strength values to each.
55
6-
python -m nunchaku.lora.flux.compose -i lora1.safetensors lora2.safetensors -s 0.8 1 -o composed_lora.safetensors
6+
**Usage:**
77
8-
Arguments:
9-
- ``-i``, ``--input-paths``: Input LoRA safetensors files.
10-
- ``-s``, ``--strengths``: Strength for each LoRA.
11-
- ``-o``, ``--output-path``: Output safetensors file.
8+
.. code-block:: bash
129
13-
This merges ``lora1.safetensors`` (strength 0.8) and ``lora2.safetensors`` (strength 1.0) into ``composed_lora.safetensors``.
10+
python -m nunchaku.lora.flux.compose \\
11+
-i lora1.safetensors lora2.safetensors \\
12+
-s 0.8 1.0 \\
13+
-o composed_lora.safetensors
14+
15+
**Arguments:**
16+
17+
- ``-i``, ``--input-paths``: Input LoRA safetensors files (one or more).
18+
- ``-s``, ``--strengths``: Strength value for each LoRA (must match number of inputs).
19+
- ``-o``, ``--output-path``: Output path for the composed LoRA safetensors file.
20+
21+
This will merge ``lora1.safetensors`` (strength 0.8) and ``lora2.safetensors`` (strength 1.0) into ``composed_lora.safetensors``.
1422
"""
1523

1624
import argparse

nunchaku/lora/flux/convert.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
"""
2-
Command-line interface for converting LoRA weights to Nunchaku format.
2+
CLI tool to convert LoRA weights to Nunchaku format.
33
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:**
85
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``)
1421
"""
1522

1623
import argparse
@@ -24,27 +31,26 @@
2431
parser.add_argument(
2532
"--quant-path",
2633
type=str,
27-
help="path to the quantized model safetensor file",
34+
help="Path to the quantized model safetensors file.",
2835
default="mit-han-lab/svdq-int4-flux.1-dev/transformer_blocks.safetensors",
2936
)
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.")
3340
parser.add_argument(
3441
"--dtype",
3542
type=str,
3643
default="bfloat16",
3744
choices=["bfloat16", "float16"],
38-
help="data type of the converted weights",
45+
help="Data type of the converted weights.",
3946
)
4047
args = parser.parse_args()
4148

4249
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.")
4451
exit(0)
4552

4653
if not args.output_root:
47-
# output to the parent directory of the lora safetensors file
4854
args.output_root = os.path.dirname(args.lora_path)
4955
if args.lora_name is None:
5056
base_name = os.path.basename(args.lora_path)

0 commit comments

Comments
 (0)