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
Nightly (#3753)
Daniel Han47ede31b8ca1
diff --git a/unsloth/import_fixes.py b/unsloth/import_fixes.pyindex f3aae7f523d..efc7a7f4cd7 100644--- a/unsloth/import_fixes.py+++ b/unsloth/import_fixes.py@@ -72,8 +72,6 @@ class HideLoggingMessage(logging.Filter):class HidePrintMessage:- __slots__ = ("_original_stream", "_hidden_texts")-def __init__(self, original_stream):self._original_stream = original_streamself._hidden_texts = []diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.pyindex d769f815bd3..99292777190 100644--- a/unsloth/models/_utils.py+++ b/unsloth/models/_utils.py@@ -72,6 +72,7 @@ __all__ = ["patch_hf_quantizer","verify_fp8_support_if_applicable","_get_inference_mode_context_manager",+ "hf_login",]import torch@@ -2344,3 +2345,23 @@ def _get_inference_mode_context_manager(model: torch.nn.Module):return torch.no_grad()else:return torch.inference_mode()+++def hf_login(token: Optional[str] = None) -> Optional[str]:+ if token is None:+ try:+ from huggingface_hub import get_token++ token = get_token()+ if token is None:+ return None+ except:+ return None+ try:+ from huggingface_hub import login++ login(token = token)+ return token+ except Exception as e:+ logger.info(f"Failed to login to huggingface using token with error: {e}")+ return tokendiff --git a/unsloth/models/llama.py b/unsloth/models/llama.pyindex 4c9337ccf92..1d7695b9aa4 100644--- a/unsloth/models/llama.py+++ b/unsloth/models/llama.py@@ -2130,8 +2130,7 @@ class FastLlamaModel:"Unsloth: `unsloth_vllm_standby` is True, but environment variable `UNSLOTH_VLLM_STANDBY` is not set to 1!")- if token is None:- token = get_token()+ token = hf_login(token)if model_patcher is None:model_patcher = FastLlamaModelSUPPORTS_BFLOAT16 = is_bfloat16_supported()diff --git a/unsloth/models/loader.py b/unsloth/models/loader.pyindex a1e57560600..fdfc3137328 100644--- a/unsloth/models/loader.py+++ b/unsloth/models/loader.py@@ -20,6 +20,7 @@ from ._utils import (HAS_FLASH_ATTENTION_SOFTCAPPING,USE_MODELSCOPE,get_transformers_model_type,+ hf_login,)from .granite import FastGraniteModelfrom .llama import FastLlamaModel, logger@@ -151,15 +152,7 @@ class FastLanguageModel(FastLlamaModel):**kwargs,):# Login to allow private models- if token is None:- token = get_token()- if token is not None:- try:- from huggingface_hub import login-- login(token = token)- except:- pass+ token = hf_login(token)if load_in_8bit or full_finetuning or qat_scheme is not None:return FastModel.from_pretrained(model_name = model_name,@@ -195,8 +188,6 @@ class FastLanguageModel(FastLlamaModel):**kwargs,)- if token is None:- token = get_token()if isinstance(dtype, str) and dtype in ["float16", "bfloat16"]:dtype = getattr(torch, dtype)assert (@@ -687,16 +678,8 @@ class FastModel(FastBaseModel):*args,**kwargs,):- if token is None:- token = get_token()# Login to allow private models- if token is not None:- try:- from huggingface_hub import login-- login(token = token)- except:- pass+ token = hf_login(token)if whisper_language is not None:assert type(whisper_language) is strif whisper_task is not None:diff --git a/unsloth/models/vision.py b/unsloth/models/vision.pyindex 138b1b633a8..b78b190bcb5 100644--- a/unsloth/models/vision.py+++ b/unsloth/models/vision.py@@ -397,8 +397,7 @@ class FastBaseModel:"Unsloth: WARNING `trust_remote_code` is True.\n""Are you certain you want to do remote code execution?")- if token is None:- token = get_token()+ token = hf_login(token)SUPPORTS_BFLOAT16 = is_bfloat16_supported()if DEVICE_TYPE == "cuda":