ethanfel commited on
Commit
7a77706
·
verified ·
1 Parent(s): 5817507

Add reverse Ref2VA-to-FL2VA experimental LoRAs

Browse files

Add rank 256, 512, and 1024 exact sign-inverted reverse-direction LoRAs, per-layer reports, inversion utility, updated checksums, NOTICE, and bidirectional usage documentation.

NOTICE CHANGED
@@ -1,5 +1,4 @@
1
  MiniMax H3 is licensed under the MiniMax H3 Community License Agreement, Copyright © 2026 MiniMax. All Rights Reserved.
2
 
3
  Modification notice:
4
- These experimental files were produced by mechanically extracting randomized-SVD approximations of the difference between the pruned BF16 FL2VA and Ref2VA MiniMax-H3 checkpoints. They are modified model-derivative files, not official MiniMax or Comfy Org releases.
5
-
 
1
  MiniMax H3 is licensed under the MiniMax H3 Community License Agreement, Copyright © 2026 MiniMax. All Rights Reserved.
2
 
3
  Modification notice:
4
+ These experimental files were produced by mechanically extracting randomized-SVD approximations of the difference between the pruned BF16 FL2VA and Ref2VA MiniMax-H3 checkpoints, plus exact sign-inverted opposite-direction forms. They are modified model-derivative files, not official MiniMax or Comfy Org releases.
 
README.md CHANGED
@@ -14,22 +14,28 @@ tags:
14
  - experimental
15
  ---
16
 
17
- # MiniMax-H3 pruned FL2VA → Ref2VA delta LoRAs
18
 
19
  > [!WARNING]
20
  > **Highly experimental, mechanically extracted adapters.** These are randomized-SVD approximations of the weight difference between the official pruned BF16 Ref2VA and FL2VA checkpoints. They were not trained as LoRAs and have not been generation-tested. Only safetensors integrity and structural loading with ComfyUI's current LoRA parser were validated. Expect artifacts, capability loss, or unpredictable behavior.
21
 
22
- These model-only ComfyUI LoRAs explore whether some Ref2VA behavior can be transferred to the pruned FL2VA model by approximating:
23
 
24
  ```text
25
  delta = pruned Ref2VA BF16 - pruned FL2VA BF16
26
  ```
27
 
28
- At strength `1.0`, applying an adapter to the matching pruned FL2VA BF16 checkpoint moves the model toward a rank-limited approximation of pruned Ref2VA. Lower strengths interpolate only in the extracted weight direction; they do not isolate a clean semantic capability.
29
 
30
- ## Required base
 
 
 
 
31
 
32
- Use only:
 
 
33
 
34
  ```text
35
  Comfy-Org/MiniMax-H3
@@ -42,7 +48,7 @@ Base SHA-256:
42
  a32572fb90b5508b201ec7c2eddcc184b13ddfd3c6f6d2cf06a0b46535d541b4
43
  ```
44
 
45
- The adapters were extracted against this target:
46
 
