cogforge-engine 2.1.0__tar.gz → 2.1.1__tar.gz
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.
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/PKG-INFO +1 -1
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/cogforge/utils.py +23 -4
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/pyproject.toml +1 -1
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/.github/workflows/release.yml +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/.gitignore +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/LICENSE +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/README.md +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/TODO +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/cogforge/__init__.py +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/cogforge/app.py +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/cogforge/backend.py +0 -0
- {cogforge_engine-2.1.0 → cogforge_engine-2.1.1}/cogforge/models.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cogforge-engine
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.1
|
|
4
4
|
Summary: A custom autograd engine and Transformer block built from scratch.
|
|
5
5
|
Project-URL: Homepage, https://github.com/avikmjd2/cogforge
|
|
6
6
|
Author-email: Avik Majumder <avikmjd2@gmail.com>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from graphviz import Digraph
|
|
2
|
+
import numpy
|
|
2
3
|
|
|
3
4
|
def trace_graph(root_tensor):
|
|
4
5
|
"""Recursively traces the tensor graph to find all nodes and edges."""
|
|
@@ -14,25 +15,43 @@ def trace_graph(root_tensor):
|
|
|
14
15
|
build(root_tensor)
|
|
15
16
|
return nodes, edges
|
|
16
17
|
|
|
17
|
-
def
|
|
18
|
+
def draw_graph(root_tensor, max_char=50,format='svg', rankdir='LR'):
|
|
18
19
|
"""
|
|
19
20
|
Renders a computational graph starting from the given root_tensor.
|
|
20
21
|
format: output format (e.g., 'png', 'svg', 'pdf')
|
|
21
22
|
rankdir: 'LR' for left-to-right layout, 'TB' for top-to-bottom
|
|
22
23
|
"""
|
|
23
24
|
dot = Digraph(format=format, graph_attr={'rankdir': rankdir})
|
|
24
|
-
|
|
25
25
|
nodes, edges = trace_graph(root_tensor)
|
|
26
26
|
|
|
27
|
+
def format_array(arr):
|
|
28
|
+
"""Sanitizes and truncates array strings for safe Graphviz rendering."""
|
|
29
|
+
if arr is None:
|
|
30
|
+
return "None"
|
|
31
|
+
if isinstance(arr, numpy.ndarray):
|
|
32
|
+
s = numpy.array2string(arr, precision=4, suppress_small=True, separator=', ')
|
|
33
|
+
else:
|
|
34
|
+
s = str(arr)
|
|
35
|
+
|
|
36
|
+
s = s.replace('\n', '')
|
|
37
|
+
|
|
38
|
+
if len(s) > max_char:
|
|
39
|
+
s = s[:max_char-3] + "..."
|
|
40
|
+
s = s.replace('{', '\\{').replace('}', '\\}').replace('|', '\\|')
|
|
41
|
+
return s
|
|
42
|
+
|
|
27
43
|
for n in nodes:
|
|
28
44
|
uid = str(id(n))
|
|
29
45
|
shape_str = str(n.shape)
|
|
30
46
|
|
|
47
|
+
data_str = format_array(n.data)
|
|
48
|
+
grad_str = format_array(n.grad)
|
|
49
|
+
|
|
31
50
|
if n.op:
|
|
32
|
-
label = f"{{ {n.op} | shape: {shape_str} }}"
|
|
51
|
+
label = f"{{ {n.op} | shape: {shape_str} | data: {data_str} | grad: {grad_str} }}"
|
|
33
52
|
dot.node(name=uid, label=label, shape='record', style='filled', fillcolor='white')
|
|
34
53
|
else:
|
|
35
|
-
label = f"{{
|
|
54
|
+
label = f"{{ Node | shape: {shape_str} | data: {data_str} | grad: {grad_str} }}"
|
|
36
55
|
dot.node(name=uid, label=label, shape='record', style='filled', fillcolor='lightblue')
|
|
37
56
|
|
|
38
57
|
for child, parent in edges:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|