# Attribute error "nonetype object has no shape"

**URL:** <https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775>\
**Category:** Beginners\
**Created:** [June 10, 2025, 1:13pm UTC](https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775 "2025-06-10T13:13:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samundiswary](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@samundiswary](https://discuss.huggingface.co/u/samundiswary)\
**Post date:** [June 10, 2025, 1:13pm UTC](https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775/1 "2025-06-10T13:13:41Z")

</div>

with torch.no\_grad(): output\_ids = model.generate( input\_ids=input\_ids, images=image\_tensor, max\_new\_tokens=256, do\_sample=True ) leads to attribute error none type object has no shape

print(“Prompt:”, prompt) print(“Type of input\_ids:”, input\_ids.dtype) print(“Shape of input\_ids before generate:”, input\_ids.shape) print(“Shape of image\_tensor:”, image\_tensor.shape) print(“Type of image\_tensor:”, image\_tensor.dtype) all print statement giving correct.could anyone suggest what leads to error.am doing inference check after finetuned multimodal model

---

<div class="post-metadata">

**Author:** ![Mdrnfox](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mdrnfox/32/47695_2.png) [@Mdrnfox](https://discuss.huggingface.co/u/Mdrnfox)\
**Post date:** [June 10, 2025, 1:59pm UTC](https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775/2 "2025-06-10T13:59:15Z")

</div>

You’re probably passing `images=image_tensor` into a model that **doesn’t expect** or properly handle that argument. Inside the `generate()` method, HuggingFace or custom model logic might be expecting the `images` argument to be processed by a `prepare_inputs_for_generation()` or `forward()` call — and if not correctly implemented, it returns `None`, causing the error when `.shape` is accessed.

Side possibility, does the model support multimodality?  
For example, a typical `AutoModelForCausalLM` does **not** support an `images` parameter.

Try this

`output_ids = model.generate(input_ids=input_ids, max_new_tokens=256, do_sample=True)`

If this works without error, your model or its generation path is not correctly set up to handle multimodal input.

Leave a like if this helped you at all 🙂

---

<div class="post-metadata">

**Author:** ![Pimpcat-AU](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pimpcat-au/32/48989_2.png) [@Pimpcat-AU](https://discuss.huggingface.co/u/Pimpcat-AU)\
**Post date:** [June 10, 2025, 8:37pm UTC](https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775/3 "2025-06-10T20:37:16Z")

</div>

Fix:  
You are passing images=image\_tensor to model.generate, but your model or generation config likely does not support the images argument—or your finetuned model doesn’t handle multimodal input as expected.

Direct script correction:

Try this: Remove images if the model doesn’t support multimodal inference  
output\_ids = model.generate(  
input\_ids=input\_ids,  
max\_new\_tokens=256,  
do\_sample=True  
)

If your model does support images, make sure image\_tensor is not None and is properly preprocessed. Otherwise, the error means image\_tensor is None when accessed inside the generate function.

Check:

assert image\_tensor is not None, “image\_tensor is None”

Solution provided by Triskel Data Deterministic AI.

---

<div class="post-metadata">

**Author:** ![samundiswary](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@samundiswary](https://discuss.huggingface.co/u/samundiswary)\
**Post date:** [June 11, 2025, 4:36am UTC](https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775/4 "2025-06-11T04:36:16Z")

</div>

liuhaotian/llava-v1.5-7b this is my base model i have fine tuned and pushed in huggingface.am giving input both image and text for inference check.please guide me

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [June 11, 2025, 6:05am UTC](https://discuss.huggingface.co/t/attribute-error-nonetype-object-has-no-shape/158775/5 "2025-06-11T06:05:21Z")

</div>

If you want to use images, it seems that you need to pass the `pixel_values` argument instead of the `images` argument for the LLaVa model.

> **[LLaVa](https://huggingface.co/docs/transformers/main/en/model_doc/llava)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

[https://stackoverflow.com/questions/1109422/getting-list-of-pixel-values-from-pil](https://stackoverflow.com/questions/1109422/getting-list-of-pixel-values-from-pil)
