AbteeXAILabs commited on
Commit
98e8642
·
verified ·
1 Parent(s): 3c62372

Refresh GGUF quickstart runner

Browse files
Files changed (1) hide show
  1. quickstart.py +90 -30
quickstart.py CHANGED
@@ -24,9 +24,22 @@ def _build_parser() -> argparse.ArgumentParser:
24
  help="Start an interactive terminal chat instead of running a single prompt.",
25
  )
26
  parser.add_argument("--max-new-tokens", type=int, default=192)
 
27
  parser.add_argument("--temperature", type=float, default=0.1)
28
  parser.add_argument("--threads", type=int, default=max(1, os.cpu_count() or 1))
29
  parser.add_argument("--llama-cli", default="", help="Optional explicit path to llama-cli.")
 
 
 
 
 
 
 
 
 
 
 
 
30
  return parser
31
 
32
 
@@ -40,8 +53,8 @@ def _preferred_gguf(root: Path) -> Path:
40
  return gguf_candidates[0]
41
 
42
 
43
- def _local_model_path(model_path: Path) -> Path:
44
- if not str(model_path).startswith("\\"):
45
  return model_path
46
  local_app_data = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
47
  cache_dir = local_app_data / "tinyluminax" / "gguf-cache"
@@ -99,6 +112,7 @@ def _run_llama_cpp_python(
99
  system_prompt: str,
100
  user_prompt: str,
101
  max_new_tokens: int,
 
102
  temperature: float,
103
  threads: int,
104
  ) -> str:
@@ -106,7 +120,7 @@ def _run_llama_cpp_python(
106
 
107
  llm = Llama(
108
  model_path=str(model_path),
109
- n_ctx=8192,
110
  n_threads=threads,
111
  n_gpu_layers=0,
112
  chat_format="chat_template.default",
@@ -130,30 +144,41 @@ def _run_llama_cli(
130
  system_prompt: str,
131
  user_prompt: str,
132
  max_new_tokens: int,
 
133
  temperature: float,
134
  threads: int,
 
 
 
135
  ) -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  completed = subprocess.run(
137
- [
138
- str(llama_cli_path),
139
- "-m",
140
- str(model_path),
141
- "-sys",
142
- system_prompt,
143
- "-p",
144
- user_prompt,
145
- "-cnv",
146
- "-st",
147
- "-n",
148
- str(max_new_tokens),
149
- "--reasoning",
150
- "off",
151
- "--temp",
152
- str(temperature),
153
- "--threads",
154
- str(threads),
155
- "--no-display-prompt",
156
- ],
157
  check=False,
158
  capture_output=True,
159
  text=True,
@@ -177,15 +202,19 @@ def _run_interactive_llama_cpp_python(
177
  model_path: Path,
178
  system_prompt: str,
179
  max_new_tokens: int,
 
180
  temperature: float,
181
  threads: int,
182
  opening_prompt: str | None = None,
 
 
 
183
  ) -> None:
184
  from llama_cpp import Llama
185
 
186
  llm = Llama(
187
  model_path=str(model_path),
188
- n_ctx=8192,
189
  n_threads=threads,
190
  n_gpu_layers=0,
191
  chat_format="chat_template.default",
@@ -237,9 +266,13 @@ def _run_interactive_llama_cli(
237
  model_path: Path,
238
  system_prompt: str,
239
  max_new_tokens: int,
 
240
  temperature: float,
241
  threads: int,
242
  opening_prompt: str | None = None,
 
 
 
243
  ) -> None:
244
  print("LumynaX interactive terminal chat")
245
  print("Interactive mode already uses llama-cli directly. Use Ctrl+C to exit.")
@@ -252,14 +285,20 @@ def _run_interactive_llama_cli(
252
  "-cnv",
253
  "-n",
254
  str(max_new_tokens),
 
 
255
  "--reasoning",
256
- "off",
257
  "--temp",
258
  str(temperature),
259
  "--threads",
260
  str(threads),
261
  "--simple-io",
262
  ]
 
 
 
 
263
  if opening_prompt and opening_prompt.strip():
264
  command.extend(["-p", opening_prompt.strip()])
265
  completed = subprocess.run(command, check=False)
@@ -293,23 +332,31 @@ def main() -> None:
293
  )
294
  _run_interactive_llama_cli(
295
  llama_cli_path=llama_cli_path,
296
- model_path=source_model_path,
297
  system_prompt=system_prompt,
298
  opening_prompt=args.prompt,
299
  max_new_tokens=args.max_new_tokens,
 
300
  temperature=args.temperature,
301
  threads=args.threads,
 
 
 
302
  )
303
  return
304
- model_path = _local_model_path(source_model_path)
305
  try:
306
  _run_interactive_llama_cpp_python(
307
  model_path=model_path,
308
  system_prompt=system_prompt,
309
  opening_prompt=args.prompt,
310
  max_new_tokens=args.max_new_tokens,
 
311
  temperature=args.temperature,
312
  threads=args.threads,
 
 
 
313
  )
314
  return
315
  except Exception as exc: # noqa: BLE001
@@ -325,12 +372,16 @@ def main() -> None:
325
  )
326
  _run_interactive_llama_cli(
327
  llama_cli_path=llama_cli_path,
328
- model_path=source_model_path,
329
  system_prompt=system_prompt,
330
  opening_prompt=args.prompt,
331
  max_new_tokens=args.max_new_tokens,
 
332
  temperature=args.temperature,
333
  threads=args.threads,
 
 
 
334
  )
335
  return
336
  if explicit_cli_requested:
@@ -341,15 +392,19 @@ def main() -> None:
341
  )
342
  _run_llama_cli(
343
  llama_cli_path=llama_cli_path,
344
- model_path=source_model_path,
345
  system_prompt=system_prompt,
346
  user_prompt=single_prompt,
347
  max_new_tokens=args.max_new_tokens,
 
348
  temperature=args.temperature,
349
  threads=args.threads,
 
 
 
350
  )
351
  return
352
- model_path = _local_model_path(source_model_path)
353
  try:
354
  print(
355
  _run_llama_cpp_python(
@@ -357,6 +412,7 @@ def main() -> None:
357
  system_prompt=system_prompt,
358
  user_prompt=single_prompt,
359
  max_new_tokens=args.max_new_tokens,
 
360
  temperature=args.temperature,
361
  threads=args.threads,
362
  ),
@@ -380,8 +436,12 @@ def main() -> None:
380
  system_prompt=system_prompt,
381
  user_prompt=single_prompt,
382
  max_new_tokens=args.max_new_tokens,
 
383
  temperature=args.temperature,
384
  threads=args.threads,
 
 
 
385
  )
386
 
387
 
 
24
  help="Start an interactive terminal chat instead of running a single prompt.",
25
  )
