Skip to content

Commit 7264e5b

Browse files
committed
refactor(flux2): make block slab config backend neutral
1 parent 71ce359 commit 7264e5b

2 files changed

Lines changed: 4 additions & 31 deletions

File tree

lightx2v/models/networks/flux2/model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Flux2TransformerWeights,
1515
preserve_weight_module_cpu_tensors,
1616
release_weight_module_device_tensors,
17-
validate_flux2_block_slab_config,
1817
)
1918
from lightx2v.utils.custom_compiler import compiled_method
2019
from lightx2v_platform.base import global_var
@@ -28,10 +27,10 @@ class _Flux2TransformerModelBase(BaseTransformerModel):
2827

2928
def __init__(self, config, model_path, device):
3029
super().__init__(model_path, config, device)
31-
self.use_block_slab_offload = validate_flux2_block_slab_config(
32-
self.config,
33-
global_var.AI_DEVICE,
34-
)
30+
# Block-slab packing is platform-agnostic. Enable it only on backends that support
31+
# event offload, with block-level CPU offload, BF16 Default weights, and no LoRA,
32+
# lazy loading, or tensor parallelism.
33+
self.use_block_slab_offload = self.config.get("offload_use_block_slab", False)
3534
self._offload_weights_loaded = False
3635
self._offload_weights_preparing = False
3736
self.in_channels = self.config.get("transformer_in_channels", self.config.get("in_channels", 64))

lightx2v/models/networks/flux2/weights/transformer_weights.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,6 @@
77
from lightx2v.utils.registry_factory import ATTN_WEIGHT_REGISTER, LN_WEIGHT_REGISTER, MM_WEIGHT_REGISTER, RMS_WEIGHT_REGISTER, ROPE_REGISTER
88

99

10-
def validate_flux2_block_slab_config(config, ai_device):
11-
"""Validate the deliberately narrow first rollout of block slabs."""
12-
if not config.get("offload_use_block_slab", False):
13-
return False
14-
15-
requirements = []
16-
if ai_device != "npu":
17-
requirements.append("AI_DEVICE='npu'")
18-
if not config.get("cpu_offload", False) or config.get("offload_granularity", "block") != "block":
19-
requirements.append("block-level cpu_offload")
20-
if not config.get("use_event_offload", False):
21-
requirements.append("use_event_offload=true")
22-
if config.get("dit_quantized", False) or config.get("dit_quant_scheme", "Default") != "Default":
23-
requirements.append("unquantized dit_quant_scheme='Default'")
24-
if config.get("lora_configs") or config.get("lora_dynamic_apply", False):
25-
requirements.append("LoRA disabled")
26-
if config.get("lazy_load", False):
27-
requirements.append("lazy_load=false")
28-
if config.get("tensor_parallel", False):
29-
requirements.append("tensor_parallel=false")
30-
31-
if requirements:
32-
raise ValueError("offload_use_block_slab currently requires " + ", ".join(requirements))
33-
return True
34-
35-
3610
def _resolve_resident_block_indices(value, num_blocks, policy, config_key):
3711
"""Resolve a resident-block count into deterministic block indices.
3812

0 commit comments

Comments
 (0)