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
@@ -0,0 +1,123 @@
1
+ """
2
+ file: data/common/graph_io.py
3
+
4
+ Shared raw-edge-file loading + label-mapping for custom graph datasets -
5
+ used by BOTH the training-side graph_traversal.py (to train on a supplied
6
+ graph instead of a synthetic one) and the inference-side
7
+ graph_traversal_task.py (which used to define these functions itself).
8
+ Moved here so the two can never silently drift apart - same
9
+ train/inference-parity rationale every other data/<modality>_dataset.py
10
+ already follows relative to its inference/tasks/<modality>_task.py twin.
11
+
12
+ Format: .csv / .tsv / .txt: one edge per row, "src,dst,line" ('#' comments
13
+ and a src/source/from header row are skipped). .json: [["src","dst","line"],
14
+ ...] or {"edges": [...]} (rows may also be {"src":..,"dst":..,"line":..}).
15
+ Names are mapped to distinct 0..999 labels with a fixed random.Random(seed)
16
+ unless every field is already an integer in [0,1000), in which case the
17
+ integers are used directly.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import csv
23
+ import json
24
+ import os
25
+ import random
26
+
27
+ from initium.data.common.real_data import resolve_link_paths
28
+
29
+ LABEL_RANGE = 1000
30
+ _HEADER_FIRST_FIELDS = {"src", "source", "from"}
31
+
32
+
33
+ def _is_label(x: str) -> bool:
34
+ try:
35
+ return 0 <= int(x) < LABEL_RANGE
36
+ except (TypeError, ValueError):
37
+ return False
38
+
39
+
40
+ def _load_raw_edges_one(path: str) -> list[tuple[str, str, str]]:
41
+ ext = os.path.splitext(path)[1].lower()
42
+ rows = []
43
+ if ext == ".json":
44
+ with open(path) as f:
45
+ data = json.load(f)
46
+ if isinstance(data, dict):
47
+ data = data.get("edges", data.get("raw_edges"))
48
+ if not isinstance(data, list):
49
+ raise ValueError(f"{path}: JSON must be a list of edges or {{'edges': [...]}}")
50
+ rows = data
51
+ else:
52
+ with open(path, newline="") as f:
53
+ for row in csv.reader(f, delimiter="\t" if ext == ".tsv" else ","):
54
+ if not row or row[0].strip().startswith("#"):
55
+ continue
56
+ rows.append(row)
57
+
58
+ edges: list[tuple[str, str, str]] = []
59
+ for i, row in enumerate(rows):
60
+ if isinstance(row, dict):
61
+ values = [row.get("src"), row.get("dst"), row.get("line")]
62
+ else:
63
+ values = row
64
+ if len(values) != 3 or any(x is None for x in values):
65
+ raise ValueError(f"{path}: row {i} is not 'src,dst,line': {values!r}")
66
+ fields = [str(x).strip() for x in values]
67
+ if i == 0 and fields[0].lower() in _HEADER_FIRST_FIELDS:
68
+ continue
69
+ edges.append((fields[0], fields[1], fields[2]))
70
+ if not edges:
71
+ raise ValueError(f"{path}: no edges found")
72
+ return edges
73
+
74
+
75
+ def load_raw_edges(path) -> list[tuple[str, str, str]]:
76
+ """`path` may be a single edge file, or a directory / glob pattern /
77
+ '+'-joined list of these (see real_data.resolve_link_paths) -- e.g. an
78
+ entire folder of edge-list files, each contributing its own edges to
79
+ one combined graph. Rows are concatenated in resolved-path order; the
80
+ per-file header-row / '#'-comment skip still applies independently to
81
+ each file (so each file may have its own header)."""
82
+ paths = resolve_link_paths(path)
83
+ all_edges: list[tuple[str, str, str]] = []
84
+ for p in paths:
85
+ all_edges.extend(_load_raw_edges_one(p))
86
+ return all_edges
87
+
88
+
89
+ def build_graph_from_raw_edges(raw_edges, label_seed: int = 1234):
90
+ """-> (edges [(src_label, edge_label, dst_label)], node_labels, adjacency)."""
91
+ if all(_is_label(x) for e in raw_edges for x in e):
92
+ raw_edges = [tuple(str(int(x)) for x in e) for e in raw_edges]
93
+ numeric = True
94
+ else:
95
+ numeric = False
96
+
97
+ stations = sorted({s for s, _, _ in raw_edges} | {d for _, d, _ in raw_edges})
98
+ lines = sorted({l for _, _, l in raw_edges})
99
+
100
+ if numeric:
101
+ station_to_label = {s: int(s) for s in stations}
102
+ line_to_label = {l: int(l) for l in lines}
103
+ else:
104
+ need = len(stations) + len(lines)
105
+ if need > LABEL_RANGE:
106
+ raise ValueError(f"graph has {need} distinct stations+lines; max is {LABEL_RANGE}")
107
+ rng = random.Random(label_seed)
108
+ all_labels = rng.sample(range(LABEL_RANGE), need)
109
+ station_to_label = dict(zip(stations, all_labels[: len(stations)]))
110
+ line_to_label = dict(zip(lines, all_labels[len(stations) :]))
111
+
112
+ edges = [(station_to_label[s], line_to_label[l], station_to_label[d]) for s, d, l in raw_edges]
113
+ station_idx = {s: i for i, s in enumerate(stations)}
114
+ adjacency: dict[int, list[tuple[int, int]]] = {i: [] for i in range(len(stations))}
115
+ for s, d, l in raw_edges:
116
+ adjacency[station_idx[s]].append((station_idx[d], line_to_label[l]))
117
+ node_labels = [station_to_label[s] for s in stations]
118
+ return edges, node_labels, adjacency
119
+
120
+
121
+ def load_graph(path: str, label_seed: int = 1234):
122
+ """One-shot: raw edge file -> (edges, node_labels, adjacency)."""
123
+ return build_graph_from_raw_edges(load_raw_edges(path), label_seed=label_seed)