47
  ```text
48
  diffusion_models/minimax_h3_ref2va_pruned_bf16.safetensors
@@ -53,11 +59,14 @@ Do not expect correct results with the full-size BF16, FP8, or INT8 checkpoints.
53
 
54
  ## Files
55
 
56
- | File | Size | Weighted matrix-delta energy capture |
57
- |---|---:|---:|
58
- | `minimax_h3_ref2va_from_fl2va_pruned_rank256_bf16_lora.safetensors` | 2.589 GB | 99.1260% |
59
- | `minimax_h3_ref2va_from_fl2va_pruned_rank512_bf16_lora.safetensors` | 5.075 GB | 99.2417% |
60
- | `minimax_h3_ref2va_from_fl2va_pruned_rank1024_bf16_lora.safetensors` | 10.048 GB | 99.4311% |
 
 
 
61
 
62
  The weighted percentage is dominated by high-energy tensors whose effective rank is naturally small. Many large attention and MLP deltas retain substantially less energy, so this statistic is **not** a quality score. Compare generations with identical prompts, inputs, seeds, and sampler settings.
63
 
@@ -66,12 +75,12 @@ Each `.safetensors.json` file contains the complete per-layer extraction report.
66
  ## ComfyUI use
67
 
68
  1. Put one `.safetensors` file in `ComfyUI/models/loras/`.
69
- 2. Load `minimax_h3_fl2va_pruned_bf16.safetensors` as the diffusion model.
70
  3. Apply the adapter with a model-only LoRA loader.
71
  4. Start at model strength `1.0`; compare `0.25`, `0.5`, `0.75`, and `1.0` using identical inputs.
72
- 5. Do not stack the three ranks together. They are alternative approximations of the same delta.
73
 
74
- All three files loaded as 531 expected ComfyUI patches: 264 matrix adapters and 267 exact vector/bias diff patches. `rope.inv_freq` was identical between the source checkpoints and was omitted.
75
 
76
  ## Extraction details
77
 
@@ -83,8 +92,9 @@ All three files loaded as 531 expected ComfyUI patches: 264 matrix adapters and
83
  - Vector and bias patches: FP32 ComfyUI `.diff` / `.diff_b`
84
  - Source tensors: 532 matching tensors
85
  - Peak extractor CUDA allocation: approximately 1.24 GB
 
86
 
87
- The included `extract_minimax_h3_ref2va_lora.py` performs checkpointed, one-tensor-at-a-time extraction. It avoids loading both 40 GB checkpoints into memory simultaneously.
88
 
89
  ## License and territorial restrictions
90
 
@@ -99,4 +109,3 @@ This repository does not grant additional rights or remove any upstream restrict
99
  - Generation-tested: **no**
100
  - Structurally parsed by ComfyUI: **yes**
101
  - Affiliated with or endorsed by MiniMax or Comfy Org: **no**
102
-
 
14
  - experimental
15
  ---
16
 
17
+ # MiniMax-H3 pruned FL2VA ↔ Ref2VA delta LoRAs
18
 
19
  > [!WARNING]
20
  > **Highly experimental, mechanically extracted adapters.** These are randomized-SVD approximations of the weight difference between the official pruned BF16 Ref2VA and FL2VA checkpoints. They were not trained as LoRAs and have not been generation-tested. Only safetensors integrity and structural loading with ComfyUI's current LoRA parser were validated. Expect artifacts, capability loss, or unpredictable behavior.
21
 
22
+ These model-only ComfyUI LoRAs explore transferring behavior in either direction between the pruned FL2VA and Ref2VA models. The forward files approximate:
23
 
24
  ```text
25
  delta = pruned Ref2VA BF16 - pruned FL2VA BF16
26
  ```
27
 
28
+ The reverse files are exact sign-inverted forms of those approximations:
29
 
30
+ ```text
31
+ reverse delta = pruned FL2VA BF16 - pruned Ref2VA BF16
32
+ ```
33
+
34
+ At strength `1.0`, applying an adapter to its matching base moves the model toward a rank-limited approximation of the other variant. Lower strengths interpolate only in the extracted weight direction; they do not isolate a clean semantic capability.
35
 
36
+ ## Required checkpoints and directions
37
+
38
+ For files named `ref2va_from_fl2va`, use this base:
39
 
40
  ```text
41
  Comfy-Org/MiniMax-H3
 
48
  a32572fb90b5508b201ec7c2eddcc184b13ddfd3c6f6d2cf06a0b46535d541b4
49
  ```
50
 
51
+ For files named `fl2va_from_ref2va`, use this base:
52
 
53
  ```text
54
  diffusion_models/minimax_h3_ref2va_pruned_bf16.safetensors
 
59
 
60
  ## Files
61
 
62
+ | Direction | File | Size | Weighted matrix-delta energy capture |
63
+ |---|---|---:|---:|
64
+ | FL2VA → Ref2VA | `minimax_h3_ref2va_from_fl2va_pruned_rank256_bf16_lora.safetensors` | 2.589 GB | 99.1260% |
65
+ | FL2VA → Ref2VA | `minimax_h3_ref2va_from_fl2va_pruned_rank512_bf16_lora.safetensors` | 5.075 GB | 99.2417% |
66
+ | FL2VA → Ref2VA | `minimax_h3_ref2va_from_fl2va_pruned_rank1024_bf16_lora.safetensors` | 10.048 GB | 99.4311% |
67
+ | Ref2VA → FL2VA | `minimax_h3_fl2va_from_ref2va_pruned_rank256_bf16_lora.safetensors` | 2.589 GB | 99.1260% |
68
+ | Ref2VA → FL2VA | `minimax_h3_fl2va_from_ref2va_pruned_rank512_bf16_lora.safetensors` | 5.075 GB | 99.2417% |
69
+ | Ref2VA → FL2VA | `minimax_h3_fl2va_from_ref2va_pruned_rank1024_bf16_lora.safetensors` | 10.048 GB | 99.4311% |
70
 
