# ValueError: Please use the \`disk\_offload\` function instead

**URL:** <https://discuss.huggingface.co/t/valueerror-please-use-the-disk-offload-function-instead/103209>\
**Category:** Beginners\
**Created:** [August 20, 2024, 6:28pm UTC](https://discuss.huggingface.co/t/valueerror-please-use-the-disk-offload-function-instead/103209 "2024-08-20T18:28:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SunDay-s](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@SunDay-s](https://discuss.huggingface.co/u/SunDay-s)\
**Post date:** [August 20, 2024, 6:28pm UTC](https://discuss.huggingface.co/t/valueerror-please-use-the-disk-offload-function-instead/103209/1 "2024-08-20T18:28:37Z")

</div>

Here is the code:

```auto
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2-7B-Instruct",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-7B-Instruct")

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

```

here is the error:

```auto
Traceback (most recent call last):
  File "C:\Users\SunDay\Desktop\NelzGPT\main.py", line 4, in <module>
    model = AutoModelForCausalLM.from_pretrained(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SunDay\miniconda3\Lib\site-packages\transformers\models\auto\auto_factory.py", line 564, in from_pretrained
    return model_class.from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\SunDay\miniconda3\Lib\site-packages\transformers\modeling_utils.py", line 4015, in from_pretrained
    dispatch_model(model, **device_map_kwargs)
  File "C:\Users\SunDay\miniconda3\Lib\site-packages\accelerate\big_modeling.py", line 496, in dispatch_model
    raise ValueError(
ValueError: You are trying to offload the whole model to the disk. Please use the `disk_offload` function instead.

```

what to do?

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/52583_2.png) [@mahmutc](https://discuss.huggingface.co/u/mahmutc)\
**Post date:** [August 21, 2024, 9:38am UTC](https://discuss.huggingface.co/t/valueerror-please-use-the-disk-offload-function-instead/103209/2 "2024-08-21T09:38:52Z")

</div>

hi @SunDay-s  
I don’t know whether there is something wrong with device\_map or not.

Can you please try with another small model from [Templates for Chat Models](https://huggingface.co/docs/transformers/v4.44.1/chat_templating) ?

And you might find this one helpful [Resolving: ValueError: You are trying to offload the whole model to the disk. Please use the `disk_offload` function instead. | by Sridevi Panneerselvam | Medium](https://medium.com/@sridevi17j/resolving-valueerror-you-are-trying-to-offload-the-whole-model-to-the-disk-70d4e8138797)
