huggingface / transformers

šŸ¤— Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
131.88k stars 26.26k forks source link

ValueError: cannot reshape array of size <number> into shape #32331

Closed TheSlackOne closed 2 weeks ago

TheSlackOne commented 1 month ago

System Info

Python 3.11.2 Debian 12 ctransformers 0.2.27 transformers 4.42.4

Who can help?

@ArthurZucker

Information

Tasks

Reproduction

Following the example on Hugging Face: https://huggingface.co/docs/transformers/en/gguf

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from huggingface_hub import hf_hub_download
from llama_cpp import Llama

# Ensure the model is loaded on the GPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(f"device set to: {device}")

# Load the model and tokenizer
model_name = "TheBloke/dolphin-2.0-mistral-7B-GGUF"
model_file = "dolphin-2.0-mistral-7b.Q4_K_M.gguf"
print(f"Loading tokenizer from {model_name}.")
tokenizer = AutoTokenizer.from_pretrained(model_name, gguf_file=model_file)
print(f"Loading model from repo {model_name}. Model file name {model_file}.")
model = AutoModelForCausalLM.from_pretrained(model_name, gguf_file=model_file)

I get

ValueError: cannot reshape array of size 36864000 into shape (222,72)

Expected behavior

Model should be loaded.

nimadez commented 1 month ago

Problem solved for me, see this commit and apply the changes or wait for the next update.

ArthurZucker commented 1 month ago

I think it was part of 4.43! šŸ¤—

Tangent-90C commented 1 month ago

Why do I still have this bug when I use the latest version?

image

ArthurZucker commented 1 month ago

can you print import transformers;transformers.__version__ ? šŸ¤—

nimadez commented 1 month ago

I can confirm that it works on 4.44.0

PrasannaPrabhakar666 commented 2 weeks ago

I faced the same problem. Initially I was using Transformers 4.41 ig and upgraded to 4.44. Still faced the same problem. Looked at the code and had same commits. So, cleared cache and restarted the system, it worked.

ArthurZucker commented 2 weeks ago

Cool, closing as solved!

TheSlackOne commented 2 weeks ago

Cool, closing as solved!

Hey @ArthurZucker, please, could you explain how it is solved?

ArthurZucker commented 2 weeks ago

cleared cache and restarted the system, it worked. šŸ˜‰