From aa0427f8982dce16411e826f2ce0bcd0da2520a5 Mon Sep 17 00:00:00 2001 From: Daniel Han-Chen Date: Tue, 6 Feb 2024 02:11:06 +1100 Subject: [PATCH] Update save.py --- unsloth/save.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/unsloth/save.py b/unsloth/save.py index 6d97071f3b..41626cb4e8 100644 --- a/unsloth/save.py +++ b/unsloth/save.py @@ -87,8 +87,14 @@ def _merge_lora(layer, name): if A is not None: sAB = (A.t().to(torch.float32) @ (s * B.t().to(torch.float32))) + # new_W = W + sAB + # W.addmm_(A.t().to(torch.float32), B.t().to(torch.float32), alpha = s) W += sAB - if not torch.isfinite(W).all(): + # if not torch.isfinite(new_W).all() or not torch.isfinite(W).all(): + # print(torch.dist(new_W, W)) + # if not torch.isfinite(W).all(): + maximum_element = torch.max(W.min().abs(), W.max()) + if not torch.isfinite(maximum_element).item(): raise ValueError(f"Unsloth: Merge failed.\n{name} has some elements = infinity.") pass W = W.t().to(dtype)