Skip to content
Merged

Nightly #3753

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e53e185
Update _utils.py
danielhanchen Dec 9, 2025
150eadf
Merge branch 'main' into nightly
danielhanchen Dec 9, 2025
25a6250
Merge branch 'main' into nightly
danielhanchen Dec 9, 2025
6b908cf
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
f754bd2
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
30ade52
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 10, 2025
94bbcaa
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
30b78c5
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
f357fc5
Merge branch 'main' into nightly
danielhanchen Dec 10, 2025
cde2d42
[FIX] [Transformers] VLM input embeds fix for gradients (#3715)
Datta0 Dec 12, 2025
a63a337
Merge branch 'main' into nightly
danielhanchen Dec 12, 2025
2c22ce6
Update rope_embedding.py
danielhanchen Dec 12, 2025
449430d
Merge branch 'main' into nightly
danielhanchen Dec 12, 2025
b5f1a77
Fixes
danielhanchen Dec 12, 2025
c94f595
Update _utils.py
danielhanchen Dec 12, 2025
01319d3
Update import_fixes.py
danielhanchen Dec 12, 2025
696a540
Update rl_replacements.py
danielhanchen Dec 12, 2025
ac54d6e
fix_openenv_no_vllm
danielhanchen Dec 12, 2025
9a98139
Fix
danielhanchen Dec 12, 2025
680f19f
Update __init__.py
danielhanchen Dec 12, 2025
fb763f3
Update __init__.py
danielhanchen Dec 12, 2025
f4f2a7f
Update __init__.py
danielhanchen Dec 12, 2025
e17b62f
Update import_fixes.py
danielhanchen Dec 12, 2025
f34eb0a
Update import_fixes.py
danielhanchen Dec 12, 2025
04ad21c
Update import_fixes.py
danielhanchen Dec 12, 2025
32b52a0
logger
danielhanchen Dec 12, 2025
0c9288f
Update __init__.py
danielhanchen Dec 12, 2025
b5b57b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2025
efb5801
Update __init__.py
danielhanchen Dec 12, 2025
12ccc47
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen Dec 12, 2025
e3918e7
Merge branch 'main' into nightly
danielhanchen Dec 12, 2025
0cb9542
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
5540212
Update import_fixes.py
danielhanchen Dec 17, 2025
4c80b03
Update __init__.py
danielhanchen Dec 17, 2025
e57edc2
Update import_fixes.py
danielhanchen Dec 17, 2025
9bc1567
Update import_fixes.py
danielhanchen Dec 17, 2025
c22fbb7
Update import_fixes.py
danielhanchen Dec 17, 2025
d7482e8
Update import_fixes.py
danielhanchen Dec 17, 2025
ca77798
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 17, 2025
71c5938
Update import_fixes.py
danielhanchen Dec 17, 2025
2991a7d
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen Dec 17, 2025
7c10195
Update unsloth/import_fixes.py
danielhanchen Dec 17, 2025
7f744d9
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
d96ac97
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
3738db7
Update save.py
danielhanchen Dec 17, 2025
fbaacce
[fbgemm] Silence tma fbgemm (#3735)
Datta0 Dec 17, 2025
6e5a561
Merge branch 'nightly' of https://github.com/unslothai/unsloth into n…
danielhanchen Dec 17, 2025
3e6cfb5
Update loader.py
danielhanchen Dec 17, 2025
30a454c
Update save.py
danielhanchen Dec 17, 2025
b58663a
Update save.py
danielhanchen Dec 17, 2025
7b61375
Update _utils.py
danielhanchen Dec 17, 2025
a2b5def
Update _utils.py
danielhanchen Dec 17, 2025
59a1fa5
Diffusers warnings
danielhanchen Dec 17, 2025
5e33a07
Update pyproject.toml
danielhanchen Dec 17, 2025
1f1bf49
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 17, 2025
0ed6738
Merge branch 'main' into nightly
danielhanchen Dec 17, 2025
5d0286d
[hf_hub] Token login (#3739)
Datta0 Dec 18, 2025
6346d17
Merge branch 'main' into nightly
danielhanchen Dec 18, 2025
1de77bf
Do not overwrite slots (#3752)
Datta0 Dec 20, 2025
4d99c57
Merge branch 'main' into nightly
danielhanchen Dec 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions unsloth/import_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def filter(self, x):


class HidePrintMessage:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The __slots__ attribute was removed from the HidePrintMessage class. Using __slots__ is a good practice for memory optimization, especially for classes that are instantiated many times. Since this class has a fixed set of attributes (_original_stream, _hidden_texts), reintroducing __slots__ would be beneficial for performance by preventing the creation of __dict__ for each instance.

class HidePrintMessage:
    __slots__ = ("_original_stream", "_hidden_texts")

__slots__ = ("_original_stream", "_hidden_texts")

def __init__(self, original_stream):
self._original_stream = original_stream
self._hidden_texts = []
Expand Down
21 changes: 21 additions & 0 deletions unsloth/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"patch_hf_quantizer",
"verify_fp8_support_if_applicable",
"_get_inference_mode_context_manager",
"hf_login",
]

import torch
Expand Down Expand Up @@ -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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a bare except: is generally discouraged as it can catch unexpected errors like SystemExit or KeyboardInterrupt, making the program harder to debug and control. It's better to catch a more specific exception, like Exception, or even more specific ones like ImportError or huggingface_hub.utils.HfHubError if applicable.

Suggested change
except:
except Exception:

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 token
3 changes: 1 addition & 2 deletions unsloth/models/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -2130,8 +2130,7 @@ def from_pretrained(
"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 = FastLlamaModel
SUPPORTS_BFLOAT16 = is_bfloat16_supported()
Expand Down
23 changes: 3 additions & 20 deletions unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
HAS_FLASH_ATTENTION_SOFTCAPPING,
USE_MODELSCOPE,
get_transformers_model_type,
hf_login,
)
from .granite import FastGraniteModel
from .llama import FastLlamaModel, logger
Expand Down Expand Up @@ -151,15 +152,7 @@ def from_pretrained(
**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,
Expand Down Expand Up @@ -195,8 +188,6 @@ def from_pretrained(
**kwargs,
)

if token is None:
token = get_token()
if isinstance(dtype, str) and dtype in ["float16", "bfloat16"]:
dtype = getattr(torch, dtype)
assert (
Expand Down Expand Up @@ -687,16 +678,8 @@ def from_pretrained(
*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 str
if whisper_task is not None:
Expand Down
3 changes: 1 addition & 2 deletions unsloth/models/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ def from_pretrained(
"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":
Expand Down