@swapai/core 0.2.0 → 0.2.2
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/README.md +8 -0
- package/dist/index.js +285 -63
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/python/swapai_worker.py +31 -1
package/package.json
CHANGED
package/python/swapai_worker.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
import argparse
|
|
5
5
|
import json
|
|
6
|
+
import math
|
|
6
7
|
import os
|
|
7
8
|
import sqlite3
|
|
8
9
|
import sys
|
|
@@ -64,8 +65,31 @@ def train(args: argparse.Namespace) -> None:
|
|
|
64
65
|
checkpoint = checkpoint_dir / "needle2.pkl"
|
|
65
66
|
output = Path(args.output).resolve()
|
|
66
67
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
68
|
+
training_input = sys.stdin.read()
|
|
69
|
+
number_labels: dict[str, Any] | None = None
|
|
70
|
+
if args.numeric_labels_from_stdin:
|
|
71
|
+
labels_json, separator, training_input = training_input.partition("\n")
|
|
72
|
+
if not separator:
|
|
73
|
+
raise RuntimeError("Numeric label map is missing")
|
|
74
|
+
labels = json.loads(labels_json)
|
|
75
|
+
values = labels.get("values") if isinstance(labels, dict) else None
|
|
76
|
+
if (
|
|
77
|
+
not isinstance(labels, dict)
|
|
78
|
+
or labels.get("format") != 1
|
|
79
|
+
or not isinstance(values, list)
|
|
80
|
+
or not values
|
|
81
|
+
or any(
|
|
82
|
+
not isinstance(value, (int, float))
|
|
83
|
+
or isinstance(value, bool)
|
|
84
|
+
or not math.isfinite(value)
|
|
85
|
+
for value in values
|
|
86
|
+
)
|
|
87
|
+
or values != sorted(set(values))
|
|
88
|
+
):
|
|
89
|
+
raise RuntimeError("Numeric label map has an invalid format")
|
|
90
|
+
number_labels = labels
|
|
67
91
|
training_data = Path(args.training_data).resolve()
|
|
68
|
-
training_data.write_text(
|
|
92
|
+
training_data.write_text(training_input, encoding="utf-8")
|
|
69
93
|
adapter = output.parent / "swapai-lora.pkl"
|
|
70
94
|
with training_data.open("r", encoding="utf-8") as handle:
|
|
71
95
|
example_count = sum(1 for line in handle if line.strip())
|
|
@@ -102,6 +126,11 @@ def train(args: argparse.Namespace) -> None:
|
|
|
102
126
|
)
|
|
103
127
|
if not output.is_file():
|
|
104
128
|
raise RuntimeError("Needle did not create the requested .cact model")
|
|
129
|
+
if number_labels is not None:
|
|
130
|
+
Path(f"{output}.numbers.json").write_text(
|
|
131
|
+
json.dumps(number_labels, separators=(",", ":")),
|
|
132
|
+
encoding="utf-8",
|
|
133
|
+
)
|
|
105
134
|
|
|
106
135
|
|
|
107
136
|
def classification_result(response: Any) -> Any:
|
|
@@ -179,6 +208,7 @@ def parser() -> argparse.ArgumentParser:
|
|
|
179
208
|
train_parser.add_argument("--main-database", required=True)
|
|
180
209
|
train_parser.add_argument("--classifier-name", required=True)
|
|
181
210
|
train_parser.add_argument("--expected-epoch", type=int, required=True)
|
|
211
|
+
train_parser.add_argument("--numeric-labels-from-stdin", action="store_true")
|
|
182
212
|
|
|
183
213
|
serve_parser = commands.add_parser("serve")
|
|
184
214
|
serve_parser.add_argument("--model", required=True)
|