Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
fixed syntax warnings (#1522)
Kareem71d2a245757c
diff --git a/unsloth/chat_templates.py b/unsloth/chat_templates.pyindex c4013932343..5785894a23f 100644--- a/unsloth/chat_templates.py+++ b/unsloth/chat_templates.py@@ -1684,7 +1684,7 @@ extra_eos_tokens = None,for j in range(1, len(response_part)):try_find = re.escape(response_part[:j])- try: found = next(re.finditer("(" + try_find + ").+?\{INPUT\}", chat_template, flags = re.DOTALL | re.MULTILINE))+ try: found = next(re.finditer("(" + try_find + ").+?\\{INPUT\\}", chat_template, flags = re.DOTALL | re.MULTILINE))except: breakpassseparator = found.group(1)@@ -2125,7 +2125,7 @@ def test_hf_gguf_equivalence(tokenizer, gguf_model = "./model-unsloth.F16.gguf")gguf_tokens = "".join(datas)# Now extract GGUF tokenization attempt- gguf_tokenized = re.findall("([\d]{1,}) \-\> \'([^\']{1,})\'", gguf_tokens, flags = re.MULTILINE)+ gguf_tokenized = re.findall(r"([\d]{1,}) \-\> \'([^\']{1,})\'", gguf_tokens, flags = re.MULTILINE)gguf_tokenized = [(int(x[0]), x[1],) for x in gguf_tokenized]input_ids = tokenizer(prompt).input_idsdiff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 6a3effb3c8f..19b09e803cd 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -589,7 +589,7 @@ if Version(peft_version) < Version("0.12.0"):spaces = len(re.match(r"[\s]{1,}", source).group(0))lines = source.split("\n")source = "\n".join(x[spaces:] for x in lines)- source = re.sub("([^\.])nn\.", r"\1torch.nn.", source)+ source = re.sub(r"([^\.])nn\.", r"\1torch.nn.", source)source = source.replace("def update_layer", "def LoraLayer_update_layer")exec(source, globals())@@ -852,7 +852,7 @@ def patch_linear_scaling(scaled_rope_function = scaled_rope_module.__name__,)rotary_emb = re.findall(- "self.rotary_emb = .+?\)", function,+ r"self\.rotary\_emb \= .+?\)", function,flags = re.DOTALL | re.MULTILINE,)if len(rotary_emb) == 0:@@ -952,7 +952,7 @@ def patch_llama_rope_scaling((longrope_module if longrope_module is not None else rope_module).__name__)rotary_emb = re.findall(- "self.rotary_emb = .+?\)", function,+ r"self\.rotary\_emb \= .+?\)", function,flags = re.DOTALL | re.MULTILINE,)if len(rotary_emb) == 0: return None, functiondiff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex 3e0717a872a..9515a41cd97 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -1888,11 +1888,11 @@ class FastLlamaModel:passexec("from transformers.trainer import (" + ", ".join(x for x in good_items) + ")", globals())- start = re.search('logger\.info\([\"\'].+?Running training', inner_training_loop).span(0)[0]+ start = re.search(r'logger\.info\([\"\'].+?Running training', inner_training_loop).span(0)[0]end = inner_training_loop.find("\n\n", start)original_debug = inner_training_loop[start:end]- spaces = re.search('\n([\s\t]{1,})', original_debug).group(0)[1:]- front_spaces = re.match('([\s\t]{1,})', inner_training_loop).group(0)+ spaces = re.search(r'\n([\s\t]{1,})', original_debug).group(0)[1:]+ front_spaces = re.match(r'([\s\t]{1,})', inner_training_loop).group(0)# Cannot use \\ since it will cause a SyntaxWarning in Python 3.12# Instead use chr(92) == \\diff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex 51450aa0d93..31c6394f5dd 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -98,9 +98,9 @@ class FastBaseVisionModel:statistics = \f"==((====))== Unsloth {__version__}: Fast {model_types[0].title()} vision patching. Transformers: {transformers_version}.\n"\- f" \\\ /| GPU: {gpu_stats.name}. Max memory: {max_memory} GB. Platform: {platform_system}.\n"\- f"O^O/ \_/ \\ Torch: {torch.__version__}. CUDA: {gpu_stats.major}.{gpu_stats.minor}. CUDA Toolkit: {torch.version.cuda}. Triton: {triton_version}\n"\- f"\ / Bfloat16 = {str(SUPPORTS_BFLOAT16).upper()}. FA [Xformers = {xformers_version}. FA2 = {HAS_FLASH_ATTENTION}]\n"\+ f" {chr(92)}{chr(92)} /| GPU: {gpu_stats.name}. Max memory: {max_memory} GB. Platform: {platform_system}.\n"\+ f"O^O/ {chr(92)}_/ {chr(92)} Torch: {torch.__version__}. CUDA: {gpu_stats.major}.{gpu_stats.minor}. CUDA Toolkit: {torch.version.cuda}. Triton: {triton_version}\n"\+ f"{chr(92)} / Bfloat16 = {str(SUPPORTS_BFLOAT16).upper()}. FA [Xformers = {xformers_version}. FA2 = {HAS_FLASH_ATTENTION}]\n"\f' "-____-" Free Apache license: http://github.com/unslothai/unsloth'print(statistics)diff --git a/unsloth/save.py b/unsloth/save.pyindex eaddfa05c53..af95de07e7f 100644--- a/unsloth/save.py+++ b/unsloth/save.py@@ -482,8 +482,8 @@ def unsloth_save_model(max_ram = psutil.virtual_memory().availablesharded_ram_usage = 5 * 1024 * 1024 * 1024if type(max_shard_size) is str:- gb_found = re.match("([0-9]{1,})[\s]{0,}GB", max_shard_size, flags = re.IGNORECASE)- mb_found = re.match("([0-9]{1,})[\s]{0,}MB", max_shard_size, flags = re.IGNORECASE)+ gb_found = re.match(r"([0-9]{1,})[\s]{0,}GB", max_shard_size, flags = re.IGNORECASE)+ mb_found = re.match(r"([0-9]{1,})[\s]{0,}MB", max_shard_size, flags = re.IGNORECASE)if gb_found: sharded_ram_usage = int(gb_found.group(1)) * 1024 * 1024 * 1024elif mb_found: sharded_ram_usage = int(mb_found.group(1)) * 1024 * 1024elif type(max_shard_size) is int:@@ -1017,9 +1017,9 @@ def save_to_gguf(print_info = \f"==((====))== Unsloth: Conversion from QLoRA to GGUF information\n"\- f" \\\ /| [0] Installing llama.cpp might take 3 minutes.\n"\- f"O^O/ \_/ \\ [1] Converting HF to GGUF 16bits might take 3 minutes.\n"\- f"\ / [2] Converting GGUF 16bits to {quantization_method} might take 10 minutes each.\n"\+ f" {chr(92)}{chr(92)} /| [0] Installing llama.cpp might take 3 minutes.\n"\+ f"O^O/ {chr(92)}_/ {chr(92)} [1] Converting HF to GGUF 16bits might take 3 minutes.\n"\+ f"{chr(92)} / [2] Converting GGUF 16bits to {quantization_method} might take 10 minutes each.\n"\f' "-____-" In total, you will have to wait at least 16 minutes.\n'print(print_info)