[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2025-12-01 10:48:28 +00:00
commit d837d6280c
3 changed files with 23 additions and 8 deletions

View file

@ -117,13 +117,16 @@ def fix_xformers_performance_issue():
def patch_vllm_imports():
if importlib.util.find_spec("vllm") is None:
return
def fix_vllm_aimv2_issue():
# ValueError: 'aimv2' is already used by a Transformers config, pick another name.
vllm_version = importlib_version("vllm")
if Version(vllm_version) < Version("0.10.1"):
vllm_version = importlib.util.find_spec("vllm").origin
vllm_version = os.path.split(vllm_version)[0]
ovis_config = Path(vllm_version) / "transformers_utils" / "configs" / "ovis.py"
ovis_config = (
Path(vllm_version) / "transformers_utils" / "configs" / "ovis.py"
)
try:
if ovis_config.exists():
with open(ovis_config, "r+", encoding = "utf-8") as f:
@ -160,16 +163,18 @@ def patch_vllm_imports():
# https://github.com/vllm-project/vllm/pull/22772/files
# trl still wants to use GuidedDecodingParams. This is a temporary patch till trl updates
import vllm
try:
from vllm.sampling_params import GuidedDecodingParams
except ImportError:
vllm.sampling_params.GuidedDecodingParams = vllm.sampling_params.StructuredOutputsParams
vllm.sampling_params.GuidedDecodingParams = (
vllm.sampling_params.StructuredOutputsParams
)
fix_vllm_aimv2_issue()
fix_vllm_guided_decoding_params()
def ignore_logger_messages():
# Ignore Environment variable `HF_TOKEN` is set
try:

View file

@ -59,7 +59,9 @@ def Qwen3MoeSparseMoeBlock_fast_forward(self, X, temp_gate = None, temp_up = Non
self.gate_proj, X, out = temp_gate
) # pretty much the only change from transformers implementation.
routing_weights = torch_nn_functional_softmax(router_logits, dim = -1, dtype = torch.float32)
routing_weights = torch_nn_functional_softmax(
router_logits, dim = -1, dtype = torch.float32
)
routing_weights, selected_experts = torch.topk(routing_weights, self.top_k, dim = -1)
routing_weights /= routing_weights.sum(dim = -1, keepdim = True)
# we cast back to the input dtype

View file

@ -348,10 +348,14 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
and trainer_file.split("_")[0] in x.lower()
]
if len(name) != 1:
print(f"Unsloth: Could not find Trainer class in trl.trainer.{trainer_file}. Found: {name}")
print(
f"Unsloth: Could not find Trainer class in trl.trainer.{trainer_file}. Found: {name}"
)
return
if len(config) != 1:
print(f"Unsloth: Could not find Config class in trl.trainer.{trainer_file}. Found: {config}")
print(
f"Unsloth: Could not find Config class in trl.trainer.{trainer_file}. Found: {config}"
)
return
# Get SFTTrainer, SFTConfig
@ -360,12 +364,16 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"):
try:
RLTrainer = eval(f"trl.trainer.{trainer_file}.{RLTrainer_name}")
except:
print(f"Unsloth: Could not load {RLTrainer_name} from trl.trainer.{trainer_file}")
print(
f"Unsloth: Could not load {RLTrainer_name} from trl.trainer.{trainer_file}"
)
return
try:
RLConfig = eval(f"trl.trainer.{trainer_file}.{RLConfig_name}")
except:
print(f"Unsloth: Could not load {RLConfig_name} from trl.trainer.{trainer_file}")
print(
f"Unsloth: Could not load {RLConfig_name} from trl.trainer.{trainer_file}"
)
return
# Check name