From faf27477aab01ed879b8d5d8d75fc6de2c5c05e5 Mon Sep 17 00:00:00 2001 From: Edd <68678137+Erland366@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:10:52 +0400 Subject: [PATCH] fix/transformers-unpack (#1180) * Fix DPO, ORPO (#1177) * Fix TRL * Update mistral.py * Patch processing_class * Update tokenizer_utils.py * Update tokenizer_utils.py * Update tokenizer_utils.py * Update tokenizer_utils.py * Update tokenizer_utils.py * Update tokenizer_utils.py * Installation guide (#1165) * chore: update chat_templates.py (#1166) orginal -> original * Disable Flex Attention * Update tokenizer_utils.py * Update _utils.py * n_items * Update cross_entropy_loss.py * Fix DPO, ORPO * Update _utils.py --------- Co-authored-by: timothelaborie <97834767+timothelaborie@users.noreply.github.com> Co-authored-by: Ikko Eltociear Ashimine * Add warning for missing Unpack and KwargsForCausalLM in older Transformers versions --------- Co-authored-by: Daniel Han Co-authored-by: timothelaborie <97834767+timothelaborie@users.noreply.github.com> Co-authored-by: Ikko Eltociear Ashimine --- unsloth/kernels/cross_entropy_loss.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py index 1c8f8c8d99..57d07af493 100644 --- a/unsloth/kernels/cross_entropy_loss.py +++ b/unsloth/kernels/cross_entropy_loss.py @@ -388,6 +388,13 @@ from transformers.models.llama.modeling_llama import ( List, Tuple, ) + +try: + from transformers.models.llama.modeling_llama import Unpack, KwargsForCausalLM +except ImportError: + logger.warning("Unsloth: Could not find Unpack, KwargsForCausalLM in LlamaForCausalLM. " + "This is expected if you are using an older version of Transformers (<4.46.0). ") + import inspect, re function = inspect.getsource(LlamaForCausalLM.forward) function = function.split("\n")