Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions unsloth/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,7 @@ def patch_tokenizer(model, tokenizer):

def patch_fast_lora():
import peft.tuners.lora.bnb
from ..kernels.fast_lora import fast_lora_forward

peft.tuners.lora.bnb.Linear4bit.forward = fast_lora_forward

Expand Down
15 changes: 14 additions & 1 deletion unsloth/models/rl_replacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,20 @@ def openenv_vllm_reload_weights():
patch_target_name = "generate_rollout_completions"
patch_target = getattr(openenv_utils, patch_target_name)

src = inspect.getsource(patch_target)
# TRL 0.29.1+ ships some openenv helpers as compiled bytecode without
# accessible source on disk; inspect.getsource raises OSError("could
# not get source code") in that case. Skip the source-rewrite patch
# rather than crashing -- the core unsloth weight-reload path stays
# functional, only the wake_up tag rewrite is skipped.
try:
src = inspect.getsource(patch_target)
except OSError as e:
logger.warning(
f"Unsloth: Could not retrieve source for trl openenv "
f"{patch_target_name} ({e}); skipping rewrite. "
f"Weight reload still functional."
)
return
src = textwrap.dedent(src)
original_src = src

Expand Down
6 changes: 6 additions & 0 deletions unsloth/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,12 @@ def patch_sft_trainer_tokenizer():
except:
return
all_imports = dir(trl.trainer.sft_trainer)
# Make typing names available to the exec'd source bodies. TRL >= 1.x
# type-hints _prepare_dataset / _prepare_non_packed_dataloader with
# `Union[...]` and friends; without these imports in the exec namespace
# those become NameErrors at exec time. Mirrors the pattern used in
# unsloth/models/_utils.py:patch_linear_scaling.
from typing import Union, Optional, List, Any, Callable, Tuple, Dict, Iterator # noqa: F401

for (
function_name,
Expand Down
Loading