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
Llama 3.1
Daniel Han5efbd701bac1
diff --git a/README.md b/README.mdindex 05977bad737..c666f2d9c86 100644--- a/README.md+++ b/README.md@@ -22,7 +22,7 @@ All notebooks are **beginner friendly**! Add your dataset, click "Run All", and| Unsloth supports | Free Notebooks | Performance | Memory use ||-----------|---------|--------|----------|-| **Llama 3 (8B)** | [▶️ Start for free](https://colab.research.google.com/drive/135ced7oHytdxu3N2DNe1Z0kqjyYIkDXp?usp=sharing) | 2x faster | 60% less |+| **Llama 3.1 (8B)** | [▶️ Start for free](https://colab.research.google.com/drive/135ced7oHytdxu3N2DNe1Z0kqjyYIkDXp?usp=sharing) | 2x faster | 60% less || **Mistral Nemo (12B)** | [▶️ Start for free](https://colab.research.google.com/drive/17d3U-CAIwzmbDRqbZ9NnpHxCkmXB6LZ0?usp=sharing) | 2x faster | 60% less || **Gemma 2 (9B)** | [▶️ Start for free](https://colab.research.google.com/drive/1vIrqH5uYDQwsJ4-OO3DErvuv4pBgVwk4?usp=sharing) | 2x faster | 63% less || **Phi-3 (mini)** | [▶️ Start for free](https://colab.research.google.com/drive/1lN6hPQveB_mHSnTOYifygFcrO8C1bxq4?usp=sharing) | 2x faster | 50% less |@@ -32,13 +32,14 @@ All notebooks are **beginner friendly**! Add your dataset, click "Run All", and| **DPO Zephyr** | [▶️ Start for free](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) | 1.9x faster | 43% less || **TinyLlama** | [▶️ Start for free](https://colab.research.google.com/drive/1AZghoNBQaMDgWJpi4RbffGM1h6raLUj9?usp=sharing) | 3.9x faster | 74% less |-- **Kaggle Notebooks** for [Llama 3 (8B)](https://www.kaggle.com/code/danielhanchen/kaggle-llama-3-8b-unsloth-notebook), [Gemma 2 (9B)](https://www.kaggle.com/code/danielhanchen/kaggle-gemma-7b-unsloth-notebook/), [Mistral (7B)](https://www.kaggle.com/code/danielhanchen/kaggle-mistral-7b-unsloth-notebook)+- **Kaggle Notebooks** for [Llama 3.1 (8B)](https://www.kaggle.com/code/danielhanchen/kaggle-llama-3-8b-unsloth-notebook), [Gemma 2 (9B)](https://www.kaggle.com/code/danielhanchen/kaggle-gemma-7b-unsloth-notebook/), [Mistral (7B)](https://www.kaggle.com/code/danielhanchen/kaggle-mistral-7b-unsloth-notebook)- Run [Llama 3 conversational notebook](https://colab.research.google.com/drive/1XamvWYinY6FOSX9GLvnqSjjsNflxdhNc?usp=sharing) and [Mistral v0.3 ChatML](https://colab.research.google.com/drive/15F1xyn8497_dUbxZP4zWmPZ3PJx1Oymv?usp=sharing)- This [text completion notebook](https://colab.research.google.com/drive/1ef-tab5bhkvWmBOObepl1WgJvfvSzn5Q?usp=sharing) is for continued pretraining / raw text- This [continued pretraining notebook](https://colab.research.google.com/drive/1tEd1FrOXWMnCU9UIvdYhs61tkxdMuKZu?usp=sharing) is for learning another language- Click [here](https://github.com/unslothai/unsloth/wiki) for detailed documentation for Unsloth.## 🦥 Unsloth.ai News+- 📣 NEW! [Llama 3.1 8b, 70b](https://colab.research.google.com/drive/135ced7oHytdxu3N2DNe1Z0kqjyYIkDXp?usp=sharing) both Base and Instruct now supported- 📣 NEW! [Mistral Nemo-12b](https://colab.research.google.com/drive/17d3U-CAIwzmbDRqbZ9NnpHxCkmXB6LZ0?usp=sharing) both Base and Instruct now supported- 📣 NEW! [Gemma-2-9b](https://colab.research.google.com/drive/1vIrqH5uYDQwsJ4-OO3DErvuv4pBgVwk4?usp=sharing) and Gemma-2-27b now supported- 📣 UPDATE! [Phi-3 mini](https://colab.research.google.com/drive/1hhdhBa1j_hsymiW9m-WzxQtgqTH_NHqi?usp=sharing) model updated. [Phi-3 Medium](https://colab.research.google.com/drive/1hhdhBa1j_hsymiW9m-WzxQtgqTH_NHqi?usp=sharing) 2x faster finetuning.diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex 27eb226f279..394213b9f07 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -868,9 +868,11 @@ def patch_llama_rope_scaling("self.rotary_emb = .+?\)", function,flags = re.DOTALL | re.MULTILINE,)+ print(rotary_emb)if len(rotary_emb) == 0: return None, functionrotary_emb = rotary_emb[0]function = function.replace(rotary_emb, fix_rope_function, 1)+ print(function)function = exec_code + "\n\n" + functionreturn init_name, functionpassdiff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex 2d224b3cad2..58fcc927642 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -1088,11 +1088,13 @@ class LlamaExtendedRotaryEmbedding(LlamaRotaryEmbedding):self.register_buffer("sin_cached", emb.sin().to(dtype=dtype, device=device, non_blocking=True), persistent=False)pass- def apply_scaling(self, freqs: torch.Tensor):+ # From https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/api/model.py#L41+ def apply_scaling(freqs: torch.Tensor):+ # Values obtained from grid searchscale_factor = 8low_freq_factor = 1high_freq_factor = 4- old_context_len = 8192+ old_context_len = 8192 # original llama3 lengthlow_freq_wavelen = old_context_len / low_freq_factorhigh_freq_wavelen = old_context_len / high_freq_factor@@ -1106,9 +1108,9 @@ class LlamaExtendedRotaryEmbedding(LlamaRotaryEmbedding):else:assert low_freq_wavelen != high_freq_wavelensmooth = (old_context_len / wavelen - low_freq_factor) / (- high_freq_factor - low_freq_factor)- new_freqs.append((1 - smooth) * freq / scale_factor +- smooth * freq)+ high_freq_factor - low_freq_factor+ )+ new_freqs.append((1 - smooth) * freq / scale_factor + smooth * freq)return torch.tensor(new_freqs, dtype=freqs.dtype, device=freqs.device)passpassdiff --git a/unsloth/models/mapper.py b/unsloth/models/mapper.pyindex 462c85f2a13..fc13c94e842 100644--- a/unsloth/models/mapper.py+++ b/unsloth/models/mapper.py@@ -218,18 +218,20 @@ __INT_TO_FLOAT_MAPPER = \"unsloth/Mistral-Nemo-Base-2407","mistralai/Mistral-Nemo-Base-2407",),- "unsloth/llama-3.1-8b-bnb-4bit" : (- "unsloth/llama-3.1-8b",+ "unsloth/Meta-Llama-3.1-8B-bnb-4bit" : (+ "unsloth/Meta-Llama-3.1-8B","meta-llama/Meta-Llama-3.1-8B",),- "unsloth/llama-3.1-8b-Instruct-bnb-4bit" : (- "unsloth/llama-3.1-8b-Instruct",+ "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit" : (+ "unsloth/Meta-Llama-3.1-8B-Instruct","meta-llama/Meta-Llama-3.1-8B-Instruct",),- "unsloth/llama-3.1-70b-bnb-4bit" : (+ "unsloth/Meta-Llama-3.1-70B-bnb-4bit" : (+ "unsloth/Meta-Llama-3.1-70B","meta-llama/Meta-Llama-3.1-70B",),- "unsloth/llama-3.1-70b-Instruct-bnb-4bit" : (+ "unsloth/Meta-Llama-3.1-70B-Instruct-bnb-4bit" : (+ "unsloth/Meta-Llama-3.1-70B-Instruct","meta-llama/Meta-Llama-3.1-70B-Instruct",),}