PyIntell 0.1.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.
- pyintell/__init__.py +31 -0
- pyintell/attention.py +126 -0
- pyintell/autograd.py +50 -0
- pyintell/builder.py +211 -0
- pyintell/embeddings.py +33 -0
- pyintell/finetuning.py +29 -0
- pyintell/focus.py +81 -0
- pyintell/generation.py +73 -0
- pyintell/layers.py +75 -0
- pyintell/loss.py +39 -0
- pyintell/model.py +224 -0
- pyintell/optim.py +94 -0
- pyintell/quantization.py +25 -0
- pyintell/scheduling.py +16 -0
- pyintell/serialization.py +313 -0
- pyintell/system.py +122 -0
- pyintell/tokenization.py +147 -0
- pyintell/training.py +15 -0
- pyintell/transformer.py +90 -0
- pyintell/utilities.py +444 -0
- pyintell-0.1.0.dist-info/METADATA +226 -0
- pyintell-0.1.0.dist-info/RECORD +25 -0
- pyintell-0.1.0.dist-info/WHEEL +5 -0
- pyintell-0.1.0.dist-info/licenses/LICENSE +21 -0
- pyintell-0.1.0.dist-info/top_level.txt +1 -0
pyintell/utilities.py
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"""General-purpose tensor, data, metrics, and model utility functions."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def tensor(data, dtype=None):
|
|
9
|
+
return np.asarray(data, dtype=dtype)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def zeros(shape, dtype=np.float32):
|
|
13
|
+
return np.zeros(shape, dtype=dtype)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def ones(shape, dtype=np.float32):
|
|
17
|
+
return np.ones(shape, dtype=dtype)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def full(shape, value, dtype=None):
|
|
21
|
+
return np.full(shape, value, dtype=dtype)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def random(shape, dtype=np.float32):
|
|
25
|
+
return np.random.random(shape).astype(dtype)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def randn(shape, dtype=np.float32):
|
|
29
|
+
return np.random.randn(*shape).astype(dtype)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def randint(low, high=None, size=None, dtype=np.int64):
|
|
33
|
+
return np.random.randint(low, high, size=size, dtype=dtype)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def arange(*args, **kwargs):
|
|
37
|
+
return np.arange(*args, **kwargs)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def reshape(x, shape):
|
|
41
|
+
return np.reshape(x, shape)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def flatten(x):
|
|
45
|
+
return np.asarray(x).reshape(-1)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def squeeze(x, axis=None):
|
|
49
|
+
return np.squeeze(x, axis=axis)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def unsqueeze(x, axis):
|
|
53
|
+
return np.expand_dims(x, axis=axis)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def transpose(x, axes=None):
|
|
57
|
+
return np.transpose(x, axes=axes)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def permute(x, axes):
|
|
61
|
+
return np.transpose(x, axes=axes)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def matmul(a, b):
|
|
65
|
+
return np.matmul(a, b)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def dot(a, b):
|
|
69
|
+
return np.dot(a, b)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def sum(x, axis=None, keepdims=False):
|
|
73
|
+
return np.sum(x, axis=axis, keepdims=keepdims)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def mean(x, axis=None, keepdims=False):
|
|
77
|
+
return np.mean(x, axis=axis, keepdims=keepdims)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def max(x, axis=None, keepdims=False):
|
|
81
|
+
return np.max(x, axis=axis, keepdims=keepdims)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def min(x, axis=None, keepdims=False):
|
|
85
|
+
return np.min(x, axis=axis, keepdims=keepdims)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def argmax(x, axis=None):
|
|
89
|
+
return np.argmax(x, axis=axis)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def argmin(x, axis=None):
|
|
93
|
+
return np.argmin(x, axis=axis)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def clip(x, minimum, maximum):
|
|
97
|
+
return np.clip(x, minimum, maximum)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def sqrt(x):
|
|
101
|
+
return np.sqrt(x)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def exp(x):
|
|
105
|
+
return np.exp(x)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def log(x):
|
|
109
|
+
return np.log(x)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def abs(x):
|
|
113
|
+
return np.abs(x)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def power(x, exponent):
|
|
117
|
+
return np.power(x, exponent)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def cat(tensors, axis=0):
|
|
121
|
+
return np.concatenate(tensors, axis=axis)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def stack(tensors, axis=0):
|
|
125
|
+
return np.stack(tensors, axis=axis)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def split(x, sections, axis=0):
|
|
129
|
+
return np.array_split(x, sections, axis=axis)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def chunk(x, chunks, axis=0):
|
|
133
|
+
return np.array_split(x, chunks, axis=axis)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def repeat(x, repeats, axis=None):
|
|
137
|
+
return np.repeat(x, repeats, axis=axis)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def expand(x, shape):
|
|
141
|
+
return np.broadcast_to(x, shape)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def pad(x, padding, constant=0):
|
|
145
|
+
return np.pad(x, padding, constant_values=constant)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def roll(x, shift, axis=None):
|
|
149
|
+
return np.roll(x, shift, axis=axis)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def gather(x, indices, axis=0):
|
|
153
|
+
return np.take(x, indices, axis=axis)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def scatter(x, indices, values, axis=0):
|
|
157
|
+
result = np.array(x, copy=True)
|
|
158
|
+
np.put_along_axis(result, np.asarray(indices), np.asarray(values), axis=axis)
|
|
159
|
+
return result
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def where(condition, x, y):
|
|
163
|
+
return np.where(condition, x, y)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def masked_fill(x, mask, value):
|
|
167
|
+
return np.where(mask, x, value)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def einsum(expression, *operands):
|
|
171
|
+
return np.einsum(expression, *operands)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def norm(x, axis=None, keepdims=False):
|
|
175
|
+
return np.linalg.norm(x, axis=axis, keepdims=keepdims)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def normalize(x, axis=-1, eps=1e-12):
|
|
179
|
+
x = np.asarray(x)
|
|
180
|
+
return x / np.maximum(norm(x, axis=axis, keepdims=True), eps)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def device():
|
|
184
|
+
return "cpu"
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def cpu():
|
|
188
|
+
return "cpu"
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def gpu():
|
|
192
|
+
return None
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def to_device(x, target="cpu"):
|
|
196
|
+
if str(target).lower() != "cpu":
|
|
197
|
+
raise RuntimeError("GPU backends are not included in the NumPy-only release")
|
|
198
|
+
return x
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def seed(value):
|
|
202
|
+
np.random.seed(value)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def set_seed(value):
|
|
206
|
+
seed(value)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def random_seed(value=None):
|
|
210
|
+
if value is None:
|
|
211
|
+
value = int.from_bytes(os.urandom(8), "little")
|
|
212
|
+
seed(value)
|
|
213
|
+
return value
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def accuracy(predictions, targets):
|
|
217
|
+
p = np.asarray(predictions)
|
|
218
|
+
t = np.asarray(targets)
|
|
219
|
+
if p.ndim > t.ndim:
|
|
220
|
+
p = np.argmax(p, axis=-1)
|
|
221
|
+
return float(np.mean(p == t))
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def precision(predictions, targets):
|
|
225
|
+
p, t = np.asarray(predictions).astype(bool), np.asarray(targets).astype(bool)
|
|
226
|
+
tp = np.sum(p & t)
|
|
227
|
+
fp = np.sum(p & ~t)
|
|
228
|
+
return float(tp / (tp + fp)) if tp + fp else 0.0
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def recall(predictions, targets):
|
|
232
|
+
p, t = np.asarray(predictions).astype(bool), np.asarray(targets).astype(bool)
|
|
233
|
+
tp = np.sum(p & t)
|
|
234
|
+
fn = np.sum(~p & t)
|
|
235
|
+
return float(tp / (tp + fn)) if tp + fn else 0.0
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def f1_score(predictions, targets):
|
|
239
|
+
p = precision(predictions, targets)
|
|
240
|
+
r = recall(predictions, targets)
|
|
241
|
+
return 2 * p * r / (p + r) if p + r else 0.0
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def perplexity(loss_value):
|
|
245
|
+
return float(np.exp(loss_value))
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def model_size(parameters, dtype="float32"):
|
|
249
|
+
sizes = {"float64": 8, "float32": 4, "float16": 2, "bfloat16": 2, "int8": 1, "int4": 0.5}
|
|
250
|
+
return int(np.ceil(int(parameters) * sizes[str(dtype).lower()]))
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def count_parameters(model):
|
|
254
|
+
return int(getattr(model, "parameters", 0))
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def trainable_parameters(model):
|
|
258
|
+
return count_parameters(model)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def parameter_shapes(model):
|
|
262
|
+
return {name: value.shape for name, value in vars(model).items() if isinstance(value, np.ndarray)}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def memory_usage(model):
|
|
266
|
+
return sum(value.nbytes for value in vars(model).values() if isinstance(value, np.ndarray))
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def model_info(model):
|
|
270
|
+
return model.summary() if hasattr(model, "summary") else {"parameters": count_parameters(model)}
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def summary(model):
|
|
274
|
+
return model_info(model)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def save_config(config, path):
|
|
278
|
+
with open(path, "w", encoding="utf-8") as file:
|
|
279
|
+
json.dump(config, file, indent=2)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def load_config(path):
|
|
283
|
+
with open(path, "r", encoding="utf-8") as file:
|
|
284
|
+
return json.load(file)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def read_text(path, encoding="utf-8"):
|
|
288
|
+
with open(path, "r", encoding=encoding) as file:
|
|
289
|
+
return file.read()
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def write_text(path, text, encoding="utf-8"):
|
|
293
|
+
with open(path, "w", encoding=encoding) as file:
|
|
294
|
+
file.write(text)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def load_text(path, encoding="utf-8"):
|
|
298
|
+
return read_text(path, encoding)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def save_text(path, text, encoding="utf-8"):
|
|
302
|
+
return write_text(path, text, encoding)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def normalize_text(text):
|
|
306
|
+
return " ".join(str(text).split())
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def clean_text(text):
|
|
310
|
+
return normalize_text(text)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def lower_text(text):
|
|
314
|
+
return str(text).lower()
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def uppercase(text):
|
|
318
|
+
return str(text).upper()
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def split_sentences(text):
|
|
322
|
+
return [part.strip() for part in str(text).replace("!", ".").replace("?", ".").split(".") if part.strip()]
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def split_words(text):
|
|
326
|
+
return str(text).split()
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def chunk_text(text, size):
|
|
330
|
+
words = split_words(text)
|
|
331
|
+
return [" ".join(words[i:i + size]) for i in range(0, len(words), size)]
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def truncate_text(text, max_words):
|
|
335
|
+
return " ".join(split_words(text)[:max_words])
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def pad_sequence(sequence, length, value=0):
|
|
339
|
+
result = list(sequence)[:length]
|
|
340
|
+
return result + [value] * max(0, length - len(result))
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def create_mask(length, causal=False):
|
|
344
|
+
if causal:
|
|
345
|
+
return np.tril(np.ones((length, length), dtype=bool))
|
|
346
|
+
return np.ones((length, length), dtype=bool)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def shuffle(data, seed_value=None):
|
|
350
|
+
items = list(data)
|
|
351
|
+
rng = np.random.default_rng(seed_value)
|
|
352
|
+
rng.shuffle(items)
|
|
353
|
+
return items
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def split_dataset(data, train_ratio=0.8, validation_ratio=0.1):
|
|
357
|
+
items = list(data)
|
|
358
|
+
n = len(items)
|
|
359
|
+
a = int(n * train_ratio)
|
|
360
|
+
b = a + int(n * validation_ratio)
|
|
361
|
+
return items[:a], items[a:b], items[b:]
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def batch(data, batch_size):
|
|
365
|
+
items = list(data)
|
|
366
|
+
return [items[i:i + batch_size] for i in range(0, len(items), batch_size)]
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def dataset(data):
|
|
370
|
+
return list(data)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def load_dataset(data):
|
|
374
|
+
return dataset(data)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def save_dataset(data, path):
|
|
378
|
+
np.save(path, np.asarray(data, dtype=object), allow_pickle=True)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def cache(data):
|
|
382
|
+
return list(data)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def filter_dataset(data, predicate):
|
|
386
|
+
return [item for item in data if predicate(item)]
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def map_dataset(data, function):
|
|
390
|
+
return [function(item) for item in data]
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def temperature(logits, value=1.0):
|
|
394
|
+
if value <= 0:
|
|
395
|
+
raise ValueError("temperature must be greater than zero")
|
|
396
|
+
return np.asarray(logits) / value
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def top_k(logits, k):
|
|
400
|
+
values = np.asarray(logits)
|
|
401
|
+
if k <= 0:
|
|
402
|
+
raise ValueError("k must be positive")
|
|
403
|
+
indices = np.argpartition(values, -min(k, values.size))[-min(k, values.size):]
|
|
404
|
+
return indices
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def top_p(logits, p=0.9):
|
|
408
|
+
values = np.asarray(logits, dtype=np.float64)
|
|
409
|
+
if not 0 < p <= 1:
|
|
410
|
+
raise ValueError("p must be in the range (0, 1]")
|
|
411
|
+
order = np.argsort(values)[::-1]
|
|
412
|
+
shifted = values[order] - np.max(values)
|
|
413
|
+
probs = np.exp(shifted)
|
|
414
|
+
probs /= probs.sum()
|
|
415
|
+
cumulative = np.cumsum(probs)
|
|
416
|
+
return order[cumulative <= p] if np.any(cumulative <= p) else order[:1]
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def repetition_penalty(logits, token_ids, penalty=1.1):
|
|
420
|
+
values = np.array(logits, dtype=np.float64, copy=True)
|
|
421
|
+
for token_id in set(token_ids):
|
|
422
|
+
if 0 <= token_id < len(values):
|
|
423
|
+
values[token_id] = values[token_id] / penalty if values[token_id] > 0 else values[token_id] * penalty
|
|
424
|
+
return values
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def frequency_penalty(logits, token_ids, penalty=0.0):
|
|
428
|
+
values = np.array(logits, dtype=np.float64, copy=True)
|
|
429
|
+
for token_id in token_ids:
|
|
430
|
+
if 0 <= token_id < len(values):
|
|
431
|
+
values[token_id] -= penalty
|
|
432
|
+
return values
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def presence_penalty(logits, token_ids, penalty=0.0):
|
|
436
|
+
values = np.array(logits, dtype=np.float64, copy=True)
|
|
437
|
+
for token_id in set(token_ids):
|
|
438
|
+
if 0 <= token_id < len(values):
|
|
439
|
+
values[token_id] -= penalty
|
|
440
|
+
return values
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def stop_at_token(token_id, stop_tokens):
|
|
444
|
+
return token_id in set(stop_tokens)
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyIntell
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A modular NumPy-based Python framework for building, training, evaluating, and generating from AI models
|
|
5
|
+
Author: Leila150
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Leila150/PyIntell
|
|
8
|
+
Project-URL: Repository, https://github.com/Leila150/PyIntell
|
|
9
|
+
Project-URL: Issues, https://github.com/Leila150/PyIntell/issues
|
|
10
|
+
Keywords: ai,machine-learning,deep-learning,transformer,neural-network,nlp,numpy
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Provides-Extra: system
|
|
29
|
+
Requires-Dist: psutil>=5.9; extra == "system"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# PyIntell
|
|
33
|
+
|
|
34
|
+
**PyIntell** is a modular NumPy-based Python framework for building, experimenting with, evaluating, training, and generating from AI/Transformer-style models.
|
|
35
|
+
|
|
36
|
+
> **Status:** `0.1.0` — Alpha. The public API is available for experimentation. Some advanced training, autograd, quantization, and hardware features are lightweight/experimental rather than production-grade.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
The **PyPI project name is `PyIntell`**.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install PyIntell
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The Python import name is **`pyintell`**:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import pyintell
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This distinction is important: **install `PyIntell`, import `pyintell`.**
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import pyintell
|
|
58
|
+
|
|
59
|
+
model = pyintell.build(
|
|
60
|
+
vocab={"hello": 0, "world": 1},
|
|
61
|
+
reverse_vocab={0: "hello", 1: "world"},
|
|
62
|
+
dataset=[[0, 1]],
|
|
63
|
+
parameters=100_000,
|
|
64
|
+
focus=["coding", "reasoning", "math"],
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
print(model.summary())
|
|
68
|
+
print(model.generate("hello"))
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Main builder
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
pyintell.build(
|
|
75
|
+
vocab,
|
|
76
|
+
reverse_vocab,
|
|
77
|
+
dataset,
|
|
78
|
+
parameters,
|
|
79
|
+
focus,
|
|
80
|
+
dtype=None,
|
|
81
|
+
settings=None,
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`build()` constructs a `Model` from a vocabulary, reverse vocabulary, dataset, requested parameter count, focus, numerical dtype, and optional settings.
|
|
86
|
+
|
|
87
|
+
## Focus system
|
|
88
|
+
|
|
89
|
+
Focus profiles are exposed through `SUPPORTED_FOCUSES` and `FOCUS_PROFILES`. Focus utilities include:
|
|
90
|
+
|
|
91
|
+
- `normalize_focus()`
|
|
92
|
+
- `build_focus_config()`
|
|
93
|
+
- `focus_description()`
|
|
94
|
+
|
|
95
|
+
Multiple focuses are supported:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
focus=["coding", "reasoning", "math"]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Models can also expose and modify focus through `get_focus()`, `set_focus()`, `focus_scores()`, and `focus_info()`.
|
|
102
|
+
|
|
103
|
+
## Public API
|
|
104
|
+
|
|
105
|
+
The `PyIntell` distribution exposes the Python package `pyintell`. Its public API includes the following functional areas.
|
|
106
|
+
|
|
107
|
+
### Model and building
|
|
108
|
+
|
|
109
|
+
`Model`, `build`, `named_parameters`, `parameter_count`, `parameters_info`, `summary`, `model_info`, `model_size`, `count_parameters`, `parameter_shapes`, `set_current_model`, and model-management helpers.
|
|
110
|
+
|
|
111
|
+
### Tokenization
|
|
112
|
+
|
|
113
|
+
`tokenizer`, `tokenize`, `tokenize_batch`, `detokenize`, `detokenize_batch`, `vocab`, `build_vocab`, `update_vocab`, `merge_vocab`, `reverse_vocab`, `vocab_size`, `token_id`, `id_token`, `token_exists`, `add_token`, `remove_token`, `special_tokens`, `add_special_token`, `encode`, `encode_batch`, `decode`, `decode_batch`, `normalize_text`, `clean_text`, `split_text`, `split_words`, `split_sentences`, `chunk_text`, `truncate`, `truncate_text`, `lower_text`, `uppercase`, and `pad_sequence`.
|
|
114
|
+
|
|
115
|
+
### Embeddings
|
|
116
|
+
|
|
117
|
+
`embedding`, `embeddings`, `positional_embedding`, `position_embedding`, `sinusoidal_embedding`, `rotary_embedding`, and `embedding_similarity`.
|
|
118
|
+
|
|
119
|
+
### Attention and Transformer
|
|
120
|
+
|
|
121
|
+
`attention`, `scaled_dot_product_attention`, `self_attention`, `cross_attention`, `multihead_attention`, `multi_query_attention`, `grouped_query_attention`, `causal_attention`, `local_attention`, `global_attention`, `sparse_attention`, `sliding_window_attention`, `block_attention`, `flash_attention`, `rotary_attention`, `alibi_attention`, `attention_mask`, `causal_mask`, `padding_mask`, `transformer_block`, and `transformer`.
|
|
122
|
+
|
|
123
|
+
### Layers and activations
|
|
124
|
+
|
|
125
|
+
`linear`, `activation`, `relu`, `gelu`, `sigmoid`, `tanh`, `leaky_relu`, `softplus`, `silu`, `swish`, `mish`, `softmax`, `log_softmax`, `layer_norm`, `batch_norm`, `rms_norm`, `dropout`, `flatten_layer`, `feedforward`, `mlp`, `residual`, and `residual_block`.
|
|
126
|
+
|
|
127
|
+
### Losses and metrics
|
|
128
|
+
|
|
129
|
+
`loss`, `cross_entropy`, `binary_cross_entropy`, `mse`, `mae`, `huber_loss`, `kl_divergence`, `contrastive_loss`, `label_smoothing`, `perplexity`, `accuracy`, `f1_score`, and `recall`.
|
|
130
|
+
|
|
131
|
+
### Tensor and numerical operations
|
|
132
|
+
|
|
133
|
+
`tensor`, `zeros`, `ones`, `full`, `random`, `randn`, `randint`, `arange`, `reshape`, `flatten`, `squeeze`, `unsqueeze`, `transpose`, `permute`, `repeat`, `expand`, `pad`, `roll`, `cat`, `stack`, `split`, `chunk`, `matmul`, `dot`, `sum`, `mean`, `max`, `min`, `argmax`, `argmin`, `clip`, `sqrt`, `exp`, `log`, `abs`, `power`, `norm`, `normalize`, `einsum`, `where`, `masked_fill`, `gather`, and `scatter`.
|
|
134
|
+
|
|
135
|
+
### Autograd
|
|
136
|
+
|
|
137
|
+
`gradient`, `compute_gradients`, `numerical_gradient`, `backward`, `requires_grad`, `detach`, `no_grad`, and `zero_grad`.
|
|
138
|
+
|
|
139
|
+
### Optimizers and scheduling
|
|
140
|
+
|
|
141
|
+
`Optimizer`, `optimizer`, `sgd`, `adam`, `adamw`, `rmsprop`, `adagrad`, `update_weights`, `step`, `learning_rate`, `weight_decay`, `gradient_clipping`, `lr_scheduler`, `constant_lr`, `linear_decay`, `cosine_decay`, and `warmup`.
|
|
142
|
+
|
|
143
|
+
### Dataset and training
|
|
144
|
+
|
|
145
|
+
`dataset`, `load_dataset`, `save_dataset`, `split_dataset`, `shuffle`, `batch`, `map_dataset`, `filter_dataset`, `cache`, `train`, and `evaluate`.
|
|
146
|
+
|
|
147
|
+
### Generation
|
|
148
|
+
|
|
149
|
+
`generate`, `sample`, `temperature`, `top_k`, `top_p`, `repetition_penalty`, `frequency_penalty`, `presence_penalty`, `stop_at_token`, `get_model`, and `model_run`.
|
|
150
|
+
|
|
151
|
+
### Serialization and storage
|
|
152
|
+
|
|
153
|
+
`save`, `load`, `save_model`, `load_model`, `delete_model`, `edit_model`, `save_weights`, `load_weights`, `state_dict`, `load_state_dict`, `serialize`, `deserialize`, `save_config`, `load_config`, `save_checkpoint`, `load_checkpoint`, `checkpoint`, `export_model`, `import_model`, `save_text`, `load_text`, `read_text`, and `write_text`.
|
|
154
|
+
|
|
155
|
+
### Quantization and fine-tuning
|
|
156
|
+
|
|
157
|
+
`quantization`, `quantize`, `dequantize`, `int4`, `int8`, `float16`, `bfloat16`, `finetune`, `finetuning`, `parameter_efficient_finetuning`, `lora`, `qlora`, `adapter`, `low_rank`, `prefix_tuning`, `prompt_tuning`, `freeze`, `unfreeze`, `freeze_layers`, `unfreeze_layers`, `trainable`, `trainable_parameters`, `prune`, `sparsify`, and `factorize`.
|
|
158
|
+
|
|
159
|
+
### System and devices
|
|
160
|
+
|
|
161
|
+
`device`, `to_device`, `cpu`, `gpu`, `cuda`, `device_count`, `device_info`, `is_gpu_available`, `cpu_info`, `gpu_info`, `cpu_memory`, `gpu_memory`, `memory_info`, `memory_usage`, `free_memory`, `clear_cache`, `ram`, `storage_info`, and `system_info`.
|
|
162
|
+
|
|
163
|
+
### Reproducibility
|
|
164
|
+
|
|
165
|
+
`seed`, `set_seed`, and `random_seed` control random initialization and reproducibility.
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
pyintell.set_seed(42)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Package layout
|
|
172
|
+
|
|
173
|
+
The project uses a `src` layout. The **distribution name is `PyIntell`**, and the **Python package/import name is `pyintell`**.
|
|
174
|
+
|
|
175
|
+
```text
|
|
176
|
+
PyIntell/
|
|
177
|
+
├── src/
|
|
178
|
+
│ └── pyintell/
|
|
179
|
+
├── .github/
|
|
180
|
+
│ └── workflows/
|
|
181
|
+
│ └── release.yml
|
|
182
|
+
├── pyproject.toml
|
|
183
|
+
├── README.md
|
|
184
|
+
└── LICENSE
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## PyPI publishing
|
|
188
|
+
|
|
189
|
+
PyPI publication is automated through GitHub Actions and PyPI Trusted Publishing.
|
|
190
|
+
|
|
191
|
+
Workflow:
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
.github/workflows/release.yml
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The release workflow:
|
|
198
|
+
|
|
199
|
+
1. Checks out the repository.
|
|
200
|
+
2. Sets up Python.
|
|
201
|
+
3. Installs `build` and `twine`.
|
|
202
|
+
4. Builds source and wheel distributions.
|
|
203
|
+
5. Runs `twine check` against the distributions.
|
|
204
|
+
6. Publishes the distributions to the `PyIntell` PyPI project using Trusted Publishing.
|
|
205
|
+
|
|
206
|
+
A GitHub Release with the `published` event triggers the workflow. It can also be started manually with `workflow_dispatch`.
|
|
207
|
+
|
|
208
|
+
## Requirements
|
|
209
|
+
|
|
210
|
+
- Python `>=3.9`
|
|
211
|
+
- NumPy `>=1.24`
|
|
212
|
+
- Optional: `psutil>=5.9` for system-related functionality
|
|
213
|
+
|
|
214
|
+
## Status
|
|
215
|
+
|
|
216
|
+
**pyintell `0.1.0` Alpha**
|
|
217
|
+
|
|
218
|
+
The project is intended for experimentation and development. The Alpha API may evolve before a stable release.
|
|
219
|
+
|
|
220
|
+
## Repository
|
|
221
|
+
|
|
222
|
+
GitHub: https://github.com/Leila150/PyIntell
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT License. See `LICENSE` for the full license text.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
pyintell/__init__.py,sha256=-IwjC_uTUmQSmSELtUB3OHy18rxbUMLAG9sNv6a-Omc,872
|
|
2
|
+
pyintell/attention.py,sha256=_UN6hn2ffU7IiW_C-Tz9XomOywK3_xZaqJ58qe9Vp1g,3784
|
|
3
|
+
pyintell/autograd.py,sha256=fcLyi3wRwPrg7WxdUK95KfsyVGXzUVZ4FYS46uc9D60,1301
|
|
4
|
+
pyintell/builder.py,sha256=Zu88uuKeYaVjys6Gos93PEx8vsQeNeXlnF1ETi-PiHM,10159
|
|
5
|
+
pyintell/embeddings.py,sha256=earu3AgFSwoTmhqoNjcUXcq766NiMd5TCnj08jzCh84,1383
|
|
6
|
+
pyintell/finetuning.py,sha256=Sgg28A01aRbdZlDL7LuDr7XG9fv-J72gqmrVslWVA5o,1871
|
|
7
|
+
pyintell/focus.py,sha256=n7aBCNneFfHZQUHW00mMSutaL2WZU6bBjR7PtzJ8H_Y,3517
|
|
8
|
+
pyintell/generation.py,sha256=I24UrQvYAh62CB3njDrapEPosd3LCFsNR8O1QLRkHBg,2867
|
|
9
|
+
pyintell/layers.py,sha256=MEkK2Yp7c_qWlmhHNVuFaKSXek5n0pFY5LGHnkppnZE,2935
|
|
10
|
+
pyintell/loss.py,sha256=tXSqrJ4wvTUUMojIze7GgUsDhx_4Y1QveB3qjw6fO_Q,2097
|
|
11
|
+
pyintell/model.py,sha256=2b2wdv6mBtAXBY0e6YainuN2wGkzLDn5wd4MnRhiJ8M,11681
|
|
12
|
+
pyintell/optim.py,sha256=hTBoLQ2A0Hy_TiftzUHwO1MceLSpyCFnUxpjXLiY8OE,4700
|
|
13
|
+
pyintell/quantization.py,sha256=15Y6zqwcDCgxjYlpoz1zZKhJOvAxNh0o_2l5CWXVuTk,1169
|
|
14
|
+
pyintell/scheduling.py,sha256=o2LkIYLb3PMKRx_tACY_mIF2AjooizhQY8d3NSAd_Ok,864
|
|
15
|
+
pyintell/serialization.py,sha256=vbEBPfFN05TsPXWJIJ4fR6N1LiXsDjJSVWBWngy3w_w,9848
|
|
16
|
+
pyintell/system.py,sha256=lk67thBEhAq8CgMJrgwSDN9DkJPbCt-6aK4EfxXcWGU,2983
|
|
17
|
+
pyintell/tokenization.py,sha256=QMMYhGzWgxvlrQu2NDKODjTkmmaV_DvfZHCC567Ho5I,3473
|
|
18
|
+
pyintell/training.py,sha256=Htv2DNl3XL2hwl_nGF3yUPTTlRCqmvr1Tbk84SG51-k,526
|
|
19
|
+
pyintell/transformer.py,sha256=gqfmDKsUHcMSzdsGyuo-QVne3vfknI9z0mHWKQGVyaY,4081
|
|
20
|
+
pyintell/utilities.py,sha256=qDPU9lhHPg7ubYOus5JWRRO-PMh6VMJNKdKRzKqpH8U,9686
|
|
21
|
+
pyintell-0.1.0.dist-info/licenses/LICENSE,sha256=u9PxYqT3h-Ucs9FlBXHTglV63_1y6yDdp7Fs1JevEhU,1065
|
|
22
|
+
pyintell-0.1.0.dist-info/METADATA,sha256=wgG-7xbmTWnuzNbhhQ0jod_MrkAHIVmTtyDlycvmWNo,8663
|
|
23
|
+
pyintell-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
24
|
+
pyintell-0.1.0.dist-info/top_level.txt,sha256=rftHPOtYxxPR-brWU1GZP9MbDW6F2grrY_tWfB4h_y0,9
|
|
25
|
+
pyintell-0.1.0.dist-info/RECORD,,
|