From dfdff912586a5c065983b7c4dbefaf78f28648e3 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 24 Oct 2024 12:17:21 -0700 Subject: [PATCH] Fix 4.47 issue (#1182) * 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 * Update _utils.py * 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 * Update cross_entropy_loss.py * Update _utils.py * Update _utils.py --------- Co-authored-by: timothelaborie <97834767+timothelaborie@users.noreply.github.com> Co-authored-by: Ikko Eltociear Ashimine Co-authored-by: Edd <68678137+Erland366@users.noreply.github.com> --- unsloth/kernels/cross_entropy_loss.py | 8 ++++++++ unsloth/models/_utils.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py index 1c8f8c8d99..f2377d55cc 100644 --- a/unsloth/kernels/cross_entropy_loss.py +++ b/unsloth/kernels/cross_entropy_loss.py @@ -388,6 +388,14 @@ from transformers.models.llama.modeling_llama import ( List, Tuple, ) + +# Transformers 4.47 need Unpack, KwargsForCausalLM +try: + from transformers.models.llama.modeling_llama import Unpack, KwargsForCausalLM +except: + pass +pass + import inspect, re function = inspect.getsource(LlamaForCausalLM.forward) function = function.split("\n") diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index bf5216b228..873a2723c2 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -162,6 +162,20 @@ if hasattr(transformers.cache_utils, "DynamicCache") and \ pass # ============================================= +# ============================================= +# Weird Databricks errors +from transformers.utils import is_openai_available +if is_openai_available(): + try: + from openai import OpenAI + except: + print("Unsloth: OpenAI failed to import - ignoring for now.") + import transformers.utils + def _is_openai_available(): return False + transformers.utils.is_openai_available = _is_openai_available + pass +pass + # ============================================= # Get Flash Attention v2 if Ampere (RTX 30xx, A100) import bitsandbytes as bnb