26
  parser.add_argument("--max-new-tokens", type=int, default=192)
27
+ parser.add_argument("--ctx-size", type=int, default=4096)
28
  parser.add_argument("--temperature", type=float, default=0.1)
29
  parser.add_argument("--threads", type=int, default=max(1, os.cpu_count() or 1))
30
  parser.add_argument("--llama-cli", default="", help="Optional explicit path to llama-cli.")
31
+ parser.add_argument(
32
+ "--cache-local",
33
+ action="store_true",
34
+ help="Copy the GGUF into LOCALAPPDATA before running. Useful when a runtime cannot read network paths.",
35
+ )
36
+ parser.add_argument("--reasoning", choices=("on", "off", "auto"), default="off")
37
+ parser.add_argument(
38
+ "--reasoning-format",
39
+ choices=("auto", "none", "deepseek", "deepseek-legacy"),
40
+ default="auto",
41
+ )
42
+ parser.add_argument("--reasoning-budget", type=int, default=None)
43
  return parser
44
 
45
 
 
53
  return gguf_candidates[0]
54
 
55
 
56
+ def _local_model_path(model_path: Path, *, cache_local: bool = False) -> Path:
57
+ if not cache_local:
58
  return model_path
59
  local_app_data = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
60
  cache_dir = local_app_data / "tinyluminax" / "gguf-cache"
 
112
  system_prompt: str,
113
  user_prompt: str,
114
  max_new_tokens: int,
115
+ ctx_size: int,
116
  temperature: float,
117
  threads: int,
118
  ) -> str:
 
120
 
121
  llm = Llama(
122
  model_path=str(model_path),
123
+ n_ctx=ctx_size,
124
  n_threads=threads,
125
  n_gpu_layers=0,
126
  chat_format="chat_template.default",
 
144
  system_prompt: str,
145
  user_prompt: str,
146
  max_new_tokens: int,
147
+ ctx_size: int,
148
  temperature: float,
149
  threads: int,
150
+ reasoning: str,
151
+ reasoning_format: str,
152
+ reasoning_budget: int | None,
153
  ) -> None:
154
+ command = [
155
+ str(llama_cli_path),
156
+ "-m",
157
+ str(model_path),
158
+ "-sys",
159
+ system_prompt,
160
+ "-p",
161
+ user_prompt,
162
+ "-cnv",
163
+ "-st",
164
+ "-n",
165
+ str(max_new_tokens),
166
+ "-c",
167
+ str(ctx_size),
168
+ "--reasoning",
169
+ reasoning,
170
+ "--temp",
171
+ str(temperature),
172
+ "--threads",
173
+ str(threads),
174
+ "--no-display-prompt",
175
+ ]
176
+ if reasoning_format != "auto":
177
+ command.extend(["--reasoning-format", reasoning_format])
178
+ if reasoning_budget is not None:
179
+ command.extend(["--reasoning-budget", str(reasoning_budget)])
180
  completed = subprocess.run(
181
+ command,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  check=False,
183
  capture_output=True,
184
  text=True,
 
202
  model_path: Path,
203
  system_prompt: str,
204
  max_new_tokens: int,
205
+ ctx_size: int,
206
  temperature: float,
207
  threads: int,
208
  opening_prompt: str | None = None,
209
+ reasoning: str = "off",
210
+ reasoning_format: str = "auto",
211
+ reasoning_budget: int | None = None,
212
  ) -> None:
