@lzhzzzzwill/cofos 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cofos.js
CHANGED
|
@@ -175,8 +175,8 @@ function main() {
|
|
|
175
175
|
HF_HUB_ENABLE_HF_TRANSFER: process.env.HF_HUB_ENABLE_HF_TRANSFER || "0",
|
|
176
176
|
HF_HUB_DOWNLOAD_TIMEOUT: process.env.HF_HUB_DOWNLOAD_TIMEOUT || "120",
|
|
177
177
|
HF_HUB_ETAG_TIMEOUT: process.env.HF_HUB_ETAG_TIMEOUT || "30",
|
|
178
|
-
HF_HUB_VERBOSITY: process.env.HF_HUB_VERBOSITY || "
|
|
179
|
-
TRANSFORMERS_VERBOSITY: process.env.TRANSFORMERS_VERBOSITY || "
|
|
178
|
+
HF_HUB_VERBOSITY: process.env.HF_HUB_VERBOSITY || "error",
|
|
179
|
+
TRANSFORMERS_VERBOSITY: process.env.TRANSFORMERS_VERBOSITY || "error",
|
|
180
180
|
};
|
|
181
181
|
const proc = spawn(py, backendArgs, {
|
|
182
182
|
stdio: ["pipe", "pipe", "pipe"],
|
package/package.json
CHANGED
|
@@ -42,7 +42,7 @@ generation:
|
|
|
42
42
|
temperature: 0.2
|
|
43
43
|
top_p: 0.9
|
|
44
44
|
max_new_tokens: 1024
|
|
45
|
-
do_sample:
|
|
45
|
+
do_sample: false
|
|
46
46
|
repetition_penalty: 1.08
|
|
47
47
|
num_beams: 1
|
|
48
48
|
no_repeat_ngram_size: 0
|
|
@@ -51,6 +51,7 @@ generation:
|
|
|
51
51
|
refine_answers: false
|
|
52
52
|
stream_refinement: false
|
|
53
53
|
refinement_max_new_tokens: 512
|
|
54
|
+
remove_invalid_values: true
|
|
54
55
|
data_processing:
|
|
55
56
|
chunk_size: 768
|
|
56
57
|
chunk_overlap: 50
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"""Local student-model inference with optional confidence-gated KG/BM25 RAG."""
|
|
3
3
|
|
|
4
4
|
import logging
|
|
5
|
+
import os
|
|
5
6
|
import re
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
from threading import Thread
|
|
@@ -181,6 +182,7 @@ class StudentAdapterInference:
|
|
|
181
182
|
self.num_beams = int(generation_config.get("num_beams", 1))
|
|
182
183
|
self.no_repeat_ngram_size = int(generation_config.get("no_repeat_ngram_size", 0))
|
|
183
184
|
self.min_new_tokens = int(generation_config.get("min_new_tokens", 0))
|
|
185
|
+
self.remove_invalid_values = bool(generation_config.get("remove_invalid_values", True))
|
|
184
186
|
self.history_max_turns = int(generation_config.get("history_max_turns", 4))
|
|
185
187
|
self.refine_answers = bool(generation_config.get("refine_answers", True))
|
|
186
188
|
self.stream_refinement = bool(generation_config.get("stream_refinement", True))
|
|
@@ -224,17 +226,31 @@ class StudentAdapterInference:
|
|
|
224
226
|
|
|
225
227
|
@staticmethod
|
|
226
228
|
def _select_dtype() -> torch.dtype:
|
|
227
|
-
"""Pick
|
|
229
|
+
"""Pick a stable dtype for the current runtime.
|
|
228
230
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
CUDA can safely use bf16/fp16. On Mac/CPU, ``device_map=auto`` may place
|
|
232
|
+
layers on CPU or disk; fp16 there can produce NaN probabilities or
|
|
233
|
+
garbage tokens. Prefer float32 outside CUDA unless the user explicitly
|
|
234
|
+
opts into another dtype with COFOS_DTYPE.
|
|
231
235
|
"""
|
|
236
|
+
requested = os.environ.get("COFOS_DTYPE", "auto").strip().lower()
|
|
237
|
+
aliases = {
|
|
238
|
+
"fp32": torch.float32,
|
|
239
|
+
"float32": torch.float32,
|
|
240
|
+
"fp16": torch.float16,
|
|
241
|
+
"float16": torch.float16,
|
|
242
|
+
"bf16": torch.bfloat16,
|
|
243
|
+
"bfloat16": torch.bfloat16,
|
|
244
|
+
}
|
|
245
|
+
if requested in aliases:
|
|
246
|
+
return aliases[requested]
|
|
247
|
+
if requested not in {"", "auto"}:
|
|
248
|
+
logging.warning("Ignoring unsupported COFOS_DTYPE=%s; using auto", requested)
|
|
249
|
+
|
|
232
250
|
if torch.cuda.is_available():
|
|
233
251
|
if torch.cuda.is_bf16_supported():
|
|
234
252
|
return torch.bfloat16
|
|
235
253
|
return torch.float16
|
|
236
|
-
if torch.backends.mps.is_available():
|
|
237
|
-
return torch.float16
|
|
238
254
|
return torch.float32
|
|
239
255
|
|
|
240
256
|
def load_model(self) -> None:
|
|
@@ -283,6 +299,7 @@ class StudentAdapterInference:
|
|
|
283
299
|
"repetition_penalty": self.repetition_penalty,
|
|
284
300
|
"eos_token_id": self.tokenizer.eos_token_id,
|
|
285
301
|
"pad_token_id": self.tokenizer.pad_token_id,
|
|
302
|
+
"remove_invalid_values": self.remove_invalid_values,
|
|
286
303
|
}
|
|
287
304
|
if self.do_sample:
|
|
288
305
|
kwargs["temperature"] = self.temperature
|
package/scripts/chat.py
CHANGED
|
@@ -24,8 +24,8 @@ os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
|
|
|
24
24
|
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "0")
|
|
25
25
|
os.environ.setdefault("HF_HUB_DOWNLOAD_TIMEOUT", "120")
|
|
26
26
|
os.environ.setdefault("HF_HUB_ETAG_TIMEOUT", "30")
|
|
27
|
-
os.environ.setdefault("HF_HUB_VERBOSITY", "
|
|
28
|
-
os.environ.setdefault("TRANSFORMERS_VERBOSITY", "
|
|
27
|
+
os.environ.setdefault("HF_HUB_VERBOSITY", "error")
|
|
28
|
+
os.environ.setdefault("TRANSFORMERS_VERBOSITY", "error")
|
|
29
29
|
|
|
30
30
|
HISTORY_FILE = os.path.join(os.path.expanduser("~"), ".cofos_history.jsonl")
|
|
31
31
|
HISTORY_MAX_TURNS = 20
|
|
@@ -474,7 +474,7 @@ def main() -> None:
|
|
|
474
474
|
from inference.student_adapter_inference import StudentAdapterInference, StudentRAGContext
|
|
475
475
|
|
|
476
476
|
debug = os.environ.get("COFOS_DEBUG", "").lower() in {"1", "true", "yes", "on"}
|
|
477
|
-
log_level = logging.INFO if debug else logging.
|
|
477
|
+
log_level = logging.INFO if debug else logging.ERROR
|
|
478
478
|
logging.basicConfig(
|
|
479
479
|
level=log_level,
|
|
480
480
|
format="%(asctime)s - %(levelname)s - %(message)s",
|
|
@@ -586,7 +586,8 @@ def main() -> None:
|
|
|
586
586
|
answer = "".join(answer_parts)
|
|
587
587
|
gen_elapsed = time.time() - t_gen
|
|
588
588
|
print("\n===DONE===", flush=True)
|
|
589
|
-
|
|
589
|
+
if os.environ.get("COFOS_DEBUG", "").lower() in {"1", "true", "yes", "on"}:
|
|
590
|
+
print(f"[chat] Generated in {gen_elapsed:.1f}s", file=sys.stderr, flush=True)
|
|
590
591
|
|
|
591
592
|
# Persist both turns only once the answer completed, so an
|
|
592
593
|
# interrupted generation cannot leave a dangling user turn behind.
|
|
@@ -595,7 +596,8 @@ def main() -> None:
|
|
|
595
596
|
_save_turn("user", question)
|
|
596
597
|
_save_turn("assistant", answer)
|
|
597
598
|
except Exception as exc:
|
|
598
|
-
|
|
599
|
+
if os.environ.get("COFOS_DEBUG", "").lower() in {"1", "true", "yes", "on"}:
|
|
600
|
+
logging.exception("Generation failed")
|
|
599
601
|
print(f"\n[COFOS error] {exc}")
|
|
600
602
|
print("===DONE===", flush=True)
|
|
601
603
|
|