sapinedamo commited on
Commit
c0701e7
1 Parent(s): a9b3346

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -1
README.md CHANGED
@@ -10,4 +10,33 @@ license: apache-2.0
10
 
11
 
12
  ## Adapter Description
13
- This adapter was created with the [PEFT](https://github.com/huggingface/peft) library and allowed the base model *bertin-project/bertin-gpt-j-6B* to be fine-tuned on the *Spanish Alpaca Dataset* by using the method *LoRA*.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
 
12
  ## Adapter Description
13
+ This adapter was created with the [PEFT](https://github.com/huggingface/peft) library and allowed the base model *bertin-project/bertin-gpt-j-6B* to be fine-tuned on the *Spanish Alpaca Dataset* by using the method *LoRA*.
14
+
15
+
16
+ ## How to use
17
+ ```py
18
+ import torch
19
+ from peft import PeftModel, PeftConfig
20
+ from transformers import AutoModelForCausalLM, AutoTokenizer
21
+
22
+ peft_model_id = "hackathon-somos-nlp-2023/bertin-gpt-j-6B-es-finetuned-salpaca"
23
+ config = PeftConfig.from_pretrained(peft_model_id)
24
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
25
+ # tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
26
+ tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
27
+
28
+ # Load the Lora model
29
+ model = PeftModel.from_pretrained(model, peft_model_id)
30
+
31
+ def gen_conversation(text):
32
+ text = "<SC>instruction: " + text + "\n "
33
+ batch = tokenizer(text, return_tensors='pt')
34
+ with torch.cuda.amp.autocast():
35
+ output_tokens = model.generate(**batch, max_new_tokens=256, eos_token_id=50258, early_stopping = True, temperature=.9)
36
+
37
+ print('\n\n', tokenizer.decode(output_tokens[0], skip_special_tokens=False))
38
+
39
+ text = "hola"
40
+
41
+ gen_conversation(text)
42
+ ```