luminamoon 1.0.0__py3-none-any.whl
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.
- luminamoon/__init__.py +43 -0
- luminamoon/dataloader/__init__.py +38 -0
- luminamoon/dataloader/_ffi.py +300 -0
- luminamoon/dataloader/batch.py +433 -0
- luminamoon/dataloader/constants.py +245 -0
- luminamoon/dataloader/diagnostics.py +76 -0
- luminamoon/dataloader/hub.py +658 -0
- luminamoon/dataloader/loader.py +982 -0
- luminamoon/optimizer/__init__.py +5 -0
- luminamoon/optimizer/constants.py +37 -0
- luminamoon/optimizer/gpu_backend.py +3662 -0
- luminamoon/optimizer/luminav.py +1459 -0
- luminamoon/py.typed +1 -0
- luminamoon-1.0.0.dist-info/METADATA +174 -0
- luminamoon-1.0.0.dist-info/RECORD +17 -0
- luminamoon-1.0.0.dist-info/WHEEL +4 -0
- luminamoon-1.0.0.dist-info/licenses/LICENSE +13 -0
luminamoon/__init__.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .dataloader import (
|
|
4
|
+
DataBatch,
|
|
5
|
+
DataStreamLoader,
|
|
6
|
+
HfHubUploader,
|
|
7
|
+
MultimodalBatch,
|
|
8
|
+
MultimodalParquetLoader,
|
|
9
|
+
StreamCoordinate,
|
|
10
|
+
dataloader_cpu_isa,
|
|
11
|
+
expand_hf_sources,
|
|
12
|
+
from_hf_dataset,
|
|
13
|
+
interleave,
|
|
14
|
+
postprocess_and_dedup_records,
|
|
15
|
+
push_to_hub,
|
|
16
|
+
resolve_hf_secrets,
|
|
17
|
+
serialize_table_to_bytes,
|
|
18
|
+
stream,
|
|
19
|
+
suggest_closest_matches,
|
|
20
|
+
)
|
|
21
|
+
from .optimizer import LuminaV
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"DataBatch",
|
|
25
|
+
"DataStreamLoader",
|
|
26
|
+
"HfHubUploader",
|
|
27
|
+
"LuminaV",
|
|
28
|
+
"MultimodalBatch",
|
|
29
|
+
"MultimodalParquetLoader",
|
|
30
|
+
"StreamCoordinate",
|
|
31
|
+
"__version__",
|
|
32
|
+
"dataloader_cpu_isa",
|
|
33
|
+
"expand_hf_sources",
|
|
34
|
+
"from_hf_dataset",
|
|
35
|
+
"interleave",
|
|
36
|
+
"postprocess_and_dedup_records",
|
|
37
|
+
"push_to_hub",
|
|
38
|
+
"resolve_hf_secrets",
|
|
39
|
+
"serialize_table_to_bytes",
|
|
40
|
+
"stream",
|
|
41
|
+
"suggest_closest_matches",
|
|
42
|
+
]
|
|
43
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ._ffi import (
|
|
4
|
+
HfHubUploader,
|
|
5
|
+
StreamCoordinate,
|
|
6
|
+
dataloader_cpu_isa,
|
|
7
|
+
postprocess_and_dedup_records,
|
|
8
|
+
serialize_table_to_bytes,
|
|
9
|
+
suggest_closest_matches,
|
|
10
|
+
)
|
|
11
|
+
from .batch import DataBatch, MultimodalBatch
|
|
12
|
+
from .hub import expand_hf_sources, push_to_hub, resolve_hf_secrets
|
|
13
|
+
from .loader import (
|
|
14
|
+
DataStreamLoader,
|
|
15
|
+
MultimodalParquetLoader,
|
|
16
|
+
from_hf_dataset,
|
|
17
|
+
interleave,
|
|
18
|
+
stream,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"DataBatch",
|
|
23
|
+
"DataStreamLoader",
|
|
24
|
+
"HfHubUploader",
|
|
25
|
+
"MultimodalBatch",
|
|
26
|
+
"MultimodalParquetLoader",
|
|
27
|
+
"StreamCoordinate",
|
|
28
|
+
"dataloader_cpu_isa",
|
|
29
|
+
"expand_hf_sources",
|
|
30
|
+
"from_hf_dataset",
|
|
31
|
+
"interleave",
|
|
32
|
+
"postprocess_and_dedup_records",
|
|
33
|
+
"push_to_hub",
|
|
34
|
+
"resolve_hf_secrets",
|
|
35
|
+
"serialize_table_to_bytes",
|
|
36
|
+
"stream",
|
|
37
|
+
"suggest_closest_matches",
|
|
38
|
+
]
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from typing import TYPE_CHECKING, Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _py_damerau_levenshtein(a: str, b: str) -> int:
|
|
8
|
+
if a == b:
|
|
9
|
+
return 0
|
|
10
|
+
la, lb = len(a), len(b)
|
|
11
|
+
if la == 0:
|
|
12
|
+
return lb
|
|
13
|
+
if lb == 0:
|
|
14
|
+
return la
|
|
15
|
+
width = lb + 1
|
|
16
|
+
matrix = [0] * ((la + 1) * width)
|
|
17
|
+
for i in range(la + 1):
|
|
18
|
+
matrix[i * width] = i
|
|
19
|
+
for j in range(lb + 1):
|
|
20
|
+
matrix[j] = j
|
|
21
|
+
for i in range(1, la + 1):
|
|
22
|
+
for j in range(1, lb + 1):
|
|
23
|
+
cost = 0 if a[i - 1] == b[j - 1] else 1
|
|
24
|
+
best = min(
|
|
25
|
+
matrix[(i - 1) * width + j] + 1,
|
|
26
|
+
matrix[i * width + (j - 1)] + 1,
|
|
27
|
+
matrix[(i - 1) * width + (j - 1)] + cost,
|
|
28
|
+
)
|
|
29
|
+
if i > 1 and j > 1 and a[i - 1] == b[j - 2] and a[i - 2] == b[j - 1]:
|
|
30
|
+
best = min(best, matrix[(i - 2) * width + (j - 2)] + 1)
|
|
31
|
+
matrix[i * width + j] = best
|
|
32
|
+
return matrix[la * width + lb]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _py_find_closest_matches(
|
|
36
|
+
query: str,
|
|
37
|
+
candidates: Sequence[str],
|
|
38
|
+
max_results: int = 3,
|
|
39
|
+
) -> list[str]:
|
|
40
|
+
q = query.strip().lower()
|
|
41
|
+
if not q or max_results <= 0:
|
|
42
|
+
return []
|
|
43
|
+
q_len = len(q)
|
|
44
|
+
threshold = 1 if q_len <= 3 else (2 if q_len <= 6 else 3)
|
|
45
|
+
scored: list[tuple[int, str]] = []
|
|
46
|
+
for cand in candidates:
|
|
47
|
+
c_raw = str(cand).strip()
|
|
48
|
+
if not c_raw:
|
|
49
|
+
continue
|
|
50
|
+
c = c_raw.lower()
|
|
51
|
+
dist = _py_damerau_levenshtein(q, c)
|
|
52
|
+
is_substr = len(q) >= 3 and (q in c or c in q)
|
|
53
|
+
if dist <= threshold or is_substr:
|
|
54
|
+
effective = min(dist, threshold) if is_substr else dist
|
|
55
|
+
scored.append((effective, c_raw))
|
|
56
|
+
scored.sort(key=lambda item: (item[0], item[1]))
|
|
57
|
+
deduped: list[str] = []
|
|
58
|
+
for _, name in scored:
|
|
59
|
+
if name not in deduped:
|
|
60
|
+
deduped.append(name)
|
|
61
|
+
if len(deduped) >= max_results:
|
|
62
|
+
break
|
|
63
|
+
return deduped
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if TYPE_CHECKING:
|
|
67
|
+
|
|
68
|
+
class StreamCoordinate:
|
|
69
|
+
shard_id: int
|
|
70
|
+
byte_offset: int
|
|
71
|
+
row_group_idx: int
|
|
72
|
+
page_idx: int
|
|
73
|
+
row_offset_in_page: int
|
|
74
|
+
global_row_idx: int
|
|
75
|
+
|
|
76
|
+
def __init__(
|
|
77
|
+
self,
|
|
78
|
+
shard_id: int = 0,
|
|
79
|
+
byte_offset: int = 0,
|
|
80
|
+
row_group_idx: int = 0,
|
|
81
|
+
page_idx: int = 0,
|
|
82
|
+
row_offset_in_page: int = 0,
|
|
83
|
+
global_row_idx: int = 0,
|
|
84
|
+
) -> None: ...
|
|
85
|
+
def to_bytes(self) -> bytes: ...
|
|
86
|
+
@staticmethod
|
|
87
|
+
def from_bytes(raw: bytes) -> StreamCoordinate: ...
|
|
88
|
+
|
|
89
|
+
class _RawDataBatch:
|
|
90
|
+
batch_id: int
|
|
91
|
+
records: list[str]
|
|
92
|
+
next_coord: StreamCoordinate
|
|
93
|
+
is_eof: bool
|
|
94
|
+
|
|
95
|
+
def __len__(self) -> int: ...
|
|
96
|
+
|
|
97
|
+
class _RawMultimodalBatch:
|
|
98
|
+
batch_id: int
|
|
99
|
+
num_rows: int
|
|
100
|
+
next_coord: StreamCoordinate
|
|
101
|
+
is_eof: bool
|
|
102
|
+
|
|
103
|
+
def column_names(self) -> list[str]: ...
|
|
104
|
+
def column(self, name: str) -> list[Any]: ...
|
|
105
|
+
def to_dict(self) -> dict[str, list[Any]]: ...
|
|
106
|
+
def __len__(self) -> int: ...
|
|
107
|
+
|
|
108
|
+
class _RawDataStreamLoader:
|
|
109
|
+
def __new__(cls, *args: Any, **kwargs: Any) -> Any: ...
|
|
110
|
+
def committed_batch_id(self) -> int: ...
|
|
111
|
+
def committed_coordinate(self) -> StreamCoordinate: ...
|
|
112
|
+
def wait_for_refill(self, timeout_ms: int = 5000) -> int: ...
|
|
113
|
+
def commit_gpu_batch(self, batch_id: int) -> StreamCoordinate: ...
|
|
114
|
+
def next_batch(self) -> Any: ...
|
|
115
|
+
def download_workers(self) -> int: ...
|
|
116
|
+
def close(self) -> None: ...
|
|
117
|
+
|
|
118
|
+
class _RawMultimodalParquetLoader:
|
|
119
|
+
def __new__(cls, *args: Any, **kwargs: Any) -> Any: ...
|
|
120
|
+
def next_batch(self) -> Any: ...
|
|
121
|
+
def export_committed_hashes(self) -> list[int]: ...
|
|
122
|
+
def import_committed_hashes(self, hashes: Sequence[int]) -> None: ...
|
|
123
|
+
|
|
124
|
+
class HfHubUploader:
|
|
125
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
|
126
|
+
def create_repo(self, *args: Any, **kwargs: Any) -> str: ...
|
|
127
|
+
def upload_file(self, *args: Any, **kwargs: Any) -> str: ...
|
|
128
|
+
def upload_bytes(self, *args: Any, **kwargs: Any) -> str: ...
|
|
129
|
+
def upload_table(self, *args: Any, **kwargs: Any) -> str: ...
|
|
130
|
+
def upload_jsonl(self, *args: Any, **kwargs: Any) -> str: ...
|
|
131
|
+
|
|
132
|
+
def dataloader_cpu_isa() -> str: ...
|
|
133
|
+
def suggest_closest_matches(
|
|
134
|
+
query: str,
|
|
135
|
+
candidates: Sequence[str],
|
|
136
|
+
max_results: int = 3,
|
|
137
|
+
) -> list[str]: ...
|
|
138
|
+
def serialize_table_to_bytes(
|
|
139
|
+
columns: Any,
|
|
140
|
+
path_in_repo: str = "part.parquet",
|
|
141
|
+
hf_image_struct: bool = True,
|
|
142
|
+
) -> bytes: ...
|
|
143
|
+
def postprocess_and_dedup_records(
|
|
144
|
+
records: Sequence[str],
|
|
145
|
+
trim_whitespace: bool = True,
|
|
146
|
+
normalize_newlines: bool = True,
|
|
147
|
+
min_byte_len: int = 1,
|
|
148
|
+
max_byte_len: int = 0,
|
|
149
|
+
truncate_over_max: bool = False,
|
|
150
|
+
json_extract_key: str | None = None,
|
|
151
|
+
seen_hashes: Sequence[int] | None = None,
|
|
152
|
+
deduplicate: bool = True,
|
|
153
|
+
) -> tuple[list[str], list[int]]: ...
|
|
154
|
+
|
|
155
|
+
else:
|
|
156
|
+
def _load_rs_module() -> Any:
|
|
157
|
+
try:
|
|
158
|
+
from luminamoon.optimizer import _luminamoon_optimizer_rs as mod
|
|
159
|
+
return mod
|
|
160
|
+
except ImportError:
|
|
161
|
+
import importlib.machinery
|
|
162
|
+
import importlib.util
|
|
163
|
+
from pathlib import Path
|
|
164
|
+
import sys
|
|
165
|
+
|
|
166
|
+
suffixes = tuple(importlib.machinery.EXTENSION_SUFFIXES)
|
|
167
|
+
for entry in sys.path:
|
|
168
|
+
if not entry:
|
|
169
|
+
continue
|
|
170
|
+
opt_dir = Path(entry) / "luminamoon" / "optimizer"
|
|
171
|
+
if not opt_dir.is_dir():
|
|
172
|
+
continue
|
|
173
|
+
for candidate in opt_dir.iterdir():
|
|
174
|
+
if candidate.name.startswith("_luminamoon_optimizer_rs") and candidate.name.endswith(suffixes):
|
|
175
|
+
spec = importlib.util.spec_from_file_location(
|
|
176
|
+
"luminamoon.optimizer._luminamoon_optimizer_rs",
|
|
177
|
+
candidate,
|
|
178
|
+
)
|
|
179
|
+
if spec is not None and spec.loader is not None:
|
|
180
|
+
module = importlib.util.module_from_spec(spec)
|
|
181
|
+
sys.modules[spec.name] = module
|
|
182
|
+
spec.loader.exec_module(module)
|
|
183
|
+
return module
|
|
184
|
+
raise
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
_rs_mod = _load_rs_module()
|
|
188
|
+
_RawDataBatch = _rs_mod.DataBatch
|
|
189
|
+
_RawDataStreamLoader = _rs_mod.DataStreamLoader
|
|
190
|
+
HfHubUploader = _rs_mod.HfHubUploader
|
|
191
|
+
_RawMultimodalBatch = _rs_mod.MultimodalBatch
|
|
192
|
+
_RawMultimodalParquetLoader = _rs_mod.MultimodalParquetLoader
|
|
193
|
+
StreamCoordinate = _rs_mod.StreamCoordinate
|
|
194
|
+
dataloader_cpu_isa = _rs_mod.dataloader_cpu_isa
|
|
195
|
+
postprocess_and_dedup_records = _rs_mod.postprocess_and_dedup_records
|
|
196
|
+
serialize_table_to_bytes = _rs_mod.serialize_table_to_bytes
|
|
197
|
+
suggest_closest_matches = _rs_mod.suggest_closest_matches
|
|
198
|
+
except ImportError:
|
|
199
|
+
|
|
200
|
+
class StreamCoordinate:
|
|
201
|
+
def __init__(
|
|
202
|
+
self,
|
|
203
|
+
shard_id: int = 0,
|
|
204
|
+
byte_offset: int = 0,
|
|
205
|
+
row_group_idx: int = 0,
|
|
206
|
+
page_idx: int = 0,
|
|
207
|
+
row_offset_in_page: int = 0,
|
|
208
|
+
global_row_idx: int = 0,
|
|
209
|
+
) -> None:
|
|
210
|
+
self.shard_id = shard_id
|
|
211
|
+
self.byte_offset = byte_offset
|
|
212
|
+
self.row_group_idx = row_group_idx
|
|
213
|
+
self.page_idx = page_idx
|
|
214
|
+
self.row_offset_in_page = row_offset_in_page
|
|
215
|
+
self.global_row_idx = global_row_idx
|
|
216
|
+
|
|
217
|
+
class _RawDataBatch:
|
|
218
|
+
batch_id: int
|
|
219
|
+
records: list[str]
|
|
220
|
+
next_coord: StreamCoordinate
|
|
221
|
+
is_eof: bool
|
|
222
|
+
|
|
223
|
+
def __len__(self) -> int:
|
|
224
|
+
return 0
|
|
225
|
+
|
|
226
|
+
class _RawMultimodalBatch:
|
|
227
|
+
batch_id: int
|
|
228
|
+
num_rows: int
|
|
229
|
+
next_coord: StreamCoordinate
|
|
230
|
+
is_eof: bool
|
|
231
|
+
|
|
232
|
+
def column_names(self) -> list[str]:
|
|
233
|
+
return []
|
|
234
|
+
|
|
235
|
+
def column(self, name: str) -> list[Any]:
|
|
236
|
+
return []
|
|
237
|
+
|
|
238
|
+
def to_dict(self) -> dict[str, list[Any]]:
|
|
239
|
+
return {}
|
|
240
|
+
|
|
241
|
+
def __len__(self) -> int:
|
|
242
|
+
return 0
|
|
243
|
+
|
|
244
|
+
class _RawDataStreamLoader:
|
|
245
|
+
def __new__(cls, *args: Any, **kwargs: Any) -> Any:
|
|
246
|
+
raise RuntimeError(
|
|
247
|
+
"luminamoon native Rust extension (_luminamoon_optimizer_rs) is not compiled"
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
class _RawMultimodalParquetLoader:
|
|
251
|
+
def __new__(cls, *args: Any, **kwargs: Any) -> Any:
|
|
252
|
+
raise RuntimeError(
|
|
253
|
+
"luminamoon native Rust extension (_luminamoon_optimizer_rs) is not compiled"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
def export_committed_hashes(self) -> list[int]:
|
|
257
|
+
return []
|
|
258
|
+
|
|
259
|
+
def import_committed_hashes(self, hashes: Sequence[int]) -> None:
|
|
260
|
+
pass
|
|
261
|
+
|
|
262
|
+
class HfHubUploader:
|
|
263
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
264
|
+
raise RuntimeError(
|
|
265
|
+
"luminamoon native Rust extension (_luminamoon_optimizer_rs) is not compiled"
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
def dataloader_cpu_isa() -> str:
|
|
269
|
+
return "SCALAR"
|
|
270
|
+
|
|
271
|
+
def suggest_closest_matches(
|
|
272
|
+
query: str,
|
|
273
|
+
candidates: Sequence[str],
|
|
274
|
+
max_results: int = 3,
|
|
275
|
+
) -> list[str]:
|
|
276
|
+
return _py_find_closest_matches(query, candidates, max_results)
|
|
277
|
+
|
|
278
|
+
def serialize_table_to_bytes(
|
|
279
|
+
columns: Any,
|
|
280
|
+
path_in_repo: str = "part.parquet",
|
|
281
|
+
hf_image_struct: bool = True,
|
|
282
|
+
) -> bytes:
|
|
283
|
+
raise RuntimeError(
|
|
284
|
+
"luminamoon native Rust extension (_luminamoon_optimizer_rs) is not compiled"
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
def postprocess_and_dedup_records(
|
|
288
|
+
records: Sequence[str],
|
|
289
|
+
trim_whitespace: bool = True,
|
|
290
|
+
normalize_newlines: bool = True,
|
|
291
|
+
min_byte_len: int = 1,
|
|
292
|
+
max_byte_len: int = 0,
|
|
293
|
+
truncate_over_max: bool = False,
|
|
294
|
+
json_extract_key: str | None = None,
|
|
295
|
+
seen_hashes: Sequence[int] | None = None,
|
|
296
|
+
deduplicate: bool = True,
|
|
297
|
+
) -> tuple[list[str], list[int]]:
|
|
298
|
+
raise RuntimeError(
|
|
299
|
+
"luminamoon native Rust extension (_luminamoon_optimizer_rs) is not compiled"
|
|
300
|
+
)
|