AyoubChLin commited on
Commit
2dc04ac
·
verified ·
1 Parent(s): 7d26fff

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -12
README.md CHANGED
@@ -126,7 +126,11 @@ This is an illustration, not an evaluation. In deployment:
126
  Install a recent Transformers release:
127
 
128
  ```bash
129
- pip install -U "transformers>=5.2.0,<6" torch
 
 
 
 
130
  ```
131
 
132
  Then apply the checkpoint's native chat template:
@@ -135,24 +139,41 @@ Then apply the checkpoint's native chat template:
135
  import torch
136
  from transformers import AutoModelForCausalLM, AutoTokenizer
137
 
138
- model_id = "AyoubChLin/lfm2.5-2.6b-fable5-coding-agent"
 
 
139
 
140
- tokenizer = AutoTokenizer.from_pretrained(model_id)
141
  model = AutoModelForCausalLM.from_pretrained(
142
- model_id,
143
- dtype=torch.bfloat16,
144
- device_map="auto",
 
 
145
  )
 
146
  model.eval()
147
 
 
 
 
 
 
 
 
148
  messages = [
149
  {
150
  "role": "system",
151
- "content": "You are a careful coding assistant. Make focused changes and verify the result.",
 
 
 
152
  },
153
  {
154
  "role": "user",
155
- "content": "Write a tested Python function that merges overlapping integer intervals.",
 
 
 
156
  },
157
  ]
158
 
@@ -162,22 +183,34 @@ inputs = tokenizer.apply_chat_template(
162
  add_generation_prompt=True,
163
  return_tensors="pt",
164
  return_dict=True,
165
- ).to(model.device)
 
 
 
 
166
 
167
  with torch.inference_mode():
168
  output = model.generate(
169
  **inputs,
170
  max_new_tokens=768,
171
  do_sample=True,
172
- temperature=0.2,
173
  top_k=50,
174
  repetition_penalty=1.1,
 
175
  pad_token_id=tokenizer.pad_token_id,
176
  eos_token_id=tokenizer.eos_token_id,
177
  )
178
 
179
- new_tokens = output[0, inputs["input_ids"].shape[1]:]
180
- print(tokenizer.decode(new_tokens, skip_special_tokens=False))
 
 
 
 
 
 
 
181
  ```
182
 
183
  `skip_special_tokens=False` preserves native reasoning and tool-call delimiters for inspection by a compatible parser. Do not send raw reasoning or unvalidated tool syntax directly to end users or executors.
 
126
  Install a recent Transformers release:
127
 
128
  ```bash
129
+ %pip install -q --upgrade \
130
+ "transformers==5.15.0" \
131
+ "accelerate>=1.10,<2" \
132
+ "safetensors>=0.6" \
133
+ "huggingface_hub>=0.34"
134
  ```
135
 
136
  Then apply the checkpoint's native chat template:
 
139
  import torch
140
  from transformers import AutoModelForCausalLM, AutoTokenizer
141
 
142
+ MODEL_ID = "AyoubChLin/lfm2.5-2.6b-fable5-coding-agent"
143
+
144
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
145
 
 
146
  model = AutoModelForCausalLM.from_pretrained(
147
+ MODEL_ID,
148
+ dtype=torch.float16, # Important: T4 uses FP16, not BF16
149
+ device_map={"": 0}, # Keep the complete model on GPU 0
150
+ low_cpu_mem_usage=True,
151
+ attn_implementation="sdpa", # No external flash-attn installation
152
  )
153
+
154
  model.eval()
155
 
156
+ parameter = next(model.parameters())
157
+ print("Model device:", parameter.device)
158
+ print("Model dtype:", parameter.dtype)
159
+
160
+ assert parameter.device.type == "cuda"
161
+ assert parameter.dtype == torch.float16
162
+
163
  messages = [
164
  {
165
  "role": "system",
166
+ "content": (
167
+ "You are a careful coding assistant. Return complete, executable "
168
+ "code and briefly explain how it was verified."
169
+ ),
170
  },
171
  {
172
  "role": "user",
173
+ "content": (
174
+ "Write a Python function that merges overlapping integer intervals. "
175
+ "Include pytest tests."
176
+ ),
177
  },
178
  ]
179
 
 
183
  add_generation_prompt=True,
184
  return_tensors="pt",
185
  return_dict=True,
186
+ truncation=True,
187
+ max_length=8192, # Safe starting point for a T4
188
+ ).to("cuda:0")
189
+
190
+ prompt_length = inputs["input_ids"].shape[1]
191
 
192
  with torch.inference_mode():
193
  output = model.generate(
194
  **inputs,
195
  max_new_tokens=768,
196
  do_sample=True,
197
+ temperature=0.1,
198
  top_k=50,
199
  repetition_penalty=1.1,
200
+ use_cache=True,
201
  pad_token_id=tokenizer.pad_token_id,
202
  eos_token_id=tokenizer.eos_token_id,
203
  )
204
 
205
+ generated_tokens = output[0, prompt_length:]
206
+
207
+ print(
208
+ tokenizer.decode(
209
+ generated_tokens,
210
+ skip_special_tokens=False,
211
+ )
212
+ )
213
+
214
  ```
215
 
216
  `skip_special_tokens=False` preserves native reasoning and tool-call delimiters for inspection by a compatible parser. Do not send raw reasoning or unvalidated tool syntax directly to end users or executors.