secemp9 commited on
Commit
6865e7b
·
verified ·
1 Parent(s): de89071

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +72 -0
README.md CHANGED
@@ -78,6 +78,78 @@ Solution:
78
 
79
  the output of the model doesn't have (for now) any formatting, it's just reasoning as output
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Axolotl config
82
 
83
  For this, I basically tried to convert my unsloth code to an axolotl config file. I also used deepspeed. Configuration below:
 
78
 
79
  the output of the model doesn't have (for now) any formatting, it's just reasoning as output
80
 
81
+ # Code Example
82
+
83
+ - Using transformers:
84
+ ```python
85
+ from transformers import AutoModelForCausalLM, AutoTokenizer
86
+ import torch
87
+
88
+ # Load the tokenizer and model
89
+ model_name = "secemp9/TraceBack-12b"
90
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
91
+ model = AutoModelForCausalLM.from_pretrained(model_name)
92
+
93
+ # Move the model to the desired device
94
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
95
+ model.to(device)
96
+
97
+ # Define the messages
98
+ messages = [
99
+ {"role": "user", "content": """Instruction:
100
+ how many r in strawberry
101
+
102
+
103
+ Solution:
104
+ There are **three** "r"s in "strawberry."
105
+ """}
106
+ ]
107
+
108
+ # Step 1: Apply chat template to get formatted text as a string
109
+ formatted_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
110
+
111
+ # Step 2: Tokenize the formatted text into a dictionary of tensors
112
+ inputs = tokenizer(formatted_text, return_tensors="pt").to(device)
113
+
114
+ # Generate the response
115
+ outputs = model.generate(**inputs, max_new_tokens=32000)
116
+
117
+ # Decode and print the output
118
+ generated_text = tokenizer.decode(outputs[0])
119
+ print(generated_text)
120
+ ```
121
+
122
+ - unsloth
123
+ ```python
124
+ from unsloth import FastLanguageModel
125
+
126
+ # Load the model and tokenizer
127
+ model, tokenizer = FastLanguageModel.from_pretrained("secemp9/TraceBack-12b")
128
+
129
+ # Define the messages (replace "stuff_here" with your actual input)
130
+ messages = [
131
+ {"role": "user", "content": """Instruction:
132
+ how many r in strawberry
133
+
134
+
135
+ Solution:
136
+ There are **three** "r"s in "strawberry."
137
+ """}
138
+ ]
139
+
140
+ # Step 1: Apply chat template to get formatted text as a string
141
+ formatted_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
142
+
143
+ # Step 2: Tokenize the formatted text into a dictionary of tensors
144
+ inputs = tokenizer(formatted_text, return_tensors="pt").to(model.device)
145
+
146
+ # Generate the response
147
+ outputs = model.generate(**inputs, max_new_tokens=32000)
148
+
149
+ # Decode and print the output
150
+ generated_text = tokenizer.decode(outputs[0])
151
+ print(generated_text)
152
+ ```
153
  # Axolotl config
154
 
155
  For this, I basically tried to convert my unsloth code to an axolotl config file. I also used deepspeed. Configuration below: