load_file() is mmap-based; a cache file with a readable header but damaged
data region crashes the whole process with a Windows fatal 'page error'
(uncatchable). Read the file as plain bytes and parse with safetensors.torch.load
so the same damage surfaces as OSError -> existing except returns {} -> caller
falls back to re-fuse. Verified: broken cache returns empty dict (no crash),
good cache still loads fully.
Mirrors the AMD compatibility approach from ComfyUI-NunchakuFluxLoraStacker
(PR #6 + follow-up): probe nunchaku availability, gate registration of all
nunchaku-dependent nodes (QwenImage/Z-ImageTurbo LoRA), and guard runtime
nunchaku imports so they raise a clear RuntimeError instead of ImportError.
The nunchaku-independent Krea2 ControlNet LoRA loader and the ControlNet node
stay registered on every platform.
Post-merge additional fixes for PR #52 (per md/PR52_MERGE_PLAN.md):
- compose_loras_v2: restore _cached_first_lora_state_dict so the first
LoRA state dict loaded during section-3 debug inspection is reused in
the section-4 main loop. Without this the first LoRA is read from disk
twice whenever the precompiled cache is disabled (default).
- qwenimage_v2.py IS_CHANGED: drop the `model` arg (ComfyUI never passes
MODEL inputs to IS_CHANGED; the TypeError -> NaN path forced re-compose
every run) and remove str(model) from the hash (object repr changes
every run, which also forced constant re-execution).
Restores the _cached_first_lora_state_dict optimization that was
unintentionally lost during the AWQ modulation layer monkey patch
commit (b618d6f). The cache variable was dropped during the
sectional restructuring of compose_loras_v2().
This eliminates duplicate file I/O for the first LoRA in single-LoRA
workflows, restoring ~40-50% loading time reduction.
- Update _detect_lora_format to support LoRA keys with extra tags like .default.weight.
This ensures compatibility with LoRAs using naming conventions such as:
transformer_blocks.0.attn.add_k_proj.lora_A.default.weight
- Add detailed warning logs to identify which LoRA files had modulation layers (img_mod/txt_mod) skipped for Nunchaku safety.