boapps commited on
Commit
5eac576
1 Parent(s): bb9207a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +78 -0
README.md CHANGED
@@ -1,3 +1,81 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ datasets:
4
+ - boapps/alpaca-hu
5
+ - mlabonne/alpagasus
6
+ language:
7
+ - hu
8
+ library_name: transformers
9
+ pipeline_tag: text-generation
10
  ---
11
+
12
+ # szürkemarha-mistral v1
13
+
14
+ Ez az első (teszt) verziója egy magyar nyelvű instrukciókövető modellnek.
15
+
16
+ ## Használat
17
+
18
+ Ebben a repoban van egy `app.py` script, ami egy gradio felületet csinál a kényelmesebb használathoz.
19
+
20
+ Vagy kódból valahogy így:
21
+
22
+ ```python
23
+ import torch
24
+ from peft import PeftModel
25
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, GenerationConfig
26
+
27
+ tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1")
28
+
29
+ BASE_MODEL = "mistralai/Mistral-7B-v0.1"
30
+ LORA_WEIGHTS = "boapps/szurkemarha-mistral"
31
+
32
+ device = "cuda"
33
+
34
+ try:
35
+ if torch.backends.mps.is_available():
36
+ device = "mps"
37
+ except:
38
+ pass
39
+
40
+ nf4_config = BitsAndBytesConfig(
41
+ load_in_4bit=True,
42
+ bnb_4bit_quant_type="nf4",
43
+ bnb_4bit_use_double_quant=True,
44
+ bnb_4bit_compute_dtype=torch.bfloat16
45
+ )
46
+
47
+ model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, quantization_config=nf4_config)
48
+
49
+ model = PeftModel.from_pretrained(
50
+ model, LORA_WEIGHTS, torch_dtype=torch.float16, force_download=True
51
+ )
52
+
53
+ prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
54
+
55
+ ### Instruction:
56
+ Melyik megyében található az alábbi város?
57
+
58
+ ### Input:
59
+ Pécs
60
+
61
+ ### Response:"""
62
+ inputs = tokenizer(prompt, return_tensors="pt")
63
+ input_ids = inputs["input_ids"].to(device)
64
+ generation_config = GenerationConfig(
65
+ temperature=0.1,
66
+ top_p=0.75,
67
+ top_k=40,
68
+ num_beams=4,
69
+ )
70
+ with torch.no_grad():
71
+ generation_output = model.generate(
72
+ input_ids=input_ids,
73
+ generation_config=generation_config,
74
+ return_dict_in_generate=True,
75
+ output_scores=True,
76
+ max_new_tokens=256,
77
+ )
78
+ s = generation_output.sequences[0]
79
+ output = tokenizer.decode(s)
80
+ print(output.split("### Response:")[1].strip())
81
+ ```