#RuntimeError: Boolean value of Tensor with more than one value is ambiguous

6 messages · Page 1 of 1 (latest)

hollow lichenBOT
#

The Unsloth documentation I have ingested does not mention how to resolve a "RuntimeError: Boolean value of Tensor with more than one value is ambiguous" when fine-tuning Qwen/Qwen3-4B for a classification task. This error typically occurs in PyTorch when a tensor with more than one element is used in a context where a single boolean value is expected, such as an if statement or logical operation. You might want to provide the specific code block where the error occurs, especially any custom loss functions, data collators, or conditional statements involving tensors, as this will help pinpoint the issue. If this doesn't help, please reach out to the Unsloth support team for further assistance.

ember owl
#

Hi, I’m trying to fine-tune the “Qwen/Qwen3-4B” model for a classification task and got stuck on an issue.

First, let me tell about the dataset. The dataset contains 4 columns: “context”, “prompt”, “response”, and “label”. The goal of this task is to identify whether a response of LLM is “extrinsic”, “intrinsic”, or “no” given a prompt with context.

I have used Unsloth to fine-tune the “Qwen/Qwen3-4B” on Kaggle. I used the T4 GPU. My fine-tuned code is in the attached file.
I got this issue: RuntimeError: Boolean value of Tensor with more than one value is ambiguous
How do I fix this problem? Can anyone give me some advice?

hollow lichenBOT
#

Sure thing! I'm looking through the available data to answer your question. Hold on a second... :hourglass_flowing_sand:

ember owl
#

Here is my full code

#

This is my issue

#

@hollow lichen Can you help me address this problem?