Mehdi-Zogh commited on
Commit
1f0d6d7
verified
1 Parent(s): 2b153a3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -43
README.md CHANGED
@@ -54,51 +54,28 @@ It can serve as a base model for further alignment, personalization, or integrat
54
  ## Get Started with the Model
55
 
56
  ```python
57
- from transformers import AutoModelForCausalLM, AutoTokenizer
58
-
59
- model_name = "Mehdi-Zogh/MNLP_M3_dpo_model"
60
-
61
- # load the tokenizer and the model
62
- tokenizer = AutoTokenizer.from_pretrained(model_name)
63
- model = AutoModelForCausalLM.from_pretrained(
64
- model_name,
65
- torch_dtype="auto",
66
- device_map="auto"
 
 
 
 
 
 
 
67
  )
68
 
69
- # prepare the model input
70
- prompt = "explain gradient descent in simple terms."
71
- messages = [
72
- {"role": "user", "content": prompt}
73
- ]
74
- text = tokenizer.apply_chat_template(
75
- messages,
76
- tokenize=False,
77
- add_generation_prompt=True,
78
- enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
79
- )
80
- model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
81
-
82
- # conduct text completion
83
- generated_ids = model.generate(
84
- **model_inputs,
85
- max_new_tokens=32768
86
- )
87
- output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
88
-
89
- # parsing thinking content
90
- try:
91
- # rindex finding 151668 (</think>)
92
- index = len(output_ids) - output_ids[::-1].index(151668)
93
- except ValueError:
94
- index = 0
95
-
96
- thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
97
- content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
98
-
99
- print("thinking content:", thinking_content)
100
- print("content:", content)
101
-
102
  ```
103
 
104
 
 
54
  ## Get Started with the Model
55
 
56
  ```python
57
+ prompt = "What are the phases of cell division?"
58
+
59
+ # Load tokenizer and model
60
+ tokenizer = AutoTokenizer.from_pretrained("Mehdi-Zogh/MNLP_M3_dpo_model", trust_remote_code=True)
61
+ model = AutoModelForCausalLM.from_pretrained("Mehdi-Zogh/MNLP_M3_dpo_model", device_map="auto", trust_remote_code=True)
62
+
63
+ # Tokenize
64
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
65
+
66
+ # Generate response
67
+ outputs = model.generate(
68
+ **inputs,
69
+ max_new_tokens=500,
70
+ temperature=0.7,
71
+ top_p=0.9,
72
+ do_sample=True,
73
+ eos_token_id=tokenizer.eos_token_id,
74
  )
75
 
76
+ # Decode and print
77
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
78
+ print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  ```
80
 
81