Skip to content

[Bug] NameError: name 'slice_indices' is not defined - qwen 2 kaggle. #3450

Closed

Description

@ProBuro

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Jun__6_02:18:23_PDT_2024
Cuda compilation tools, release 12.5, V12.5.82
Build cuda_12.5.r12.5/compiler.34385749_0
transformers version 4.56.2

Just a few hours ago, this message began to appear. How to solve the problem?

/kaggle/working/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py in 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)
706
707 hidden_states = outputs[0]
--> 708 logits = self.lm_head(hidden_states[:, slice_indices, :]) if os.environ.get('UNSLOTH_RETURN_LOGITS', '0') == '1' else EMPTY_LOGITS
709 loss = None
710 NOT_RETURN_LOGITS = os.environ.get('UNSLOTH_RETURN_LOGITS', '0') == '0'

NameError: name 'slice_indices' is not defined

Activity

  1. changed the title [-][Bug] Please fill in your issue title here.[/-] [+][Bug] NameError: name 'slice_indices' is not defined - qwen 2 kaggle.[/+] on Oct 14, 2025
  2. codejoetheduke commented on Oct 14, 2025

    @codejoetheduke

    Same here also got this problem:

    Image
  3. bao231 commented on Oct 21, 2025

    @bao231
    Image
  4. bao231 commented on Oct 21, 2025

    @bao231

    same problem

  5. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    I think you should use Qwen3, there's a notebook provided by Unsloth. I stopped getting those errors after using that notebook

  6. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    Same error

  7. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    Yes might be.

  8. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    Same error

    Did you use Qwen3?

  9. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    I tried some methods, but it doesn't work

    pip install --force-reinstall --no-deps -U unsloth unsloth-zoo
    
    import os
    os.environ["UNSLOTH_RETURN_LOGITS"] = "0"
    os.environ.pop("UNSLOTH_RETURN_LOGITS", None)
    
    path = "/content/unsloth_compiled_cache/unsloth_compiled_module_qwen2_vl.py"
    s = open(path, "r", encoding="utf-8").read()
    s = s.replace("hidden_states[:, slice_indices, :]", "hidden_states")
    open(path, "w", encoding="utf-8").write(s)
    

    unsloth_compiled_module_qwen2_vl.py

    I don't know where this file is located, and I'm guessing it's rewritten each time the library is loaded.
    So I can't modify it to achieve my goal.
    Where is its source file? What generates it?

  10. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    If you can modify the code of this file, you may be able to solve the problem

  11. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    Additionally, it's worth clarifying the differences between the Qwen2, Qwen2.5, and Qwen3 models and their corresponding ipynb files.
    I compared the two files and found no difference, aside from the library version.

    transformers

    Image
  12. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    I suspect this is related to the model. Different models use different files in the unsloth_compiled_cache, which can sometimes cause errors and sometimes not.

    Thus, the ultimate cause of the problem may lie with the files in the unsloth_compiled_cache, rather than the model.

  13. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    So use Qwen3 to avoid all those errors. Let's hope unsloth fixes that error in the previous versions

  14. 3 remaining items

  15. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    Relax, try a smaller model then. Maybe not the 8B model. I was also try to rack my brain around it but couldn't find an answer

  16. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    😭 Not for me. I had to use a smaller model like the Qwen2-VL-2B; the Qwen3-VL-4B was too large.

    My main issue was inference on devices without a GPU.

    Oh I see, is it for an edge device? Because it is fine if not. You can use a smaller Qwen3 model. Before that, have you saved the weights of the Qwen2.5vl model? You can run it without unsloth if you think that will solve your problem.

  17. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    😭 Not for me. I had to use a smaller model like the Qwen2-VL-2B; the Qwen3-VL-4B was too large.
    My main issue was inference on devices without a GPU.

    Oh I see, is it for an edge device? Because it is fine if not. You can use a smaller Qwen3 model. Before that, have you saved the weights of the Qwen2.5vl model? You can run it without unsloth if you think that will solve your problem.

    Wow, you are a genius!

  18. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    I am glad that helped!

  19. Deng-Xian-Sheng commented on Oct 21, 2025

    @Deng-Xian-Sheng

    I am glad that helped!

    I tried training, and it seems to work fine.
    So, I can try saving the weights. If that works, I can save them first and then use some other inference method!
    I'm not sure about compatibility; it's said to be slow, but it's better than not working at all.
    Ultimately, I need a gguf. As long as the gguf works, I can use unsloth inference or some other method for inference during the testing phase before packaging it as a gguf. Speed ​​doesn't matter.

    That's a great idea! Worth trying.
    However, I'm going to bed now. I'll wake up in a few hours and try it out.

    I'll leave a comment if I get any news.
    At the very least, it's a viable alternative.

    Thank you, you seem to be an experienced engineer!

  20. codejoetheduke commented on Oct 21, 2025

    @codejoetheduke

    You are welcome! Good night then

  21. andreasspap commented on Oct 23, 2025

    @andreasspap

    Hello. I have the same error but im using Qwen2.5 vl 7b and i dont want to change my model. I tried to run a notebook that some weeks ago was executed correclty and now i have this error.

  22. rahulismyname commented on Nov 3, 2025

    @rahulismyname

    Hi, I still face this issue with Qwen 2 VL every versions. I want to stick to this model for evaluation. Is there a workaround apart from changing the model ?
    Heyy @Deng-Xian-Sheng , unsloth_compiled_module_qwen2_vl.py file you are looking for is inside unsloth_compiled_cache folder in the working directory. I tried updating the code, but still its not useful.
    Hi @andreasspap, Were you able to find any solutions ?
    Hi @unslothai, Please fix this issue.

  23. Deng-Xian-Sheng commented on Nov 3, 2025

    @Deng-Xian-Sheng

    qwen3-vl-2B has been released: https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct. I haven't had time to test the "using alternative reasoning methods" approach due to some work commitments.

    You can try it if you have time.

    Updating the code in that folder is ineffective, likely because the library overwrites those files every time it runs.

    Unless you can find the source files.

  24. Deng-Xian-Sheng commented on Nov 3, 2025

    @Deng-Xian-Sheng

    It seems the qwen3-vl series already includes all model sizes from the qwen2.5-vl series. I haven't looked into it closely, but models of various sizes are available.

    If you must use qwen2.5-vl for some other reason, you may need to investigate further.

  25. Deng-Xian-Sheng commented on Nov 3, 2025

    @Deng-Xian-Sheng

    https://huggingface.co/collections/Qwen/qwen3-vl

    It has an 8B model, which is likely close to the 7B you're using.

    Alternatively, you could use the slightly smaller 4B.

    For benchmarking purposes, you could use a library like vllm for inference.

  26. danielhanchen commented on Nov 3, 2025

    @danielhanchen
    Member

    Extreme apologies on the delay @bao231 @rahulismyname @Deng-Xian-Sheng @ProBuro @codejoetheduke - we just fixed Qwen 2 VL - so sorry again!

    For Colab, Kaggle, please disconnect and delete runtime and try again. For local installs, please update Unsloth via pip install --upgrade --no-cache-dir --no-deps --force-reinstall unsloth unsloth_zoo

  27. added
    fixed - pending confirmation
    on Nov 3, 2025
  28. danielhanchen commented on Sep 9, 2026

    @danielhanchen
    Member

    Fixed! The fused lm_head rewrite only emits the slice_indices indexing when the model's forward actually defines it, which Qwen2-VL's doesn't.

    Please update Unsloth: uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir (if it's not in the current release yet it'll be in the next one). Reopen if it still happens!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions