mrm8488 commited on
Commit
090d30d
1 Parent(s): 7d4764c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -1
README.md CHANGED
@@ -25,5 +25,23 @@ Dataset from [Workshop for NLP introduction with Spanish jokes](https://github.c
25
 
26
  ## How to use
27
  ```py
28
- # TODO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  ```
 
25
 
26
  ## How to use
27
  ```py
28
+ import torch
29
+ from peft import PeftModel, PeftConfig
30
+ from transformers import AutoModelForCausalLM, AutoTokenizer
31
+
32
+ peft_model_id = "mrm8488/bertin-gpt-j-6B-es-finetuned-chistes_spanish_jokes-500"
33
+ config = PeftConfig.from_pretrained(peft_model_id)
34
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=True, device_map='auto')
35
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
36
+
37
+ # Load the Lora model
38
+ model = PeftModel.from_pretrained(model, peft_model_id)
39
+
40
+ # Inference
41
+ batch = tokenizer("Esto son dos amigos", return_tensors='pt')
42
+
43
+ with torch.cuda.amp.autocast():
44
+ output_tokens = model.generate(**batch, max_new_tokens=50)
45
+
46
+ print('\n\n', tokenizer.decode(output_tokens[0], skip_special_tokens=True))
47
  ```