213
  from llama_cpp import Llama
214
 
215
  llm = Llama(
216
  model_path=str(model_path),
217
+ n_ctx=ctx_size,
218
  n_threads=threads,
219
  n_gpu_layers=0,
220
  chat_format="chat_template.default",
 
266
  model_path: Path,
267
  system_prompt: str,
268
  max_new_tokens: int,
269
+ ctx_size: int,
270
  temperature: float,
271
  threads: int,
272
  opening_prompt: str | None = None,
273
+ reasoning: str = "off",
274
+ reasoning_format: str = "auto",
275
+ reasoning_budget: int | None = None,
276
  ) -> None:
277
  print("LumynaX interactive terminal chat")
278
  print("Interactive mode already uses llama-cli directly. Use Ctrl+C to exit.")
 
285
  "-cnv",
286
  "-n",
287
  str(max_new_tokens),
288
+ "-c",
289
+ str(ctx_size),
290
  "--reasoning",
291
+ reasoning,
292
  "--temp",
293
  str(temperature),
294
  "--threads",
295
  str(threads),
296
  "--simple-io",
297
  ]
298
+ if reasoning_format != "auto":
299
+ command.extend(["--reasoning-format", reasoning_format])
300
+ if reasoning_budget is not None:
301
+ command.extend(["--reasoning-budget", str(reasoning_budget)])
302
  if opening_prompt and opening_prompt.strip():
303
  command.extend(["-p", opening_prompt.strip()])
304
  completed = subprocess.run(command, check=False)
 
332
  )
333
  _run_interactive_llama_cli(
334
  llama_cli_path=llama_cli_path,
335
+ model_path=_local_model_path(source_model_path, cache_local=args.cache_local),
336
  system_prompt=system_prompt,
337
  opening_prompt=args.prompt,
338
  max_new_tokens=args.max_new_tokens,
339
+ ctx_size=args.ctx_size,
340
  temperature=args.temperature,
341
  threads=args.threads,
342
+ reasoning=args.reasoning,
343
+ reasoning_format=args.reasoning_format,
344
+ reasoning_budget=args.reasoning_budget,
345
  )
346
  return
347
+ model_path = _local_model_path(source_model_path, cache_local=args.cache_local)
348
  try:
349
  _run_interactive_llama_cpp_python(
350
  model_path=model_path,
351
  system_prompt=system_prompt,
352
  opening_prompt=args.prompt,
353
  max_new_tokens=args.max_new_tokens,
354
+ ctx_size=args.ctx_size,
355
  temperature=args.temperature,
356
  threads=args.threads,
357
+ reasoning=args.reasoning,
358
+ reasoning_format=args.reasoning_format,
359
+ reasoning_budget=args.reasoning_budget,
360
  )
361
  return
362
  except Exception as exc: # noqa: BLE001
 
372
  )
373
  _run_interactive_llama_cli(
374
  llama_cli_path=llama_cli_path,
375
+ model_path=model_path,
376
  system_prompt=system_prompt,
377
  opening_prompt=args.prompt,
378
  max_new_tokens=args.max_new_tokens,
379
+ ctx_size=args.ctx_size,
380
  temperature=args.temperature,
381
  threads=args.threads,
382
+ reasoning=args.reasoning,
383
+ reasoning_format=args.reasoning_format,
384
+ reasoning_budget=args.reasoning_budget,
385
  )
386
  return
387
  if explicit_cli_requested:
 
392
  )
393
  _run_llama_cli(
394
  llama_cli_path=llama_cli_path,
395
+ model_path=_local_model_path(source_model_path, cache_local=args.cache_local),
396
  system_prompt=system_prompt,
397
  user_prompt=single_prompt,
398
  max_new_tokens=args.max_new_tokens,
399
+ ctx_size=args.ctx_size,
400
  temperature=args.temperature,
401
  threads=args.threads,
402
+ reasoning=args.reasoning,
403
+ reasoning_format=args.reasoning_format,
404
+ reasoning_budget=args.reasoning_budget,
405
  )
406
  return
407
+ model_path = _local_model_path(source_model_path, cache_local=args.cache_local)
408
  try:
409
  print(
410
  _run_llama_cpp_python(
 
412
  system_prompt=system_prompt,
413
  user_prompt=single_prompt,
414
  max_new_tokens=args.max_new_tokens,
415
+ ctx_size=args.ctx_size,
416
  temperature=args.temperature,
417
  threads=args.threads,
418
  ),
 
436
  system_prompt=system_prompt,
437
  user_prompt=single_prompt,
438
  max_new_tokens=args.max_new_tokens,
439
+ ctx_size=args.ctx_size,
440
  temperature=args.temperature,
441
  threads=args.threads,
442
+ reasoning=args.reasoning,
443
+ reasoning_format=args.reasoning_format,
444
+ reasoning_budget=args.reasoning_budget,
445
  )
446
 
447