When passing a tensor to the model, collecting the loss, and calling loss.backward(), i'm getting the error: Element 0 of tensors does not require grad and does not have a grad_fn
Here's a minimum reproduceable code:
from peft import PeftModel
from transformers import LLaMAForCausalLM
model = LLaMAForCausalLM.from_pretrained(
"decapoda-research/llama-7b-hf",
load_in_8bit=True,
device_map="auto",)
model = PeftModel.from_pretrained(model, "tloen/alpaca-lora-7b")
model(torch.ones(2, 2).type(torch.LongTensor), labels = torch.ones(2,2).type(torch.LongTensor)).loss
>>> tensor(50.9062, dtype=torch.float16)
where I expect the loss tensor to have a grad_fcn, and / or requires_grad=True.
like
from transformers import BertForSequenceClassification
>>> model = BertForSequenceClassification.from_pretrained("bert-base-uncased", return_dict=True)
>>> model(torch.ones(2,34).long(), labels = torch.ones(2,2)).loss
tensor(0.8236, grad_fn=<BinaryCrossEntropyWithLogitsBackward0>)
When passing a tensor to the model, collecting the loss, and calling
loss.backward()
, i'm getting the error:Element 0 of tensors does not require grad and does not have a grad_fn
Here's a minimum reproduceable code:
where I expect the loss tensor to have a grad_fcn, and / or
requires_grad=True
.like
from here
Please help me.