71
  The weighted percentage is dominated by high-energy tensors whose effective rank is naturally small. Many large attention and MLP deltas retain substantially less energy, so this statistic is **not** a quality score. Compare generations with identical prompts, inputs, seeds, and sampler settings.
72
 
 
75
  ## ComfyUI use
76
 
77
  1. Put one `.safetensors` file in `ComfyUI/models/loras/`.
78
+ 2. Load pruned FL2VA for a `ref2va_from_fl2va` file, or pruned Ref2VA for a `fl2va_from_ref2va` file.
79
  3. Apply the adapter with a model-only LoRA loader.
80
  4. Start at model strength `1.0`; compare `0.25`, `0.5`, `0.75`, and `1.0` using identical inputs.
81
+ 5. Do not stack ranks or opposing directions together. They are alternative forms of the same underlying delta.
82
 
83
+ All six files loaded as 531 expected ComfyUI patches each: 264 matrix adapters and 267 exact vector/bias diff patches. `rope.inv_freq` was identical between the source checkpoints and was omitted.
84
 
85
  ## Extraction details
86
 
 
92
  - Vector and bias patches: FP32 ComfyUI `.diff` / `.diff_b`
93
  - Source tensors: 532 matching tensors
94
  - Peak extractor CUDA allocation: approximately 1.24 GB
95
+ - Reverse-direction construction: exact sign inversion of one LoRA factor and every `.diff` / `.diff_b` tensor
96
 
97
+ The included `extract_minimax_h3_ref2va_lora.py` performs checkpointed, one-tensor-at-a-time extraction. It avoids loading both 40 GB checkpoints into memory simultaneously. `invert_comfy_lora_direction.py` creates the opposite direction without repeating or degrading the SVD.
98
 
99
  ## License and territorial restrictions
100
 
 
109
  - Generation-tested: **no**
110
  - Structurally parsed by ComfyUI: **yes**
111
  - Affiliated with or endorsed by MiniMax or Comfy Org: **no**
 
SHA256SUMS CHANGED
@@ -1,3 +1,6 @@
1
  f8f15be3728fe52159b2dd840f6c8d7057f99b93690ba5bb129d827757cf13f4 minimax_h3_ref2va_from_fl2va_pruned_rank256_bf16_lora.safetensors
2
  f7e7fac7e5d29622705f92e1a1cd359db0c54c3364344fdecfc82d8d32b7d512 minimax_h3_ref2va_from_fl2va_pruned_rank512_bf16_lora.safetensors
3
  b97515fd5e654a3b37c4f499404f73340cb46e93bb626a575cd8626fd889fad0 minimax_h3_ref2va_from_fl2va_pruned_rank1024_bf16_lora.safetensors
 
 
 
 
1
  f8f15be3728fe52159b2dd840f6c8d7057f99b93690ba5bb129d827757cf13f4 minimax_h3_ref2va_from_fl2va_pruned_rank256_bf16_lora.safetensors
2
  f7e7fac7e5d29622705f92e1a1cd359db0c54c3364344fdecfc82d8d32b7d512 minimax_h3_ref2va_from_fl2va_pruned_rank512_bf16_lora.safetensors
3
  b97515fd5e654a3b37c4f499404f73340cb46e93bb626a575cd8626fd889fad0 minimax_h3_ref2va_from_fl2va_pruned_rank1024_bf16_lora.safetensors
