Repository navigation
Description
What I did -
conda create -n qwen python=3.11 -y
conda activate qwen
pip install --force-reinstall git+https://github.com/unslothai/unsloth-zoo.git
pip install --force-reinstall git+https://github.com/unslothai/unsloth.git
pip install bitsandbytes==0.45.5
pip install wandb
pip install torchvision
Start training using -
model, tokenizer = FastVisionModel.from_pretrained(
"unsloth/Qwen2-VL-7B-Instruct",
max_seq_length = 2048,
load_in_4bit=True,
load_in_8bit=False,
full_finetuning=False,
)
model = FastVisionModel.get_peft_model(
model,
finetune_vision_layers=True,
finetune_language_layers=True,
finetune_attention_modules=True,
finetune_mlp_modules=True,
r=8,
lora_alpha=16,
lora_dropout=0,
bias="none",
random_state=3407,
use_rslora=True,
loftq_config=None
)
trainer = SFTTrainer(
model=model,
tokenizer=tokenizer,
data_collator=UnslothVisionDataCollator(model, tokenizer),
train_dataset=train_ds,
eval_dataset=eval_ds,
args=SFTConfig(
per_device_train_batch_size=4,
gradient_accumulation_steps=1,
num_train_epochs=3, # You might want to experiment with this
#max_steps=1000,
warmup_steps=5,
learning_rate=2e-5,
fp16=not is_bf16_supported(),
bf16=is_bf16_supported(),
logging_steps=50,
optim="adamw_8bit",
weight_decay=0.01,
lr_scheduler_type="linear",
seed=3407,
output_dir="jun30", # Updated output directory name
report_to="wandb",
remove_unused_columns=False,
dataset_text_field="",
dataset_kwargs={"skip_prepare_dataset": True},
dataset_num_proc=4,
max_seq_length=2048,
save_strategy="steps",
eval_strategy="steps",
save_steps=1000,
eval_steps=1000,
),
)
trainer.train()
What I got -
Traceback (most recent call last):
File "/workspace/test/train_correction.py", line 170, in
model = FastVisionModel.get_peft_model(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth/models/vision.py", line 630, in get_peft_model
model = _get_peft_model(model, lora_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/mapping_func.py", line 123, in get_peft_model
return MODEL_TYPE_TO_PEFT_MODEL_MAPPING[peft_config.task_type](
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/peft_model.py", line 1722, in init
super().init(model, peft_config, adapter_name, **kwargs)
File "/venv/test/lib/python3.11/site-packages/peft/peft_model.py", line 132, in init
self.base_model = cls(model, {adapter_name: peft_config}, adapter_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/tuners/lora/model.py", line 142, in init
super().init(model, config, adapter_name, low_cpu_mem_usage=low_cpu_mem_usage)
File "/venv/test/lib/python3.11/site-packages/peft/tuners/tuners_utils.py", line 180, in init
self.inject_adapter(self.model, adapter_name, low_cpu_mem_usage=low_cpu_mem_usage)
File "/venv/test/lib/python3.11/site-packages/peft/tuners/tuners_utils.py", line 508, in inject_adapter
self._create_and_replace(peft_config, adapter_name, target, target_name, parent, current_key=key)
File "/venv/test/lib/python3.11/site-packages/peft/tuners/lora/model.py", line 237, in _create_and_replace
new_module = self._create_new_module(lora_config, adapter_name, target, device_map=device_map, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/tuners/lora/model.py", line 342, in _create_new_module
new_module = dispatcher(target, adapter_name, lora_config=lora_config, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/tuners/lora/layer.py", line 1764, in dispatch_default
kwargs.update(lora_config.loftq_config)
TypeError: 'NoneType' object is not iterable
on setting loftq_config={}, I then got
Traceback (most recent call last):
File "/workspace/test/train_correction.py", line 221, in
trainer.train()
File "/venv/test/lib/python3.11/site-packages/transformers/trainer.py", line 2207, in train
return inner_training_loop(
^^^^^^^^^^^^^^^^^^^^
File "", line 321, in _fast_inner_training_loop
File "/workspace/test/unsloth_compiled_cache/UnslothSFTTrainer.py", line 895, in training_step
return super().training_step(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 34, in _unsloth_training_step
File "/workspace/test/unsloth_compiled_cache/UnslothSFTTrainer.py", line 884, in compute_loss
outputs = super().compute_loss(
^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth/models/_utils.py", line 1083, in _unsloth_pre_compute_loss
outputs = self._old_compute_loss(model, inputs, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/transformers/trainer.py", line 3837, in compute_loss
outputs = model(**inputs)
^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/accelerate/utils/operations.py", line 818, in forward
return model_forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/accelerate/utils/operations.py", line 806, in call
return convert_to_fp32(self.model_forward(*args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/amp/autocast_mode.py", line 44, in decorate_autocast
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/peft_model.py", line 1757, in forward
return self.base_model(
^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1857, in _call_impl
return inner()
^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1805, in inner
result = forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/peft/tuners/tuners_utils.py", line 193, in forward
return self.model.forward(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 852, in forward
return Qwen2VLForConditionalGeneration_forward(self, input_ids, attention_mask, position_ids, past_key_values, inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, pixel_values, pixel_values_videos, image_grid_thw, video_grid_thw, rope_deltas, cache_position, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/transformers/utils/generic.py", line 943, in wrapper
output = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 677, in Qwen2VLForConditionalGeneration_forward
outputs = self.model(
^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/transformers/models/qwen2_vl/modeling_qwen2_vl.py", line 1166, in forward
image_embeds = self.get_image_features(pixel_values, image_grid_thw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/transformers/models/qwen2_vl/modeling_qwen2_vl.py", line 1119, in get_image_features
image_embeds = self.visual(pixel_values, grid_thw=image_grid_thw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 601, in forward
return Qwen2VisionTransformerPretrainedModel_forward(self, hidden_states, grid_thw, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 520, in Qwen2VisionTransformerPretrainedModel_forward
hidden_states = self._gradient_checkpointing_func(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/_compile.py", line 51, in inner
return disable_fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 838, in _fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/utils/checkpoint.py", line 488, in checkpoint
return CheckpointFunction.apply(function, preserve, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/autograd/function.py", line 575, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/gradient_checkpointing.py", line 475, in forward
outputs = run_function(*args)
^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/transformers/modeling_layers.py", line 82, in call
return self._gradient_checkpointing_func(partial(super().call, **kwargs), *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/_compile.py", line 51, in inner
return disable_fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 838, in _fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/utils/checkpoint.py", line 488, in checkpoint
return CheckpointFunction.apply(function, preserve, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/autograd/function.py", line 575, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/gradient_checkpointing.py", line 475, in forward
outputs = run_function(*args)
^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/transformers/models/qwen2_vl/modeling_qwen2_vl.py", line 411, in forward
hidden_states = hidden_states + self.attn(
^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 445, in forward
return VisionAttention_forward(self, hidden_states, cu_seqlens, rotary_pos_emb, position_embeddings, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 655, in _fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 374, in VisionAttention_forward
logger.warning_once(
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 380, in torch_dynamo_resume_in_VisionAttention_forward_at_374
emb = torch.cat((rotary_pos_emb, rotary_pos_emb), dim=-1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected Tensor as element 0 in argument 0, but got tuple
Activity
Rakshith12-pixel commentedon Jun 30, 2025
on downgrading unsloth and unsloth-zoo to 2025.6.8 and unsloth_zoo to 2025.6.6 I then got
Traceback (most recent call last):
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/compiler.py", line 432, in create_new_function
new_module, old_path = import_module(compile_folder, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/compiler.py", line 427, in import_module
new_module = importlib.import_module(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 936, in exec_module
File "", line 1074, in get_code
File "", line 1004, in source_to_code
File "", line 241, in _call_with_frames_removed
File "/workspace/test/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 771
loss = self.loss_function(logits=logits, labels=labels.to(self.lm_head.weight.device), self.config.vocab_size)
^
SyntaxError: positional argument follows keyword argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/compiler.py", line 457, in create_new_function
spec.loader.exec_module(new_module)
File "", line 936, in exec_module
File "", line 1074, in get_code
File "", line 1004, in source_to_code
File "", line 241, in _call_with_frames_removed
File "/tmp/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py", line 771
loss = self.loss_function(logits=logits, labels=labels.to(self.lm_head.weight.device), self.config.vocab_size)
^
SyntaxError: positional argument follows keyword argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/compiler.py", line 2156, in unsloth_compile_transformers
combined_module = create_new_function(
^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/compiler.py", line 459, in create_new_function
raise RuntimeError(f"Direct module loading failed for {name}: {e}")
RuntimeError: Direct module loading failed for unsloth_compiled_module_qwen2_vl: positional argument follows keyword argument (unsloth_compiled_module_qwen2_vl.py, line 771)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/workspace/test/train_correction.py", line 161, in
model, tokenizer = FastVisionModel.from_pretrained(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth/models/loader.py", line 701, in from_pretrained
model_types, supports_sdpa = unsloth_compile_transformers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/venv/test/lib/python3.11/site-packages/unsloth/models/_utils.py", line 1239, in unsloth_compile_transformers
_unsloth_compile_transformers(
File "/venv/test/lib/python3.11/site-packages/unsloth_zoo/compiler.py", line 2168, in unsloth_compile_transformers
raise RuntimeError(exception)
RuntimeError: Direct module loading failed for unsloth_compiled_module_qwen2_vl: positional argument follows keyword argument (unsloth_compiled_module_qwen2_vl.py, line 771)
Rakshith12-pixel commentedon Jun 30, 2025
Wait, now the above error was a different one I got due to the advice of Matthew on discord. after that I did
pip install -U transformers==4.52.4 and pip install -U unsloth==2025.06.04 unsloth-zoo==2025.06.04 referring to #2814 , and the training has started now!
mmathew23 commentedon Jun 30, 2025
Hi just reopening so we can keep track and make sure to update when it's resolved. Thanks!
mmathew23 commentedon Jul 1, 2025
This is been fixed with this PR #2848.
There's also been a pypi release so the issue should be fixed with a pip install --upgrade. Let me know if it works.
shimmyshimmer commentedon Jul 23, 2025
@Rakshith12-pixel please let us know if it's working. I will be closing this issue for now thanks