Unable to train safetensors format
I’m trying to create a lora for the model from an example CSV of data, but we’re getting this error:Traceback (most recent call last):
  File "/home/zino/apps/dload/main.py", line 49, in 
    model = AutoModelForSequenceClassification.from_pretrained(model_name)
  File "/home/zino/apps/dload/.venv/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 484, in from_pretrained
    return model_class.from_pretrained(
  File "/home/zino/apps/dload/.venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 2555, in from_pretrained
    raise EnvironmentError(
OSError: TheBloke/Nous-Hermes-13B-GPTQ does not appear to
have a file named pytorch_model.bin, tf_model.h5, model.ckpt or flax_model.msgpack.import pandas as pd
import torch
from torch.utils.data import Dataset, DataLoader
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AdamW
from transformers import AutoModelForCausalLM
import loralib as loraLoad CSV datadata = pd.read_csv(“data/guardian_articles.csv”)train_data = data.sample(frac=0.8, random_state=1)valid_data = data.drop(train_data.index)Load tokenizermodel_name = “TheBloke/Nous-Hermes-13B-GPTQ”#model_dir= “models/TheBloke_Nous-Hermes-13B-GPTQ”tokenizer = AutoTokenizer.from_pretrained(model_name)Tokenize datadef tokenize_data(data, tokenizer):text_data = [str(text) for text in data[“bodyContent”].tolist()]return tokenizer(text_data, padding=True, truncation=True, max_length=512)train_encodings = tokenize_data(train_data, tokenizer)valid_encodings = tokenize_data(valid_data, tokenizer)Custom dataset classclass CustomDataset(Dataset):definit(self, encodings, labels):self.encodings = encodingsself.labels = labelsdef __getitem__(self, idx):
    item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
    item["labels"] = torch.tensor(self.labels[idx])
    return item

def __len__(self):
    return len(self.labels)train_dataset = CustomDataset(train_encodings, train_data[“webTitle”].tolist())valid_dataset = CustomDataset(valid_encodings, valid_data[“webTitle”].tolist())DataLoaderstrain_loader = DataLoader(train_dataset, batch_size=8, shuffle=True)valid_loader = DataLoader(valid_dataset, batch_size=8, shuffle=False)Load pre-trained model#model= AutoModelForCausalLM.from_pretrained(model_name)model = AutoModelForSequenceClassification.from_pretrained(model_name)Apply LoRA to the modelrank = 16lora_model = lora.inject_lora(model, rank=rank)Mark only LoRA parameters as trainablelora.mark_only_lora_as_trainable(lora_model)Optimizeroptimizer = AdamW(lora_model.parameters(), lr=1e-5)Training loopnum_epochs = 3device = torch.device(“cuda” if torch.cuda.is_available() else “cpu”)lora_model.to(device)for epoch in range(num_epochs):lora_model.train()for batch in train_loader:optimizer.zero_grad()input_ids = batch[“input_ids”].to(device)attention_mask = batch[“attention_mask”].to(device)labels = batch[“labels”].to(device)outputs = lora_model(input_ids, attention_mask=attention_mask, labels=labels)
    loss = outputs.loss
    loss.backward()
    optimizer.step()Validation looplora_model.eval()total_predictions = 0correct_predictions = 0with torch.no_grad():for batch in valid_loader:input_ids = batch[“input_ids”].to(device)attention_mask = batch[“attention_mask”].to(device)labels = batch[“labels”].to(device)outputs = lora_model(input_ids, attention_mask=attention_mask)
    predictions = torch.argmax(outputs.logits, dim=1)

    total_predictions += labels.size(0)
    correct_predictions += (predictions == labels).sum().item()accuracy = correct_predictions / total_predictionsprint(f"Validation accuracy: {accuracy:.2f}")output_dir = “./lora_model”lora_model.save_pretrained(output_dir)Is it possible to use this format for training?