Views
No views yet

1import torch
2from peft import PeftModel, PeftConfig
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5peft_model_id = "hackathon-somos-nlp-2023/salsapaca-native"
6config = PeftConfig.from_pretrained(peft_model_id)
7model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
8tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
9
10# Load the Lora model
11model = PeftModel.from_pretrained(model, peft_model_id)
12
13def gen_conversation(text):
14 text = "<SC>instruction: " + text + "\n "
15 batch = tokenizer(text, return_tensors='pt')
16 with torch.cuda.amp.autocast():
17 output_tokens = model.generate(**batch, max_new_tokens=256, eos_token_id=50258, early_stopping = True, temperature=.9)
18
19 print('\n\n', tokenizer.decode(output_tokens[0], skip_special_tokens=False))
20
21text = "hola"
22
23gen_conversation(text)
@misc {hackathon-somos-nlp-2023,
author = { {Edison Bejarano, Leonardo Bolaños, Alberto Ceballos, Santiago Pineda, Nicolay Potes} },
title = { SAlsapaca },
year = 2023,
url = { https://huggingface.co/hackathon-somos-nlp-2023/salsapaca-native }
publisher = { Hugging Face }
}