4
+ cd4001221599e88f1fa06b2e0cddbc69d61e14765f9b0a994369663f9fc86167 minimax_h3_fl2va_from_ref2va_pruned_rank256_bf16_lora.safetensors
5
+ b7cad943cea4fee3d4614c092f78b370fd3d9cc876f7a5c6f6d254c1aed8b122 minimax_h3_fl2va_from_ref2va_pruned_rank512_bf16_lora.safetensors
6
+ 8c90b63df76e1819870c8b6809b08eb2bf8cf80348e59e3117d69e322a481d68 minimax_h3_fl2va_from_ref2va_pruned_rank1024_bf16_lora.safetensors
invert_comfy_lora_direction.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Create the exact opposite direction of an extracted ComfyUI LoRA.
3
+
4
+ For a normal LoRA patch, negating either the up or down factor negates the
5
+ represented matrix delta. ComfyUI ``.diff`` and ``.diff_b`` tensors are
6
+ negated directly. Alpha and the other LoRA factor remain unchanged.
7
+
8
+ The conversion streams one tensor at a time and writes resumable safetensors
9
+ parts, so even very large LoRAs require little memory.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import argparse
15
+ import hashlib
16
+ import json
17
+ import os
18
+ import shutil
19
+ from pathlib import Path
20
+ from typing import Any
21
+
22
+ import torch
23
+ from safetensors import safe_open
24
+ from safetensors.torch import save_file
25
+
26
+ from extract_minimax_h3_ref2va_lora import merge_parts, write_json_atomic
27
+
28
+
29
+ def parse_args() -> argparse.Namespace:
30
+ parser = argparse.ArgumentParser(
31
+ description="Invert an extracted ComfyUI LoRA without recomputing its SVD."
32
+ )
33
+ parser.add_argument("--input", type=Path, required=True)
34
+ parser.add_argument("--output", type=Path, required=True)
35
+ parser.add_argument("--keep-parts", action="store_true")
36
+ parser.add_argument("--quiet", action="store_true")
37
+ return parser.parse_args()
38
+
39
+
40
+ def should_negate(key: str) -> bool:
41
+ return (
42
+ key.endswith(".lora_up.weight")
43
+ or key.endswith(".diff")
44
+ or key.endswith(".diff_b")
45
+ )
46
+
47
+
48
+ def part_path(parts_dir: Path, index: int, key: str) -> Path:
49
+ digest = hashlib.sha1(key.encode("utf-8")).hexdigest()[:12]
50
+ return parts_dir / f"{index:04d}-{digest}.safetensors"
51
+
52
+
53
+ def reverse_metadata(metadata: dict[str, str], input_path: Path) -> dict[str, str]:
54
+ output = dict(metadata)
55
+ source_base = output.get("source_base")
56
+ source_target = output.get("source_target")
57
+ if source_base is not None and source_target is not None:
58
+ output["source_base"] = source_target
59
+ output["source_target"] = source_base
60
+ output["modelspec.title"] = "MiniMax-H3 REF2VA to FL2VA extracted LoRA"
61
+ output["modelspec.description"] = (
62
+ "Opposite-direction form of an extracted FL2VA-to-REF2VA LoRA; "
63
+ "one factor and all exact ComfyUI diff patches are sign-inverted."
64
+ )
65
+ output["direction"] = "ref2va_to_fl2va"
66
+ output["inverted_from"] = input_path.name
67
+ return output
68
+
69
+
70
+ def reverse_report(input_path: Path, output_path: Path, summary: dict[str, Any]) -> None:
71
+ input_report = input_path.with_suffix(input_path.suffix + ".json")
72
+ output_report = output_path.with_suffix(output_path.suffix + ".json")
73
+ if input_report.is_file():
74
+ report = json.loads(input_report.read_text())
75
+ report_summary = report.setdefault("summary", {})
76
+ report_summary.update(summary)
77
+ write_json_atomic(output_report, report)
78
+ else:
79
+ write_json_atomic(output_report, {"summary": summary})
80
+
81
+
82
+ def run(args: argparse.Namespace) -> None:
83
+ if not args.input.is_file():
84
+ raise FileNotFoundError(args.input)
85
+ if args.output.exists():
86
+ raise FileExistsError(f"Refusing to overwrite {args.output}")
87
+
88
+ parts_dir = Path(f"{args.output}.parts")
89
+ parts_dir.mkdir(parents=True, exist_ok=True)
90
+ progress_path = parts_dir / "progress.json"
91
+ progress: dict[str, Any] = {
92
+ "input": str(args.input.resolve()),
93
+ "completed": {},
94
+ }
95
+ if progress_path.exists():
96
+ progress = json.loads(progress_path.read_text())
97
+ if progress.get("input") != str(args.input.resolve()):
98
+ raise ValueError("Existing parts belong to a different input file")
99
+ completed: dict[str, Any] = progress.setdefault("completed", {})
100
+
101
+ with safe_open(args.input, framework="pt", device="cpu") as source:
102
+ keys = list(source.keys())
103
+ metadata = source.metadata() or {}
104
+ negated_count = 0
105
+ copied_count = 0
106
+
107
+ for index, key in enumerate(keys):
108
+ output_part = part_path(parts_dir, index, key)
109
+ negate = should_negate(key)
110
+ previous = completed.get(key)
111
+ if previous is not None and output_part.is_file():
112
+ if previous["negated"]:
113
+ negated_count += 1
114
+ else:
115
+ copied_count += 1
116
+ if not args.quiet:
117
+ print(f"[{index + 1:04d}/{len(keys)}] resume {key}", flush=True)
118
+ continue
119
+
120
+ tensor = source.get_tensor(key)
121
+ output_tensor = (-tensor).contiguous() if negate else tensor.contiguous()
122
+ temporary = output_part.with_name(f".{output_part.name}.tmp")
123
+ temporary.unlink(missing_ok=True)
124
+ save_file({key: output_tensor}, str(temporary))
125
+ os.replace(temporary, output_part)
126
+ completed[key] = {
127
+ "negated": negate,
128
+ "shape": list(tensor.shape),
129
+ "dtype": str(tensor.dtype),
130
+ "part": output_part.name,
131
+ }
132
+ write_json_atomic(progress_path, progress)
133
+ if negate:
134
+ negated_count += 1
135
+ action = "negate"
136
+ else:
137
+ copied_count += 1
138
+ action = "copy"
139
+ if not args.quiet:
140
+ print(f"[{index + 1:04d}/{len(keys)}] {action} {key}", flush=True)
141
+
142
+ parts = sorted(parts_dir.glob("[0-9][0-9][0-9][0-9]-*.safetensors"))
143
+ output_metadata = reverse_metadata(metadata, args.input)
144
+ tensor_count = merge_parts(parts, args.output, output_metadata)
145
+ if tensor_count != len(keys):
146
+ raise ValueError(f"Final tensor count mismatch: {tensor_count} != {len(keys)}")
147
+
148
+ with safe_open(args.output, framework="pt", device="cpu") as final:
149
+ if list(final.keys()) != keys:
150
+ raise ValueError("Final key order/content differs from the input")
151
+
152
+ summary = {
153
+ "direction": "ref2va_to_fl2va",
154
+ "inverted_from": args.input.name,
155
+ "output_file": args.output.name,
156
+ "output_tensors": tensor_count,
157
+ "negated_tensors": negated_count,
158
+ "copied_tensors": copied_count,
159
+ "output_bytes": args.output.stat().st_size,
160
+ }
161
+ reverse_report(args.input, args.output, summary)
162
+ print(json.dumps(summary, indent=2), flush=True)
163
+
164
+ if not args.keep_parts:
165
+ for part in parts:
166
+ part.unlink()
167
+ progress_path.unlink(missing_ok=True)
168
+ shutil.rmtree(parts_dir)
169
+
170
+
171
+ def main() -> None:
172
+ run(parse_args())
173
+
174
+
175
+ if __name__ == "__main__":
176
+ main()
minimax_h3_fl2va_from_ref2va_pruned_rank1024_bf16_lora.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8c90b63df76e1819870c8b6809b08eb2bf8cf80348e59e3117d69e322a481d68
3
+ size 10047563968
minimax_h3_fl2va_from_ref2va_pruned_rank1024_bf16_lora.safetensors.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97009c54e939ff7576cf1c65ede03421eb6035c079d471899543847dc0d127c1
3
+ size 216945
minimax_h3_fl2va_from_ref2va_pruned_rank256_bf16_lora.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd4001221599e88f1fa06b2e0cddbc69d61e14765f9b0a994369663f9fc86167
3
+ size 2588648560
minimax_h3_fl2va_from_ref2va_pruned_rank256_bf16_lora.safetensors.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9cc0dccd043471612a5db6f333027e38666ae6b1d57ef07a9ca838c5f3ab6ed
3
+ size 217055
minimax_h3_fl2va_from_ref2va_pruned_rank512_bf16_lora.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7cad943cea4fee3d4614c092f78b370fd3d9cc876f7a5c6f6d254c1aed8b122
3
+ size 5074953760
minimax_h3_fl2va_from_ref2va_pruned_rank512_bf16_lora.safetensors.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05f96c313abfa9e301844dc3ead2b2b7b635c32775d775f366ba27dcf95630ea
3
+ size 216928
minimax_h3_ref2va_from_fl2va_pruned_rank1024_bf16_lora.safetensors.json CHANGED
The diff for this file is too large to render. See raw diff
 
minimax_h3_ref2va_from_fl2va_pruned_rank256_bf16_lora.safetensors.json CHANGED
The diff for this file is too large to render. See raw diff
 
minimax_h3_ref2va_from_fl2va_pruned_rank512_bf16_lora.safetensors.json CHANGED
The diff for this file is too large to render. See raw diff