initium-deeplearning 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.
- initium/LNN_controller/cfc_backbone_parallel.py +265 -0
- initium/LNN_controller/cfc_controller.py +325 -0
- initium/LNN_controller/chained_controller.py +83 -0
- initium/LNN_controller/hybrid_controller.py +90 -0
- initium/MoE/README.md +1 -0
- initium/MoE/moe_layer.py +552 -0
- initium/__init__.py +1 -0
- initium/config/controller_config.py +86 -0
- initium/config/train_config.py +64 -0
- initium/core_training.py +2182 -0
- initium/data/__init__.py +0 -0
- initium/data/audio/__init__.py +0 -0
- initium/data/audio/audio_dataset.py +96 -0
- initium/data/base_dataset.py +75 -0
- initium/data/common/__init__.py +0 -0
- initium/data/common/chain_task.py +542 -0
- initium/data/common/digit_codec.py +85 -0
- initium/data/common/graph_io.py +123 -0
- initium/data/common/real_data.py +747 -0
- initium/data/dataset_registry.py +59 -0
- initium/data/graph_traversal/__init__.py +0 -0
- initium/data/graph_traversal/graph_traversal.py +746 -0
- initium/data/multimodal/__init__.py +0 -0
- initium/data/multimodal/multimodal_dataset.py +401 -0
- initium/data/text/__init__.py +0 -0
- initium/data/text/text_dataset.py +79 -0
- initium/data/video/__init__.py +0 -0
- initium/data/video/video_dataset.py +85 -0
- initium/inference/__init__.py +1 -0
- initium/inference/cache/__init__.py +1 -0
- initium/inference/cache/base_cache.py +112 -0
- initium/inference/cache/cache_config.py +21 -0
- initium/inference/cache/cache_registry.py +99 -0
- initium/inference/cache/cached_engine.py +264 -0
- initium/inference/cache/keys.py +77 -0
- initium/inference/cache/prefix_cache.py +59 -0
- initium/inference/cache/result_cache.py +57 -0
- initium/inference/cache/state_utils.py +74 -0
- initium/inference/cache/stores.py +167 -0
- initium/inference/capabilities.py +86 -0
- initium/inference/checkpoint_io.py +63 -0
- initium/inference/engine.py +88 -0
- initium/inference/inference_config.py +22 -0
- initium/inference/metrics.py +103 -0
- initium/inference/model_loader.py +270 -0
- initium/inference/run_inference.py +526 -0
- initium/inference/run_logging.py +173 -0
- initium/inference/tasks/__init__.py +1 -0
- initium/inference/tasks/audio_task.py +114 -0
- initium/inference/tasks/base_task.py +60 -0
- initium/inference/tasks/graph_traversal_task.py +235 -0
- initium/inference/tasks/multimodal_task.py +74 -0
- initium/inference/tasks/task_registry.py +68 -0
- initium/inference/tasks/text_task.py +114 -0
- initium/inference/tasks/video_task.py +114 -0
- initium/mamba_controller/mamba2_controller.py +433 -0
- initium/mamba_controller/mamba3_controller.py +242 -0
- initium/mamba_controller/mamba_backbone_parallel.py +291 -0
- initium/mamba_controller/mamba_controller.py +983 -0
- initium/mamba_controller/split_graph_dnc.py +623 -0
- initium/memory_manipulation/dynamic_memory_resize.py +157 -0
- initium/memory_manipulation/dynamic_n_controller.py +152 -0
- initium/memory_manipulation/link_matrix_ablation.py +130 -0
- initium/memory_manipulation/nvrtc_compat.py +143 -0
- initium/memory_manipulation/stochastic_write_head_v2.py +545 -0
- initium/setup_wheels.py +175 -0
- initium_deeplearning-0.1.0.dist-info/METADATA +253 -0
- initium_deeplearning-0.1.0.dist-info/RECORD +71 -0
- initium_deeplearning-0.1.0.dist-info/WHEEL +4 -0
- initium_deeplearning-0.1.0.dist-info/entry_points.txt +3 -0
- initium_deeplearning-0.1.0.dist-info/licenses/LICENSE +674 -0
initium/data/__init__.py
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""
|
|
2
|
+
file: data/audio/audio_dataset.py
|
|
3
|
+
|
|
4
|
+
Audio modality dataset: AudioChainDataset(KVChainDataset). Default (no
|
|
5
|
+
dataset_link): synthetic frequency-bin(key)->amplitude-bin(value)
|
|
6
|
+
tone-event facts, drawn fresh each episode (unchanged behavior). With
|
|
7
|
+
dataset_link (a path to a real audio file, needs torchaudio): each STFT
|
|
8
|
+
frame is quantized to a dominant-frequency-bin id (data/common/real_data.py
|
|
9
|
+
audio_token_stream) and turned into a real fact pool, split into a
|
|
10
|
+
disjoint TRAIN/TEST pool the same way text_dataset.py does -- the audio
|
|
11
|
+
analogue of the graph dataset's held-out London Underground graph.
|
|
12
|
+
test_dataset_link (a second audio file) can be given to use a genuinely
|
|
13
|
+
different recording as the test set instead of a held-out slice of the
|
|
14
|
+
same one.
|
|
15
|
+
|
|
16
|
+
Depth axis: number of tone-events (utterance-duration analogue). Fields:
|
|
17
|
+
value (per-event recognition), cumsum (chained running-energy state).
|
|
18
|
+
Robustness axis: additive noise -- softly blends the clean value one-hot
|
|
19
|
+
with a second random one-hot, weighted by severity, instead of a hard
|
|
20
|
+
digit flip.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import random
|
|
24
|
+
|
|
25
|
+
import torch
|
|
26
|
+
|
|
27
|
+
from initium.data.common.chain_task import KVChainDataset
|
|
28
|
+
from initium.data.common.real_data import build_audio_kv_pool, split_train_test_facts
|
|
29
|
+
|
|
30
|
+
AUDIO_CURRICULUM = [
|
|
31
|
+
(3, 2),
|
|
32
|
+
(3, 3),
|
|
33
|
+
(5, 3),
|
|
34
|
+
(5, 4),
|
|
35
|
+
(8, 4),
|
|
36
|
+
(8, 5),
|
|
37
|
+
(10, 5),
|
|
38
|
+
(10, 6),
|
|
39
|
+
(12, 6),
|
|
40
|
+
(12, 7),
|
|
41
|
+
(15, 8),
|
|
42
|
+
(15, 9),
|
|
43
|
+
(20, 10),
|
|
44
|
+
(20, 12),
|
|
45
|
+
]
|
|
46
|
+
AUDIO_LESSON_NR_CELLS = [128, 128, 128, 128, 160, 160, 160, 160, 192, 192, 192, 192, 256, 256]
|
|
47
|
+
assert len(AUDIO_CURRICULUM) == len(AUDIO_LESSON_NR_CELLS)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class AudioChainDataset(KVChainDataset):
|
|
51
|
+
name = "audio-chain"
|
|
52
|
+
|
|
53
|
+
def __init__(self, dataset_link=None, test_dataset_link=None):
|
|
54
|
+
# dataset_link / test_dataset_link each accept a single file, a
|
|
55
|
+
# directory (an entire folder of clips), a glob pattern
|
|
56
|
+
# ("/data/audio_clips/*.wav"), or a '+'-joined list of these -- see
|
|
57
|
+
# data/common/real_data.py's resolve_link_paths. Each matched file
|
|
58
|
+
# contributes its own facts (e.g. 5 clips with different
|
|
59
|
+
# frequency/amplitude profiles) to one combined pool.
|
|
60
|
+
self._table = AUDIO_CURRICULUM
|
|
61
|
+
self._lesson_nr_cells = AUDIO_LESSON_NR_CELLS
|
|
62
|
+
self._fact_pool = None
|
|
63
|
+
self._test_fact_pool = None
|
|
64
|
+
if dataset_link is not None:
|
|
65
|
+
pool = build_audio_kv_pool(dataset_link, self.label_range)
|
|
66
|
+
if test_dataset_link is not None:
|
|
67
|
+
self._fact_pool = pool
|
|
68
|
+
self._test_fact_pool = build_audio_kv_pool(test_dataset_link, self.label_range)
|
|
69
|
+
else:
|
|
70
|
+
self._fact_pool, self._test_fact_pool = split_train_test_facts(pool)
|
|
71
|
+
print(
|
|
72
|
+
f"[audio-chain] {len(self._fact_pool)} train facts from {dataset_link} | "
|
|
73
|
+
f"{len(self._test_fact_pool)} test facts"
|
|
74
|
+
+ (f" from {test_dataset_link}" if test_dataset_link else " (held-out split)")
|
|
75
|
+
)
|
|
76
|
+
elif test_dataset_link is not None:
|
|
77
|
+
# Inference-only: no training pool needed, just a fixed real
|
|
78
|
+
# test pool -- every inference/tasks/*_task.py passes
|
|
79
|
+
# --dataset-link through as test_dataset_link.
|
|
80
|
+
self._test_fact_pool = build_audio_kv_pool(test_dataset_link, self.label_range)
|
|
81
|
+
print(f"[audio-chain] {len(self._test_fact_pool)} test facts from {test_dataset_link}")
|
|
82
|
+
|
|
83
|
+
def _synthetic_ood_facts(self, n_facts: int = 20):
|
|
84
|
+
rng = random.Random(9001) # different seed -> different "speaker profile"
|
|
85
|
+
keys = rng.sample(range(self.label_range), n_facts)
|
|
86
|
+
vals = [rng.randrange(self.label_range) for _ in range(n_facts)]
|
|
87
|
+
return list(zip(keys, vals))
|
|
88
|
+
|
|
89
|
+
def perturb_fact(self, key_vec: torch.Tensor, value_vec: torch.Tensor, rng, severity: float):
|
|
90
|
+
if severity <= 0:
|
|
91
|
+
return key_vec, value_vec
|
|
92
|
+
noise_vec = torch.zeros_like(value_vec)
|
|
93
|
+
nd, db = self.codec.num_digits, self.codec.digit_base
|
|
94
|
+
for d in range(nd):
|
|
95
|
+
noise_vec[d * db + rng.randrange(db)] = 1.0
|
|
96
|
+
return key_vec, (1.0 - severity) * value_vec + severity * noise_vec
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
file: data/base_dataset.py
|
|
3
|
+
|
|
4
|
+
Interface core_training.py talks to. Any new dataset (text, audio, video, ...)
|
|
5
|
+
implements BaseDataset and registers itself in dataset_registry.py; the core
|
|
6
|
+
training loop never imports anything dataset-specific.
|
|
7
|
+
|
|
8
|
+
Curriculum contract (returned by make_curriculum()):
|
|
9
|
+
.lesson (int, 0-based), .table (sequence, len = number of lessons),
|
|
10
|
+
.lesson_nr_cells (list[int], per-lesson memory size, overridable by core),
|
|
11
|
+
.maybe_advance(model, device, step=None, optimizer=None)
|
|
12
|
+
-> (lesson, id_score_pct, id_perfect_pct)
|
|
13
|
+
Optional log-writer attributes set by core and read via getattr:
|
|
14
|
+
advance_log_writer/_file, hop_log_writer/_file, field_log_writer/_file.
|
|
15
|
+
Datasets without a curriculum should return a 1-lesson curriculum.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BaseDataset:
|
|
20
|
+
name = "base"
|
|
21
|
+
input_dim: int | None = None # model input/output width (DNC input_size)
|
|
22
|
+
output_dim: int | None = None # output_proj width
|
|
23
|
+
advance_threshold: float = 0.85 # default accuracy floor for dynamic beta
|
|
24
|
+
|
|
25
|
+
def make_curriculum(self):
|
|
26
|
+
raise NotImplementedError
|
|
27
|
+
|
|
28
|
+
def sample_batch(self, curriculum, batch_size):
|
|
29
|
+
"""-> (inputs, targets, mask) tensors, batch-first."""
|
|
30
|
+
raise NotImplementedError
|
|
31
|
+
|
|
32
|
+
def loss(self, output, target, mask):
|
|
33
|
+
raise NotImplementedError
|
|
34
|
+
|
|
35
|
+
def diversity(self, output, target, mask) -> float:
|
|
36
|
+
raise NotImplementedError
|
|
37
|
+
|
|
38
|
+
def set_output_proj(self, proj):
|
|
39
|
+
raise NotImplementedError
|
|
40
|
+
|
|
41
|
+
def evaluate_ood(self, model, device, num_episodes, rng, verbose_n=0, field_log=None):
|
|
42
|
+
"""-> (acc_pct, perfect_pct, breakdown_dict)"""
|
|
43
|
+
raise NotImplementedError
|
|
44
|
+
|
|
45
|
+
def evaluate_id_ablated(self, model, device, curriculum, lesson_idx):
|
|
46
|
+
"""Memory-off eval on lesson `lesson_idx` -> (acc_pct, perfect_pct)"""
|
|
47
|
+
raise NotImplementedError
|
|
48
|
+
|
|
49
|
+
def evaluate_id_combiner_stage_ablated(
|
|
50
|
+
self, model, device, curriculum, lesson_idx, skip_stages
|
|
51
|
+
):
|
|
52
|
+
"""Combiner-stage-off eval on lesson `lesson_idx` -> (acc_pct, perfect_pct).
|
|
53
|
+
Optional: only implemented by datasets/models with a multi-stage
|
|
54
|
+
split-graph combiner (see SplitGraphDNC)."""
|
|
55
|
+
raise NotImplementedError
|
|
56
|
+
|
|
57
|
+
def evaluate_robustness(self, model, device, curriculum, lesson_idx, perturbation, rng):
|
|
58
|
+
"""Same lesson-distribution eval as evaluate_id_ablated, but sampling
|
|
59
|
+
PERTURBED episodes (modality-specific corruption) instead of
|
|
60
|
+
ablating the model itself. -> (acc_pct, perfect_pct). Layer D
|
|
61
|
+
("Robustness") of the shared eval skeleton (Task/Generalization/
|
|
62
|
+
Dependency/Robustness) -- optional per dataset, NotImplementedError
|
|
63
|
+
by default."""
|
|
64
|
+
raise NotImplementedError
|
|
65
|
+
|
|
66
|
+
def field_log_header(self):
|
|
67
|
+
"""Column names (after the shared step/lesson/eval_type prefix
|
|
68
|
+
core_training.py's field_breakdown CSV always writes) for THIS
|
|
69
|
+
dataset's write_field_log() rows. Each dataset owns its own field
|
|
70
|
+
schema (graph: src/edge/dst; the KV-chain family: value/cumsum) so
|
|
71
|
+
core_training.py never hardcodes one dataset's column layout."""
|
|
72
|
+
raise NotImplementedError
|
|
73
|
+
|
|
74
|
+
def write_field_log(self, writer, file, step, lesson, eval_type, field_log):
|
|
75
|
+
raise NotImplementedError
|
|
File without changes
|