Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def _load_from_gguf(self, config: AnyModelConfig) -> AnyModel:

model_path = Path(config.path)
target_device = TorchDevice.choose_torch_device()
compute_dtype = TorchDevice.choose_bfloat16_safe_dtype(target_device)
compute_dtype = TorchDevice.choose_krea2_gguf_dtype(target_device)

# GGMLTensor wrappers (kept on CPU; dequantized on-the-fly by the cache during inference).
sd = gguf_sd_loader(model_path, compute_dtype=compute_dtype)
Expand Down
15 changes: 15 additions & 0 deletions invokeai/backend/util/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,18 @@ def choose_anima_inference_dtype(cls, device: Optional[torch.device] = None) ->
if config.precision == "auto":
return cls.choose_bfloat16_safe_dtype(device)
return NAME_TO_PRECISION[config.precision]

@classmethod
def choose_krea2_gguf_dtype(cls, device: Optional[torch.device] = None) -> torch.dtype:
"""Choose the compute dtype for Krea-2 GGUF weights.

Krea-2 GGUF dequantization in BF16 is unreliable on MPS, so use FP32 there. On other devices,
explicit precision settings are honored and ``auto`` retains the BF16-safe default used by Krea-2.
"""
device = device or cls.choose_torch_device()
if device.type == "mps":
return torch.float32
config = get_config()
if config.precision == "auto":
return cls.choose_bfloat16_safe_dtype(device)
return NAME_TO_PRECISION[config.precision]