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
|
@@ -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)
|