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.
Files changed (71) hide show
  1. initium/LNN_controller/cfc_backbone_parallel.py +265 -0
  2. initium/LNN_controller/cfc_controller.py +325 -0
  3. initium/LNN_controller/chained_controller.py +83 -0
  4. initium/LNN_controller/hybrid_controller.py +90 -0
  5. initium/MoE/README.md +1 -0
  6. initium/MoE/moe_layer.py +552 -0
  7. initium/__init__.py +1 -0
  8. initium/config/controller_config.py +86 -0
  9. initium/config/train_config.py +64 -0
  10. initium/core_training.py +2182 -0
  11. initium/data/__init__.py +0 -0
  12. initium/data/audio/__init__.py +0 -0
  13. initium/data/audio/audio_dataset.py +96 -0
  14. initium/data/base_dataset.py +75 -0
  15. initium/data/common/__init__.py +0 -0
  16. initium/data/common/chain_task.py +542 -0
  17. initium/data/common/digit_codec.py +85 -0
  18. initium/data/common/graph_io.py +123 -0
  19. initium/data/common/real_data.py +747 -0
  20. initium/data/dataset_registry.py +59 -0
  21. initium/data/graph_traversal/__init__.py +0 -0
  22. initium/data/graph_traversal/graph_traversal.py +746 -0
  23. initium/data/multimodal/__init__.py +0 -0
  24. initium/data/multimodal/multimodal_dataset.py +401 -0
  25. initium/data/text/__init__.py +0 -0
  26. initium/data/text/text_dataset.py +79 -0
  27. initium/data/video/__init__.py +0 -0
  28. initium/data/video/video_dataset.py +85 -0
  29. initium/inference/__init__.py +1 -0
  30. initium/inference/cache/__init__.py +1 -0
  31. initium/inference/cache/base_cache.py +112 -0
  32. initium/inference/cache/cache_config.py +21 -0
  33. initium/inference/cache/cache_registry.py +99 -0
  34. initium/inference/cache/cached_engine.py +264 -0
  35. initium/inference/cache/keys.py +77 -0
  36. initium/inference/cache/prefix_cache.py +59 -0
  37. initium/inference/cache/result_cache.py +57 -0
  38. initium/inference/cache/state_utils.py +74 -0
  39. initium/inference/cache/stores.py +167 -0
  40. initium/inference/capabilities.py +86 -0
  41. initium/inference/checkpoint_io.py +63 -0
  42. initium/inference/engine.py +88 -0
  43. initium/inference/inference_config.py +22 -0
  44. initium/inference/metrics.py +103 -0
  45. initium/inference/model_loader.py +270 -0
  46. initium/inference/run_inference.py +526 -0
  47. initium/inference/run_logging.py +173 -0
  48. initium/inference/tasks/__init__.py +1 -0
  49. initium/inference/tasks/audio_task.py +114 -0
  50. initium/inference/tasks/base_task.py +60 -0
  51. initium/inference/tasks/graph_traversal_task.py +235 -0
  52. initium/inference/tasks/multimodal_task.py +74 -0
  53. initium/inference/tasks/task_registry.py +68 -0
  54. initium/inference/tasks/text_task.py +114 -0
  55. initium/inference/tasks/video_task.py +114 -0
  56. initium/mamba_controller/mamba2_controller.py +433 -0
  57. initium/mamba_controller/mamba3_controller.py +242 -0
  58. initium/mamba_controller/mamba_backbone_parallel.py +291 -0
  59. initium/mamba_controller/mamba_controller.py +983 -0
  60. initium/mamba_controller/split_graph_dnc.py +623 -0
  61. initium/memory_manipulation/dynamic_memory_resize.py +157 -0
  62. initium/memory_manipulation/dynamic_n_controller.py +152 -0
  63. initium/memory_manipulation/link_matrix_ablation.py +130 -0
  64. initium/memory_manipulation/nvrtc_compat.py +143 -0
  65. initium/memory_manipulation/stochastic_write_head_v2.py +545 -0
  66. initium/setup_wheels.py +175 -0
  67. initium_deeplearning-0.1.0.dist-info/METADATA +253 -0
  68. initium_deeplearning-0.1.0.dist-info/RECORD +71 -0
  69. initium_deeplearning-0.1.0.dist-info/WHEEL +4 -0
  70. initium_deeplearning-0.1.0.dist-info/entry_points.txt +3 -0
  71. initium_deeplearning-0.1.0.dist-info/licenses/LICENSE +674 -0
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