MatNLP commited on
Commit
c614af5
1 Parent(s): 4530879

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -2
README.md CHANGED
@@ -1,5 +1,7 @@
1
  ---
2
  library_name: peft
 
 
3
  ---
4
  ## Training procedure
5
 
@@ -14,7 +16,54 @@ The following `bitsandbytes` quantization config was used during training:
14
  - bnb_4bit_quant_type: nf4
15
  - bnb_4bit_use_double_quant: False
16
  - bnb_4bit_compute_dtype: float16
17
- ### Framework versions
18
 
 
19
 
20
- - PEFT 0.4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: peft
3
+ language:
4
+ - pt
5
  ---
6
  ## Training procedure
7
 
 
16
  - bnb_4bit_quant_type: nf4
17
  - bnb_4bit_use_double_quant: False
18
  - bnb_4bit_compute_dtype: float16
 
19
 
20
+ ## Algoritmo para utilização do modelo
21
 
22
+ import torch
23
+ from peft import PeftModel, PeftConfig
24
+ from transformers import AutoModelForCausalLM,BitsAndBytesConfig,AutoTokenizer
25
+
26
+ #Quantização
27
+ use_4bit = True
28
+ bnb_4bit_compute_dtype = "float16"
29
+ bnb_4bit_quant_type = "nf4"
30
+ use_nested_quant = False
31
+
32
+
33
+ # Carrega o tokenizer e modelo com configuração QLoRA
34
+ compute_dtype = getattr(torch, bnb_4bit_compute_dtype)
35
+
36
+ bnb_config = BitsAndBytesConfig(load_in_4bit = use_4bit,
37
+ bnb_4bit_quant_type = bnb_4bit_quant_type,
38
+ bnb_4bit_compute_dtype = compute_dtype,
39
+ bnb_4bit_use_double_quant = use_nested_quant)
40
+
41
+
42
+ #Import do modelo
43
+ config = PeftConfig.from_pretrained("MatNLP/Sectrum")
44
+ base_model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-chat-hf",quantization_config = bnb_config)
45
+ model = PeftModel.from_pretrained(base_model, "MatNLP/Sectrum")
46
+
47
+
48
+ # Carrega o tokenizador
49
+ tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-chat-hf", trust_remote_code = True,skip_special_tokens=True)
50
+ tokenizer.pad_token = tokenizer.eos_token
51
+ tokenizer.padding_side = "right"
52
+
53
+
54
+ # Prepara o prompt
55
+ prompt = "Como proteger meu e-mail?"
56
+
57
+ # Cria o pipeline
58
+ pipe = pipeline(task = "text-generation",
59
+ model = model,
60
+ tokenizer = tokenizer,
61
+ max_length = 200)
62
+ #streamer=TextStreamer(tokenizer,skip_prompt=True)
63
+
64
+
65
+ # Executa o pipeline e gera o texto a partir do prompt inicial
66
+ resultado = pipe(f"<s>[INST] {prompt} [/INST]")
67
+
68
+
69
+ print(resultado[0]['generated_text'].split("[/INST]")[1].split('<\s>')[0])