Smolagents Error: probability tensor contains either `inf`, `nan` or element < 0

I tried to migrate from HFApiModel to TransformerModel as I do not wish to incur more cost but I had this error. I am using ZeroGPU

  model = TransformersModel(
        # model_id="Qwen/Qwen2.5-Coder-14B-Instruct",
        model_id="meta-llama/Llama-3.2-3B-Instruct",
        device_map="cuda"
        ,max_new_tokens=5000,torch_dtype="bfloat16"
    )

I tried to solve it on my own via but the error persist. What else should I try?

1 Like

I think it’s the same kind of error as in the past, which can be avoided by quantization, and it’s interesting that it also occurs in float32.

I found a hypothesis that the cause may be a failure to tokenize a special token.

1 Like

interesting, now I tried unsloth llama 3.2 bnb 4bits and it threw another error:

RuntimeError: All input tensors need to be on the same GPU, but found some tensors to not be on a GPU:
[(torch.Size([1, 4718592]), device(type=‘cpu’)), (torch.Size([147456]), device(type=‘cpu’)), (torch.Size([3072, 3072]), device(type=‘cpu’))]

not sure how to change the input tensor into gpu. I am using stream_to_gradio() to send the new message to the agent.

I do thank you for your help.

edit:
not sure if this is the right path by doing

   model = TransformersModel(
        # model_id="Qwen/Qwen2.5-Coder-14B-Instruct",
        model_id="unsloth/Llama-3.2-3B-Instruct-unsloth-bnb-4bit",
        device_map="cuda"
    )
    model.model = model.model.to("cuda")

or

   model = TransformersModel(
        # model_id="Qwen/Qwen2.5-Coder-14B-Instruct",
        model_id="unsloth/Llama-3.2-3B-Instruct-unsloth-bnb-4bit",
        device_map="cuda"
    )
model.model.to("cuda")

edit: neither worked

1 Like

It’s been properly .to(model.device) ed…
I wonder if this is another bug.

How about like this?

   model = TransformersModel(
        # model_id="Qwen/Qwen2.5-Coder-14B-Instruct",
        model_id="unsloth/Llama-3.2-3B-Instruct-unsloth-bnb-4bit",
        device_map="cuda"
    )
print(model.model.device)
1 Like

Thanks for the help.

Here is the bug report that i created

1 Like

Good job!:hugs:

1 Like