#SmolVLM2: Unexpected Indentation Error

47 messages · Page 1 of 1 (latest)

somber helm
#

Hello, I try to use unsloth to load smolvlm2 for inference but I got this error.

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1133, in get_code
  File "<frozen importlib._bootstrap_external>", line 1063, in source_to_code
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/hermeschen/Repo/taiwan-license-plate-recognition/unsloth_compiled_cache/unsloth_compiled_module_smolvlm.py", line 481
    = loss_fct(shift_logits, shift_labels)
IndentationError: unexpected indent

Then I looked up "unsloth_compiled_cache/unsloth_compiled_module_smolvlm.py" and found it generate something wrong.
I supposed that loss_fct(shift_logits, shift_labels) should be assign to loss and try to fix it manaully but it still being overwritten. Is there any solution for this?

worn vigil
#

is there any fix for this yet? did you manage to fix this?

placid whale
#

Please always provide your environment, a code snippet, along with the error.

somber helm
somber helm
placid whale
somber helm
#

I think is this one.

#

It breaks when loading model

#

And my unsloth import is on the top of all other imports but it's before transformers

placid whale
#

yes i'll check this out. the reason the file changes is that it's compiled just in time using a triton compiler

#

that's the case for all the filees under the folder "unsloth_compiled_cache" . That's what the unsloth_zoo compiler.py module does

somber helm
placid whale
#

actually i just ran

#

it

#

you should be fine from the latest updated version from today. They pushed changes

#

so in your system

#
pip install --upgrade --force-reinstall --no-cache-dir --no-deps git+https://github.com/unslothai/unsloth.git
pip install --upgrade --force-reinstall --no-cache-dir --no-deps git+https://github.com/unslothai/unsloth-zoo.git
#

you should be good to go

somber helm
#

Yeah, I use the latest version. But still failed.

#

I will try if it works on newer commit

placid whale
#

also:

  • are you running this on your device in a jupyter notebook or running on google colab. The notebook you shared is for Qwen..
  • if on your device, what is your GPU.
  • check you have cuda available inside the python environment
nvcc --version

and

nvidia-smi
  • which exact smolvlm model are you running, share the huggingface repo.
  • what versions of transformers, xformers, trl and torch do you have on your system
placid whale
#

I am not getting an error at all on a 3060 which is odd

#

either:
1- share your code
or
2- let me know when can you hop on a discord call and share your screen so i can see what's going on

#

all the packages seem the latest

somber helm
#

Actually, I already removed the code after found this problem because I just testing if it can works. It looks like the one below

import os
from argparse import ArgumentParser
from typing import Any, Dict, List

import datasets
import evaluate
import torch
import yaml
from unsloth import FastVisionModel
from datasets import load_dataset
from dotenv import load_dotenv
from transformers import GenerationConfig, TextStreamer

model, processor = FastVisionModel.from_pretrained(
    options["model_name"],
    load_in_4bit=False,  # Use 4bit to reduce memory use. False for 16bit LoRA.
    use_gradient_checkpointing="unsloth",  # True or "unsloth" for long context
    _attn_implementation="flash_attention_2",
    use_cache=True,
    dtype=torch.bfloat16,
    device_map="auto",
    low_cpu_mem_usage=True,
)
FastVisionModel.for_inference(model)
placid whale
placid whale
#

@somber helm do you mind opening a github issue with this. I think it might be a bug somewhere (potentially maybe in another package) and It might help resolve it faster if its on github issues as it will get more eyes .
just include the code snippet you shared with me.
mention that you're trying to load https://huggingface.co/HuggingFaceTB/SmolVLM2-500M-Video-Instruct
the fact that you're running on your local machine which has an RTX 3080
and that your versions of unsloth, torch,transformers, trl and xformers are up to date

#

let me know when you open it

somber helm
#

Yeah, I’ve already opened one on GitHub.

#

Here

placid whale
#

thank you

placid whale
#

solved it.

somber helm
placid whale
#

it's in the transformer's library implementation for the model. give me 10 mins i will add details to the github issue , push a PR to transfromers and a monkey patch PR to unsloth_zoo then i'll come back and tell you how to apply a hack until one of the PRs is approved

somber helm
#

Okay, thank you very much!

placid whale
#

it was tricky. i thought i was hallucinating 😂 sloththumbs

#

also don't turn on

unless you're training or finetuning.
It's not used during inference

somber helm
#

Oh, you’re right. I forgot to remove it.

placid whale
#

just pushed an unsloth-zoo patch pull request to solve this

#

let's give it a couple of hours to see if it gets merged to main 😄