|
127 | 127 | ) |
128 | 128 | _compile_config.disable = True # Must set manually |
129 | 129 |
|
| 130 | +from unsloth_zoo.vllm_utils import ( |
| 131 | + convert_lora_modules, |
| 132 | + return_lora_modules, |
| 133 | +) |
| 134 | + |
130 | 135 | try: |
131 | 136 | torch_compiler_set_stance = torch.compiler.set_stance |
132 | 137 | except: |
133 | 138 | torch_compiler_set_stance = None |
134 | 139 |
|
135 | 140 |
|
136 | | -def _fix_requires_grad_hooks_for_kwargs(model): |
137 | | - """ |
138 | | - Fix requires_grad pre-hooks for models whose forward() receives all |
139 | | - arguments via kwargs (e.g. Idefics3 vision encoder). |
140 | | -
|
141 | | - requires_grad_pre_hook in unsloth_zoo only inspects positional args. |
142 | | - When positional args are empty it raises RuntimeError. This replaces |
143 | | - those hooks with a version that returns gracefully on empty args. |
144 | | - """ |
145 | | - from collections import OrderedDict |
146 | | - |
147 | | - def _safe_requires_grad_pre_hook(module, input): |
148 | | - type_input = type(input) |
149 | | - if type_input is torch.Tensor: |
150 | | - input.requires_grad_(True) |
151 | | - elif type_input is tuple or type_input is list: |
152 | | - if len(input) == 0: |
153 | | - return |
154 | | - if torch.is_floating_point(input[0]): |
155 | | - input[0].requires_grad_(True) |
156 | | - |
157 | | - |
158 | | - for name, module in model.named_modules(): |
159 | | - if len(module._forward_pre_hooks) == 0: |
160 | | - continue |
161 | | - new_hooks = OrderedDict() |
162 | | - for hook_id, hook in module._forward_pre_hooks.items(): |
163 | | - qualname = getattr(hook, "__qualname__", "") |
164 | | - if "requires_grad_pre_hook" in qualname: |
165 | | - new_hooks[hook_id] = _safe_requires_grad_pre_hook |
166 | | - else: |
167 | | - new_hooks[hook_id] = hook |
168 | | - module._forward_pre_hooks = new_hooks |
169 | | - |
170 | | - |
171 | | - |
172 | | - |
173 | 141 | def unsloth_base_fast_generate( |
174 | 142 | self, |
175 | 143 | *args, |
@@ -497,7 +465,7 @@ def from_pretrained( |
497 | 465 | if is_vlm and fast_inference: |
498 | 466 | if not any(arch in VLLM_SUPPORTED_VLM for arch in model_types): |
499 | 467 | raise RuntimeError( |
500 | | - f"Unsloth: Fast inference is only supported for Language models and Qwen2.5-VL, Gemma3 among vision models. " |
| 468 | + f"Unsloth: Fast inference is only supported for Language models and Qwen2.5-VL, Gemma3, Idefics3 among vision models. " |
501 | 469 | f"Found architectures: {', '.join(model_types)}!" |
502 | 470 | ) |
503 | 471 |
|
@@ -530,7 +498,9 @@ def from_pretrained( |
530 | 498 | vllm_version = "" |
531 | 499 | elif DEVICE_TYPE == "hip": |
532 | 500 | gpu_stats = torch.cuda.get_device_properties(0) |
533 | | - gpu_stats_name = resolve_hip_gpu_stats_name(gpu_stats) |
| 501 | + gpu_stats_name = ( |
| 502 | + gpu_stats.name + ". " if gpu_stats.name != "" else "AMD GPU Device. " |
| 503 | + ) |
534 | 504 | gpu_version = torch.version.hip |
535 | 505 | gpu_stats_snippet = f"ROCm Toolkit: {gpu_version}." |
536 | 506 | try: |
@@ -1264,8 +1234,6 @@ def get_peft_model( |
1264 | 1234 | fix_lora_auto_mapping(model) |
1265 | 1235 | # Enable gradients on modules which are trainable |
1266 | 1236 | requires_grad_for_gradient_checkpointing(model) |
1267 | | - # Fix hooks for models with kwargs-only forward (e.g. Idefics3) |
1268 | | - _fix_requires_grad_hooks_for_kwargs(model) |
1269 | 1237 | trust_remote_code = getattr(model, "_unsloth_trust_remote_code", False) |
1270 | 1238 | model = FastBaseModel.post_patch_model( |
1271 | 1239 | model, |
|
0 commit comments