Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

int8 LoRA: skip unsupported patches one by one and count them by category

Bowen Xuef4ac944221bc
diff --git a/freevideo_engine/lora_cache.py b/freevideo_engine/lora_cache.py
index 93d7e52..4434a42 100644
--- a/freevideo_engine/lora_cache.py
+++ b/freevideo_engine/lora_cache.py
@@ -32,6 +32,10 @@ from . import disk_space
MODULATION = re.compile(r'transformer_blocks\.\d+\.adaln_proj\.')
+INT8_UNMERGEABLE = ('This LoRA changes parts of the model that the int8 version cannot merge yet, '
+ 'so it cannot be used for now. LoRAs that change only linear layers work.')
+
+
def index_adapter(row, targets, skipped=None):
pairs = {}
full = []
@@ -76,8 +80,8 @@ def index_adapter(row, targets, skipped=None):
for target, split, swap in _targets(name):
if target not in targets and '.attn.' in target:
target = target.replace('.attn.', '.attn.orig.', 1)
- if skipped is not None and target not in targets and MODULATION.match(target):
- skipped.append(target)
+ if skipped is not None and target not in targets:
+ skipped.append(('modulation' if MODULATION.match(target) else 'other_layer', target))
continue
expected = targets.get(target)
rows = bshape[0] if split is None else bshape[0] // 3
@@ -92,6 +96,15 @@ def index_adapter(row, targets, skipped=None):
target += '#bias' if bias else ''
if target not in targets and '.attn.' in target:
target = target.replace('.attn.', '.attn.orig.', 1)
+ if skipped is not None:
+ # Quantized weights cannot take a full difference, and the int8 package
+ # keeps no bias or non-linear patch path yet: count each one, apply the rest.
+ if target.endswith('#bias'):
+ skipped.append(('bias', target))
+ else:
+ skipped.append(('quantized_diff' if target in targets or
+ target.replace('.attn.', '.attn.orig.', 1) in targets else 'other_layer', target))
+ continue
expected = targets.get(target)
actual = list(shape)
if split is not None:
@@ -163,8 +176,7 @@ def prepare(cache, adapters, output_root=None):
manifest_path = cache / 'manifest.json'
manifest = json.loads(manifest_path.read_text(encoding='utf-8'))
if manifest.get('precision') == 'int8':
- raise ValueError('This LoRA changes parts of the model that the int8 version cannot merge yet, '
- 'so it cannot be used for now. LoRAs that change only linear layers work.')
+ raise ValueError(INT8_UNMERGEABLE)
if manifest.get('precision') != 'fp8':
raise ValueError('LoRA variants require the prepared FP8 model')
from .adaln_assets import SLIM_FORMATS, restore_projections
diff --git a/freevideo_engine/lora_online_cache.py b/freevideo_engine/lora_online_cache.py
index 2126994..879ed47 100644
--- a/freevideo_engine/lora_online_cache.py
+++ b/freevideo_engine/lora_online_cache.py
@@ -1,4 +1,5 @@
"""Prepare small, streamable adapter factors beside unchanged FP8 weights."""
+from collections import Counter
import hashlib
import json
import os
@@ -9,7 +10,7 @@ import time
import torch
from safetensors.torch import save_file
-from .lora_cache import MODULATION, _targets, index_adapter, prepare as prepare_fused
+from .lora_cache import INT8_UNMERGEABLE, MODULATION, _targets, index_adapter, prepare as prepare_fused
from .media_request import digest, verify_files
from .monitoring import save
from .storage import fingerprint
@@ -45,10 +46,11 @@ def prepare(cache, adapters, output_root=None):
precision = manifest.get('precision')
# Low-rank branches run beside the base projection, so they need no change
# to FP8 or ConvRot int8 weights.
- # The int8 package cannot merge AdaLN projections, so those adapters alone
- # are skipped and counted in the report; every other patch still applies.
+ # The int8 package cannot merge AdaLN projections, full differences, biases or
+ # layers outside its linear projections, so those patches alone are skipped and
+ # counted by category in the report; every low-rank linear patch still applies.
skip_modulation = precision == 'int8'
- if precision not in ('fp8', 'int8') or not _supported(adapters, manifest.get('linears', {}), skip_modulation):
+ if precision not in ('fp8', 'int8') or (not skip_modulation and not _supported(adapters, manifest.get('linears', {}), False)):
# Full-difference, bias and modulation patches retain the existing
# exact preparation path. Never silently omit an unsupported patch.
path, report = prepare_fused(cache, adapters, output_root)
@@ -84,6 +86,8 @@ def prepare(cache, adapters, output_root=None):
for patch in index_adapter(adapter, targets, skipped if skip_modulation else None):
block = (patch['target'].split('.')[1] if patch['target'].startswith('transformer_blocks.') else 'root')
groups.setdefault(block, []).append(patch)
+ if skip_modulation and not groups:
+ raise ValueError(INT8_UNMERGEABLE)
output.mkdir(parents=True, exist_ok=True)
started = time.perf_counter()
records, specs, block_bytes = [], {}, {}
@@ -139,7 +143,8 @@ def prepare(cache, adapters, output_root=None):
verify_files({'loras': adapters})
root_bytes = block_bytes.get('root', 0)
summary = dict(targets=sum(len(spec['modules']) for spec in specs.values()),
- adapter_count=len(adapters), skipped_modulation=len(skipped), factor_bytes=sum(block_bytes.values()),
+ adapter_count=len(adapters), skipped_modulation=sum(1 for c, _ in skipped if c == 'modulation'),
+ skipped=dict(sorted(Counter(c for c, _ in skipped).items())), factor_bytes=sum(block_bytes.values()),
root_bytes=root_bytes,
max_block_bytes=max((v for k, v in block_bytes.items() if k != 'root'), default=0))
online = dict(version=1, blocks=specs, block_bytes=block_bytes, summary=summary)