ruslanmv commited on
Commit
ec1b39e
1 Parent(s): da7d24f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +32 -47
README.md CHANGED
@@ -18,66 +18,51 @@ pip install -qU transformers==4.36.2 datasets python-dotenv peft bitsandbytes
18
  ## Example Usage
19
  ```python
20
 
21
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
22
 
23
  # Define the name of your fine-tuned model
24
  finetuned_model = 'ruslanmv/Medical-Mixtral-7B-v2k'
25
 
26
- # Load tokenizer
27
- tokenizer = AutoTokenizer.from_pretrained(finetuned_model, trust_remote_code=True)
28
-
29
- # Load the model with the provided adapter configuration and weights
30
- model_pretrained = AutoModelForCausalLM.from_pretrained(finetuned_model, trust_remote_code=True, torch_dtype=torch.float16)
31
-
32
- messages = [
33
- {'role': 'user', 'content': 'What should I do to reduce my weight gained due to genetic hypothyroidism?'},
34
- {'role': 'assistant', 'content': ''},
35
- ]
36
-
37
- input_ids = tokenizer.apply_chat_template(messages, return_tensors='pt').to('cuda')
38
- outputs = model_pretrained.generate(input_ids, max_new_tokens=500)
39
-
40
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
41
-
42
-
43
- ```
44
-
45
- For Gpus
46
- ```python
47
-
48
- # Define the name of your fine-tuned model
49
- finetuned_model = 'ruslanmv/{new_model}'
50
-
51
  # Load fine-tuned model
52
  bnb_config = BitsAndBytesConfig(
53
- load_in_4bit= True,
54
- bnb_4bit_quant_type= "nf4",
55
- bnb_4bit_compute_dtype= torch.bfloat16,
56
- bnb_4bit_use_double_quant= False,
57
  )
58
  model_pretrained = AutoModelForCausalLM.from_pretrained(
59
- finetuned_model,
60
- load_in_4bit=True,
61
- quantization_config=bnb_config,
62
- torch_dtype=torch.bfloat16,
63
- device_map="auto",
64
- trust_remote_code=True,
65
- cache_dir=cache_dir
66
  )
 
67
  # Load tokenizer
68
- tokenizer = AutoTokenizer.from_pretrained(finetuned_model,
69
- trust_remote_code=True,
70
- cache_dir=cache_dir)
71
- pipe = pipeline(task="text-generation",
72
- model=model_pretrained,
73
- tokenizer=tokenizer, max_length=200)
 
74
  def build_prompt(question):
75
- prompt=f"[INST]@Enlighten. {question} [/INST]"
76
- return prompt
77
 
78
- question = "What does abutment of the nerve root mean?"
79
  prompt = build_prompt(question)
80
- result = pipe(prompt)
 
 
 
 
 
 
 
 
81
 
82
 
83
  ```
 
18
  ## Example Usage
19
  ```python
20
 
21
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, logging, BitsAndBytesConfig
22
+ import os, torch
23
 
24
  # Define the name of your fine-tuned model
25
  finetuned_model = 'ruslanmv/Medical-Mixtral-7B-v2k'
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  # Load fine-tuned model
28
  bnb_config = BitsAndBytesConfig(
29
+ load_in_4bit=True,
30
+ bnb_4bit_quant_type="nf4",
31
+ bnb_4bit_compute_dtype=torch.bfloat16,
32
+ bnb_4bit_use_double_quant=False,
33
  )
34
  model_pretrained = AutoModelForCausalLM.from_pretrained(
35
+ finetuned_model,
36
+ load_in_4bit=True,
37
+ quantization_config=bnb_config,
38
+ torch_dtype=torch.bfloat16,
39
+ device_map="auto",
40
+ trust_remote_code=True
 
41
  )
42
+
43
  # Load tokenizer
44
+ tokenizer = AutoTokenizer.from_pretrained(finetuned_model, trust_remote_code=True)
45
+
46
+ # Set pad_token_id to eos_token_id
47
+ model_pretrained.config.pad_token_id = tokenizer.eos_token_id
48
+
49
+ pipe = pipeline(task="text-generation", model=model_pretrained, tokenizer=tokenizer, max_length=500)
50
+
51
  def build_prompt(question):
52
+ prompt = f"[INST]@Enlighten. [/INST] {question}"
53
+ return prompt
54
 
55
+ question = "Are my symptoms due to HIV infection? I had a high-risk exposure 15 months ago"
56
  prompt = build_prompt(question)
57
+
58
+ # Generate text based on the prompt
59
+ result = pipe(prompt)[0]
60
+ generated_text = result['generated_text']
61
+
62
+ # Remove the prompt from the generated text
63
+ generated_text = generated_text.replace(prompt, "", 1).strip()
64
+
65
+ print(generated_text)
66
 
67
 
68
  ```