From 4057bfe021fc1d61022fb66a2ff423fa6db9590d Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Fri, 21 Mar 2025 15:20:48 -0700 Subject: [PATCH] Update _utils.py --- unsloth/models/_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 45385a6007..027ddf6e89 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -300,11 +300,12 @@ if hasattr(transformers.cache_utils, "DynamicCache") and \ source = source.split("\n") source = "\n".join(x[start:] for x in source) where = source.find("raise KeyError") - source = source[:where] + \ - f"if len(self) == 0:\n{spaces}{spaces}"\ - " raise RuntimeError('Unsloth: You must call `FastLanguageModel.for_inference(model)` before doing inference for Unsloth models.')\n" + \ - f"{spaces}{spaces}else:\n{spaces}{spaces}{spaces}" + source[where:] + # source = source[:where] + \ + # f"if len(self) == 0:\n{spaces}{spaces}"\ + # " raise RuntimeError('Unsloth: You must call `FastLanguageModel.for_inference(model)` before doing inference for Unsloth models.')\n" + \ + # f"{spaces}{spaces}else:\n{spaces}{spaces}{spaces}" + source[where:] source = source.replace("__getitem__", "__cache_utils_getitem__", 1) + print(source) exec(source) transformers.cache_utils.DynamicCache.__getitem__ = __cache_utils_getitem__ pass