# Error: AttributeError: 'NoneType' object has no attribute 'shape' when prompt tuning with Chatglm2

**URL:** <https://discuss.huggingface.co/t/error-attributeerror-nonetype-object-has-no-attribute-shape-when-prompt-tuning-with-chatglm2/57851>\
**Category:** Beginners\
**Created:** [October 9, 2023, 5:40am UTC](https://discuss.huggingface.co/t/error-attributeerror-nonetype-object-has-no-attribute-shape-when-prompt-tuning-with-chatglm2/57851 "2023-10-09T05:40:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joey3000](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@Joey3000](https://discuss.huggingface.co/u/Joey3000)\
**Post date:** [October 9, 2023, 5:40am UTC](https://discuss.huggingface.co/t/error-attributeerror-nonetype-object-has-no-attribute-shape-when-prompt-tuning-with-chatglm2/57851/1 "2023-10-09T05:40:22Z")

</div>

I modified simple code of peft to train chatglm2-6b witn prompt-tuning.  
Below is my code:  
from transformers import AutoModelForCausalLM

from peft import get\_peft\_config, get\_peft\_model, PromptTuningInit, PromptTuningConfig, TaskType, PeftType

import torch

from datasets import load\_dataset

import os

from transformers import AutoTokenizer

from torch.utils.data import DataLoader

from transformers import default\_data\_collator, get\_linear\_schedule\_with\_warmup

from tqdm import tqdm

from datasets import load\_dataset

device = “cuda”

#model\_name\_or\_path = “bigscience/bloomz-560m”  
#tokenizer\_name\_or\_path = “bigscience/bloomz-560m”  
model\_name\_or\_path = “./chatglm2-6b”  
tokenizer\_name\_or\_path = “./chatglm2-6b”

peft\_config = PromptTuningConfig(  
task\_type=TaskType.CAUSAL\_LM,  
prompt\_tuning\_init=PromptTuningInit.RANDOM,  
num\_virtual\_tokens=8,  
)

dataset\_name = “twitter\_complaints”

text\_column = “Tweet text”  
label\_column = “text\_label”  
max\_length = 64  
lr = 3e-2  
num\_epochs = 10  
batch\_size = 8

from datasets import load\_dataset

dataset = load\_dataset(“ought/raft”, dataset\_name)

classes = [k.replace(“\_”, " ") for k in dataset[“train”].features[“Label”].names]  
print(classes)

dataset = dataset.map(  
lambda x: {“text\_label”: [classes[label] for label in x[“Label”]]},  
batched=True,  
num\_proc=1,  
)  
print(dataset)

dataset[“train”][0]

# data preprocessing

tokenizer = AutoTokenizer.from\_pretrained(model\_name\_or\_path, trust\_remote\_code=True)  
if tokenizer.pad\_token\_id is None:  
tokenizer.pad\_token\_id = tokenizer.eos\_token\_id

target\_max\_length = max([len(tokenizer(class\_label)[“input\_ids”]) for class\_label in classes])  
print(“target\_max\_length:”, target\_max\_length)

# 预处理

def preprocess\_function(examples):  
batch\_size = len(examples[text\_column])  
print(“batch\_size:”, batch\_size)

```
inputs = [f"{text_column} : {x} Label : " for x in examples[text_column]]
targets = [str(x) for x in examples[label_column]]

model_inputs = tokenizer(inputs, padding='max_length', truncation=True, max_length=max_length)
labels = tokenizer(targets, padding='max_length', truncation=True, max_length=max_length)

for i in range(batch_size):
    sample_input_ids = model_inputs["input_ids"][i]
    label_input_ids = labels["input_ids"][i] + [tokenizer.pad_token_id]
    if i == 0:
        print(i, sample_input_ids, label_input_ids)
    model_inputs["input_ids"][i] = sample_input_ids + label_input_ids
    labels["input_ids"][i] = [-100] * len(sample_input_ids) + label_input_ids
    model_inputs["attention_mask"][i] = [1] * len(model_inputs["input_ids"][i])
#print(model_inputs)

for i in range(batch_size):
    sample_input_ids = model_inputs["input_ids"][i]
    label_input_ids = labels["input_ids"][i]
    
    model_inputs["input_ids"][i] = [tokenizer.pad_token_id] * (max_length - len(sample_input_ids)) + sample_input_ids
    model_inputs["attention_mask"][i] = [0] * (max_length - len(sample_input_ids)) + model_inputs["attention_mask"][i]
    labels["input_ids"][i] = [-100] * (max_length - len(sample_input_ids)) + label_input_ids
    
    model_inputs["input_ids"][i] = torch.tensor(model_inputs["input_ids"][i][:max_length])
    model_inputs["attention_mask"][i] = torch.tensor(model_inputs["attention_mask"][i][:max_length])
    labels["input_ids"][i] = torch.tensor(labels["input_ids"][i][:max_length])
    if i == 0:
        print("model_inputs input_ids:", model_inputs["input_ids"][i])
        print("model_inputs attention_mask:", model_inputs["attention_mask"][i])
        print("labels input_ids:", labels["input_ids"][i])

    
model_inputs["labels"] = labels["input_ids"]
return model_inputs

```

print(“column\_names:”, dataset[“train”].column\_names)

# 将原始的训练和测试数据同时预处理，然后作为训练和评估数据集

processed\_datasets = dataset.map(  
preprocess\_function,  
batched=True,  
num\_proc=1,  
remove\_columns=dataset[“train”].column\_names,  
load\_from\_cache\_file=False,  
desc=“Running tokenizer on dataset”,  
)

train\_dataset = processed\_datasets[“train”]  
eval\_dataset = processed\_datasets[“train”]

# 训练与评估使用同一份数据，但是训练数据打乱

train\_dataloader = DataLoader(train\_dataset, shuffle=True, collate\_fn=default\_data\_collator, batch\_size=batch\_size, pin\_memory=True)  
eval\_dataloader = DataLoader(eval\_dataset, collate\_fn=default\_data\_collator, batch\_size=batch\_size, pin\_memory=True)  
print(len(train\_dataloader))  
print(len(eval\_dataloader))

def test\_preprocess\_function(examples):  
batch\_size = len(examples[text\_column])  
inputs = [f"{text\_column} : {x} Label : " for x in examples[text\_column]]  
model\_inputs = tokenizer(inputs, padding=‘max\_length’, truncation=True, max\_length=max\_length)  
# print(model\_inputs)  
for i in range(batch\_size):  
sample\_input\_ids = model\_inputs[“input\_ids”][i]

```
    model_inputs["input_ids"][i] = [tokenizer.pad_token_id] * ( max_length - len(sample_input_ids)) + sample_input_ids
    model_inputs["attention_mask"][i] = [0] * (max_length - len(sample_input_ids)) + model_inputs["attention_mask"][i]
    
    model_inputs["input_ids"][i] = torch.tensor(model_inputs["input_ids"][i][:max_length])
    model_inputs["attention_mask"][i] = torch.tensor(model_inputs["attention_mask"][i][:max_length])
return model_inputs

```

# 将原始的测试数据用于测试

test\_dataset = dataset[“test”].map(  
test\_preprocess\_function,  
batched=True,  
num\_proc=1,  
remove\_columns=dataset[“train”].column\_names,  
load\_from\_cache\_file=False,  
desc=“Running tokenizer on dataset”,  
)

test\_dataloader = DataLoader(test\_dataset, collate\_fn=default\_data\_collator, batch\_size=batch\_size, pin\_memory=True)  
next(iter(test\_dataloader))

# creating model

model = AutoModelForCausalLM.from\_pretrained(model\_name\_or\_path, trust\_remote\_code=True)

model = get\_peft\_model(model, peft\_config)

model.print\_trainable\_parameters()

# model

# optimizer and lr scheduler

optimizer = torch.optim.AdamW(model.parameters(), lr=lr)  
lr\_scheduler = get\_linear\_schedule\_with\_warmup(  
optimizer=optimizer,  
num\_warmup\_steps=0,  
num\_training\_steps=(len(train\_dataloader) \* num\_epochs),  
)

# training and evaluation

model = model.to(device)

for epoch in range(num\_epochs):  
model.train()  
total\_loss = 0  
for step, batch in enumerate(tqdm(train\_dataloader)):  
batch = {k: v.to(device) for k, v in batch.items()}  
print(batch)  
print(batch[“input\_ids”].shape)  
outputs = model(\*\*batch)  
loss = outputs.loss  
total\_loss += loss.detach().float()  
loss.backward()  
optimizer.step()  
lr\_scheduler.step()  
optimizer.zero\_grad()

```
model.eval()
eval_loss = 0
eval_preds = []
for step, batch in enumerate(tqdm(eval_dataloader)):
    batch = {k: v.to(device) for k, v in batch.items()}
    with torch.no_grad():
        outputs = model(**batch)
    loss = outputs.loss
    eval_loss += loss.detach().float()
    eval_preds.extend(
        tokenizer.batch_decode(torch.argmax(outputs.logits, -1).detach().cpu().numpy(), skip_special_tokens=True)
    )

eval_epoch_loss = eval_loss / len(eval_dataloader)
eval_ppl = torch.exp(eval_epoch_loss)
train_epoch_loss = total_loss / len(train_dataloader)
train_ppl = torch.exp(train_epoch_loss)
print(f"{epoch=}: {train_ppl=} {train_epoch_loss=} {eval_ppl=} {eval_epoch_loss=}")

```

But I got below error message:  
` 0%| | 0/7 [00:00<?, ?it/s]/anaconda/envs/llm/lib/python3.8/site-packages/peft/peft_model.py:936: UserWarning: Position ids are not supported for parameter efficient tuning. Ignoring position ids. warnings.warn("Position ids are not supported for parameter efficient tuning. Ignoring position ids.") 0%| | 0/7 [00:00<?, ?it/s]` `{'input_ids': tensor([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 19141, 21226, 30992, 14771, 289, 2205, 356, 2540, 307, 683, 1126, 13085, 263, 1929, 12416, 1126, 29114, 2886, 1214, 30912, 30930, 2074, 30967, 30972, 30938, 31015, 30936, 30970, 30966, 30916, 704, 30915, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 1989, 30926, 1102, 309, 5258, 766, 4402, 267, 7401, 332, 496, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 1989, 30936, 277, 25953, 30947, 3034, 363, 1266, 30953, 30917, 475, 4367, 289, 2396, 2466, 10540, 30987, 17110, 29419, 810, 343, 878, 30930, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 1989, 5907, 1076, 8320, 16689, 316, 3873, 1709, 878, 9687, 293, 4089, 16036, 498, 9829, 2520, 1431, 30910, 30943, 30940, 30940, 1233, 30930, 3122, 323, 434, 30930, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 1989, 30960, 275, 3660, 26822, 650, 383, 344, 16176, 623, 10072, 8305, 332, 3637, 1319, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 839, 307, 457, 30953, 30912, 634, 552, 30910, 30966, 4441, 5493, 290, 1989, 1122, 1567, 1556, 30921, 263, 1428, 1122, 1567, 289, 636, 1661, 307, 30953, 30924, 883, 278, 4382, 576, 30930, 666, 323, 260, 30353, 291, 552, 13981, 30930, 2260, 1397, 1989, 30949, 594, 1989, 30949, 594, 8332, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 1989, 30956, 30944, 8654, 15861, 376, 1477, 434, 323, 552, 726, 1672, 21945, 1363, 30910], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64790, 64792, 21184, 2254, 1363, 1989, 1480, 30914, 30962, 11563, 1989, 9267, 2112, 475, 9255, 323, 9829, 13139, 323, 2834, 293, 940, 803, 2991, 23430, 30930, 3286, 354, 1811, 354, 30953, 30917, 1994, 3624, 21945, 1363, 30910]], device='cuda:0'), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], device='cuda:0'), 'position_ids': tensor([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]], device='cuda:0'), 'labels': tensor([[-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100], [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100]], device='cuda:0')} torch.Size([8, 64])` `---------------------------------------------------------------------------  
AttributeError Traceback (most recent call last)  
Cell In[11], line 11  
9 print(batch)  
10 print(batch[“input\_ids”].shape)  
—\> 11 outputs = model(\*\*batch)  
12 loss = outputs.loss  
13 total\_loss += loss.detach().float()

File /anaconda/envs/llm/lib/python3.8/site-packages/torch/nn/modules/module.py:1501, in Module.\_call\_impl(self, \*args, \*\*kwargs)  
1496 # If we don’t have any hooks, we want to skip the rest of the logic in  
1497 # this function, and just call forward.  
1498 if not (self.\_backward\_hooks or self.\_backward\_pre\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks  
1499 or \_global\_backward\_pre\_hooks or \_global\_backward\_hooks  
1500 or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks):  
 → 1501 return forward\_call(\*args, \*\*kwargs)  
1502 # Do not call functions when jit is used  
1503 full\_backward\_hooks, non\_full\_backward\_hooks = ,

File /anaconda/envs/llm/lib/python3.8/site-packages/peft/peft\_model.py:966, in PeftModelForCausalLM.forward(self, input\_ids, attention\_mask, inputs\_embeds, labels, output\_attentions, output\_hidden\_states, return\_dict, \*\*kwargs)  
964 prompts = prompts.to(inputs\_embeds.dtype)  
965 inputs\_embeds = torch.cat((prompts, inputs\_embeds), dim=1)  
 → 966 return self.base\_model(inputs\_embeds=inputs\_embeds, \*\*kwargs)

File /anaconda/envs/llm/lib/python3.8/site-packages/torch/nn/modules/module.py:1501, in Module.\_call\_impl(self, \*args, \*\*kwargs)  
1496 # If we don’t have any hooks, we want to skip the rest of the logic in  
1497 # this function, and just call forward.  
1498 if not (self.\_backward\_hooks or self.\_backward\_pre\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks  
1499 or \_global\_backward\_pre\_hooks or \_global\_backward\_hooks  
1500 or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks):  
 → 1501 return forward\_call(\*args, \*\*kwargs)  
1502 # Do not call functions when jit is used  
1503 full\_backward\_hooks, non\_full\_backward\_hooks = ,

File ~/.cache/huggingface/modules/transformers\_modules/chatglm2-6b/modeling\_chatglm.py:934, in ChatGLMForConditionalGeneration.forward(self, input\_ids, position\_ids, attention\_mask, past\_key\_values, inputs\_embeds, labels, use\_cache, output\_attentions, output\_hidden\_states, return\_dict, return\_last\_logit)  
931 use\_cache = use\_cache if use\_cache is not None else self.config.use\_cache  
932 return\_dict = return\_dict if return\_dict is not None else self.config.use\_return\_dict  
 → 934 transformer\_outputs = self.transformer(  
935 input\_ids=input\_ids,  
936 position\_ids=position\_ids,  
937 attention\_mask=attention\_mask,  
938 past\_key\_values=past\_key\_values,  
939 inputs\_embeds=inputs\_embeds,  
940 use\_cache=use\_cache,  
941 output\_hidden\_states=output\_hidden\_states,  
942 return\_dict=return\_dict,  
943 )  
945 hidden\_states = transformer\_outputs[0]  
946 if return\_last\_logit:

File /anaconda/envs/llm/lib/python3.8/site-packages/torch/nn/modules/module.py:1501, in Module.\_call\_impl(self, \*args, \*\*kwargs)  
1496 # If we don’t have any hooks, we want to skip the rest of the logic in  
1497 # this function, and just call forward.  
1498 if not (self.\_backward\_hooks or self.\_backward\_pre\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks  
1499 or \_global\_backward\_pre\_hooks or \_global\_backward\_hooks  
1500 or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks):  
 → 1501 return forward\_call(\*args, \*\*kwargs)  
1502 # Do not call functions when jit is used  
1503 full\_backward\_hooks, non\_full\_backward\_hooks = ,

File ~/.cache/huggingface/modules/transformers\_modules/chatglm2-6b/modeling\_chatglm.py:804, in ChatGLMModel.forward(self, input\_ids, position\_ids, attention\_mask, full\_attention\_mask, past\_key\_values, inputs\_embeds, use\_cache, output\_hidden\_states, return\_dict)  
801 use\_cache = use\_cache if use\_cache is not None else self.config.use\_cache  
802 return\_dict = return\_dict if return\_dict is not None else self.config.use\_return\_dict  
 → 804 batch\_size, seq\_length = input\_ids.shape  
806 if inputs\_embeds is None:  
807 inputs\_embeds = self.embedding(input\_ids)

AttributeError: ‘NoneType’ object has no attribute ‘shape’`

---

<div class="post-metadata">

**Author:** ![lsxxhh](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@lsxxhh](https://discuss.huggingface.co/u/lsxxhh)\
**Post date:** [April 10, 2024, 7:19am UTC](https://discuss.huggingface.co/t/error-attributeerror-nonetype-object-has-no-attribute-shape-when-prompt-tuning-with-chatglm2/57851/2 "2024-04-10T07:19:15Z")

</div>

Have you solved this problem?（你解决这个问题了嘛？）

---

<div class="post-metadata">

**Author:** ![swtb](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@swtb](https://discuss.huggingface.co/u/swtb)\
**Post date:** [April 10, 2024, 8:13am UTC](https://discuss.huggingface.co/t/error-attributeerror-nonetype-object-has-no-attribute-shape-when-prompt-tuning-with-chatglm2/57851/3 "2024-04-10T08:13:45Z")

</div>

> [@Joey3000](#):
>
> remove\_columns=dataset[“train”].column\_names,

If I am not mistaken, this line would effectively drop all of the columns during the processing step. Which would cause a None Type to be passed in as inputs. Which is why they get the error about their inputsIds not having “shape” because they are NoneType
