The model weights are not tied. Please use the `tie_weights` method before using the `infer_auto_device` function.
I'm having this error in a Jupyter Notebook exercise
ValueError: The current device_map
had weights offloaded to the disk. Please provide an offload_folder
for them. Alternatively, make sure you have safetensors
installed if the model you are using offers the weights in this format.
Can anybody help me?
I have the same issue (not Jupiter notebook in my case) although I have followed advices found in forums and youtube videos, but no success yet :(
I share my testing code, launched from Console Prompt (Windows 11 Enterprise with 16GB RAM), and error details, in case anyone could help here.
Code:
import langchain
from langchain import HuggingFacePipeline
from langchain import PromptTemplate
from langchain import LLMChain
from langchain.document_loaders import OnlinePDFLoader
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "OpenAssistant/stablelm-7b-sft-v7-epoch-3"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name, device_map="auto", offload_folder="offload", torch_dtype=torch.float16
)
model.tie_weights()
llm = HuggingFacePipeline.from_model_id(model_id = model_name,
task = "text-generation", model_kwargs = {
"temperature" : 0.0, "max_length" : 2048, "device_map" : "auto"})
loader = OnlinePDFLoader("https://arxiv.org/pdf/1911.01547.pdf")
document = loader.load()
template = """<|prompter|>{question}<|endoftext|><|assistant|>"""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = "What is the meaning of life?"
llm_chain.run(question)
Output:
The model weights are not tied. Please use the tie_weights
method before using the infer_auto_device
function.
Loading checkpoint shards: 100%|ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 9/9 [00:50<00:00, 5.66s/it]
The model weights are not tied. Please use the tie_weights
method before using the infer_auto_device
function.
20 β
β 21 β
β 22 β
β β± 23 llm = HuggingFacePipeline.from_model_id(model_id = model_name, β
β 24 β β β β β β β β β β β β task = "text-generation", model_kwargs β
β 25 β β β β β β β β β β β β "temperature" : 0.0, "max_length" : 204 β
β 26 β
β β
β c:\Program Files\Python38\lib\site-packages\langchain\llms\huggingface_pipeline.py:92 in β
β from_model_id β
β β
β 89 β β β
β 90 β β try: β
β 91 β β β if task == "text-generation": β
β β± 92 β β β β model = AutoModelForCausalLM.from_pretrained(model_id, **_model_kwargs) β
β 93 β β β elif task in ("text2text-generation", "summarization"): β
β 94 β β β β model = AutoModelForSeq2SeqLM.from_pretrained(model_id, **_model_kwargs) β
β 95 β β β else: β
β β
β c:\Program Files\Python38\lib\site-packages\transformers\models\auto\auto_factory.py:467 in β
β from_pretrained β
β β
β 464 β β β ) β
β 465 β β elif type(config) in cls._model_mapping.keys(): β
β 466 β β β model_class = _get_model_class(config, cls._model_mapping) β
β β± 467 β β β return model_class.from_pretrained( β
β 468 β β β β pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, β
β 469 β β β ) β
β 470 β β raise ValueError( β
β β
β c:\Program Files\Python38\lib\site-packages\transformers\modeling_utils.py:2777 in β
β from_pretrained β
β β
β 2774 β β β β mismatched_keys, β
β 2775 β β β β offload_index, β
β 2776 β β β β error_msgs, β
β β± 2777 β β β ) = cls._load_pretrained_model( β
β 2778 β β β β model, β
β 2779 β β β β state_dict, β
β 2780 β β β β loaded_state_dict_keys, # XXX: rename? β
β β
β c:\Program Files\Python38\lib\site-packages\transformers\modeling_utils.py:2871 in β
β _load_pretrained_model β
β β
β 2868 β β β ) β
β 2869 β β β is_safetensors = archive_file.endswith(".safetensors") β
β 2870 β β β if offload_folder is None and not is_safetensors: β
β β± 2871 β β β β raise ValueError( β
β 2872 β β β β β "The current device_map
had weights offloaded to the disk. Please β
β 2873 β β β β β " for them. Alternatively, make sure you have safetensors
installe β
β 2874 β β β β β " offers the weights in this format." β
β°βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ―
ValueError: The current device_map
had weights offloaded to the disk. Please provide an offload_folder
for them. Alternatively, make sure you have safetensors
installed if the model you are using offers
the weights in this format.
Thanks a lot in advance!!