@lzhzzzzwill/cofos 1.1.9 → 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/package.json
CHANGED
|
@@ -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
|
|
@@ -225,17 +226,31 @@ class StudentAdapterInference:
|
|
|
225
226
|
|
|
226
227
|
@staticmethod
|
|
227
228
|
def _select_dtype() -> torch.dtype:
|
|
228
|
-
"""Pick
|
|
229
|
+
"""Pick a stable dtype for the current runtime.
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
|
|
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.
|
|
232
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
|
+
|
|
233
250
|
if torch.cuda.is_available():
|
|
234
251
|
if torch.cuda.is_bf16_supported():
|
|
235
252
|
return torch.bfloat16
|
|
236
253
|
return torch.float16
|
|
237
|
-
if torch.backends.mps.is_available():
|
|
238
|
-
return torch.float16
|
|
239
254
|
return torch.float32
|
|
240
255
|
|
|
241
256
|
def load_model(self) -> None:
|