@dxo/graph 0.0.0 → 0.0.9
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.
- package/README.md +3 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/module-graph.d.ts +10 -0
- package/dist/module-graph.d.ts.map +1 -0
- package/dist/module-graph.js +70 -0
- package/dist/module-graph.js.map +1 -0
- package/package.json +37 -8
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
# @dxo/graph
|
|
2
2
|
|
|
3
|
-
Placeholder
|
|
3
|
+
**Placeholder — developer preview, API unstable.**
|
|
4
|
+
|
|
5
|
+
Serializable model-graph IR for Studio, CLI, and exporters. Distinguishes **module** / **execution** / **kernel** views. Not a Netron replacement yet; no full format parsers in this stub.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI-agnostic model graph IR placeholder (Living `10` / `@dxo/graph`).
|
|
3
|
+
* Module graph ≠ execution trace ≠ kernel graph — do not collapse them.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MODEL_GRAPH_FORMAT: "dxo-model-graph";
|
|
6
|
+
export declare const MODEL_GRAPH_VERSION: 0;
|
|
7
|
+
export type GraphViewKind = 'module' | 'execution' | 'kernel';
|
|
8
|
+
export type GraphNode = {
|
|
9
|
+
id: string;
|
|
10
|
+
kind: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
modulePath?: string;
|
|
13
|
+
attrs?: Record<string, unknown>;
|
|
14
|
+
};
|
|
15
|
+
export type GraphEdge = {
|
|
16
|
+
id: string;
|
|
17
|
+
source: string;
|
|
18
|
+
target: string;
|
|
19
|
+
tensor?: {
|
|
20
|
+
shape?: number[];
|
|
21
|
+
dtype?: string;
|
|
22
|
+
device?: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type ModelGraphV0 = {
|
|
26
|
+
format: typeof MODEL_GRAPH_FORMAT;
|
|
27
|
+
version: typeof MODEL_GRAPH_VERSION;
|
|
28
|
+
view: GraphViewKind;
|
|
29
|
+
nodes: GraphNode[];
|
|
30
|
+
edges: GraphEdge[];
|
|
31
|
+
};
|
|
32
|
+
export declare function graphVersion(): string;
|
|
33
|
+
export { emptyModelGraph, moduleGraphFromLinear, moduleGraphFromModule, moduleGraphFromSequential, serializeModelGraph, } from './module-graph.js';
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,kBAAkB,EAAG,iBAA0B,CAAC;AAC7D,eAAO,MAAM,mBAAmB,EAAG,CAAU,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE9D,MAAM,MAAM,SAAS,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB,MAAM,EAAE,OAAO,kBAAkB,CAAC;IAClC,OAAO,EAAE,OAAO,mBAAmB,CAAC;IACpC,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,KAAK,EAAE,SAAS,EAAE,CAAC;CACtB,CAAC;AAEF,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,OAAO,EACH,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,GACtB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI-agnostic model graph IR placeholder (Living `10` / `@dxo/graph`).
|
|
3
|
+
* Module graph ≠ execution trace ≠ kernel graph — do not collapse them.
|
|
4
|
+
*/
|
|
5
|
+
export const MODEL_GRAPH_FORMAT = 'dxo-model-graph';
|
|
6
|
+
export const MODEL_GRAPH_VERSION = 0;
|
|
7
|
+
export function graphVersion() {
|
|
8
|
+
return `${MODEL_GRAPH_FORMAT}@${MODEL_GRAPH_VERSION}`;
|
|
9
|
+
}
|
|
10
|
+
export { emptyModelGraph, moduleGraphFromLinear, moduleGraphFromModule, moduleGraphFromSequential, serializeModelGraph, } from './module-graph.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAA0B,CAAC;AAC7D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAU,CAAC;AA2B9C,MAAM,UAAU,YAAY;IACxB,OAAO,GAAG,kBAAkB,IAAI,mBAAmB,EAAE,CAAC;AAC1D,CAAC;AAED,OAAO,EACH,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,GACtB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Module } from '@dxo/nn';
|
|
2
|
+
import { Linear, Sequential } from '@dxo/nn';
|
|
3
|
+
import { type GraphViewKind, type ModelGraphV0 } from './index.js';
|
|
4
|
+
export declare function emptyModelGraph(view?: GraphViewKind): ModelGraphV0;
|
|
5
|
+
export declare function serializeModelGraph(graph: ModelGraphV0): string;
|
|
6
|
+
export declare function moduleGraphFromLinear(linear: Linear, path?: string): ModelGraphV0;
|
|
7
|
+
export declare function moduleGraphFromSequential(seq: Sequential, path?: string): ModelGraphV0;
|
|
8
|
+
/** Build a module graph from any @dxo/nn Module (Linear or Sequential supported). */
|
|
9
|
+
export declare function moduleGraphFromModule(mod: Module, path?: string): ModelGraphV0;
|
|
10
|
+
//# sourceMappingURL=module-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-graph.d.ts","sourceRoot":"","sources":["../src/module-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,MAAM,EAAQ,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAkC,KAAK,aAAa,EAA2C,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5I,wBAAgB,eAAe,CAAC,IAAI,GAAE,aAAwB,GAAG,YAAY,CAQ5E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAE/D;AAUD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,SAAW,GAAG,YAAY,CAenF;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,SAAe,GAAG,YAAY,CA2B5F;AAED,qFAAqF;AACrF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,SAAU,GAAG,YAAY,CAI/E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Linear, Relu, Sequential } from '@dxo/nn';
|
|
2
|
+
import { MODEL_GRAPH_FORMAT, MODEL_GRAPH_VERSION } from './index.js';
|
|
3
|
+
export function emptyModelGraph(view = 'module') {
|
|
4
|
+
return {
|
|
5
|
+
format: MODEL_GRAPH_FORMAT,
|
|
6
|
+
version: MODEL_GRAPH_VERSION,
|
|
7
|
+
view,
|
|
8
|
+
nodes: [],
|
|
9
|
+
edges: [],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function serializeModelGraph(graph) {
|
|
13
|
+
return JSON.stringify(graph);
|
|
14
|
+
}
|
|
15
|
+
function node(id, kind, label, modulePath, attrs) {
|
|
16
|
+
return { id, kind, label, modulePath, attrs };
|
|
17
|
+
}
|
|
18
|
+
function edge(id, source, target, tensor) {
|
|
19
|
+
return { id, source, target, tensor };
|
|
20
|
+
}
|
|
21
|
+
export function moduleGraphFromLinear(linear, path = 'linear') {
|
|
22
|
+
const nodes = [
|
|
23
|
+
node('input', 'tensor', 'input'),
|
|
24
|
+
node('linear', 'Linear', 'Linear', path, {
|
|
25
|
+
inFeatures: linear.inFeatures,
|
|
26
|
+
outFeatures: linear.outFeatures,
|
|
27
|
+
params: ['weight', 'bias'],
|
|
28
|
+
}),
|
|
29
|
+
node('output', 'tensor', 'output'),
|
|
30
|
+
];
|
|
31
|
+
const edges = [
|
|
32
|
+
edge('e-in-linear', 'input', 'linear', { dtype: 'f32' }),
|
|
33
|
+
edge('e-linear-out', 'linear', 'output', { dtype: 'f32' }),
|
|
34
|
+
];
|
|
35
|
+
return { format: MODEL_GRAPH_FORMAT, version: MODEL_GRAPH_VERSION, view: 'module', nodes, edges };
|
|
36
|
+
}
|
|
37
|
+
export function moduleGraphFromSequential(seq, path = 'sequential') {
|
|
38
|
+
const nodes = [node('input', 'tensor', 'input')];
|
|
39
|
+
const edges = [];
|
|
40
|
+
let prev = 'input';
|
|
41
|
+
seq.layers.forEach((layer, i) => {
|
|
42
|
+
const id = `layer_${i}`;
|
|
43
|
+
if (layer instanceof Linear) {
|
|
44
|
+
nodes.push(node(id, 'Linear', `Linear(${layer.inFeatures}->${layer.outFeatures})`, `${path}/${id}`, {
|
|
45
|
+
inFeatures: layer.inFeatures,
|
|
46
|
+
outFeatures: layer.outFeatures,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
else if (layer instanceof Relu) {
|
|
50
|
+
nodes.push(node(id, 'Relu', 'Relu', `${path}/${id}`));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
nodes.push(node(id, layer.constructor.name, layer.constructor.name, `${path}/${id}`));
|
|
54
|
+
}
|
|
55
|
+
edges.push(edge(`e-${prev}-${id}`, prev, id, { dtype: 'f32' }));
|
|
56
|
+
prev = id;
|
|
57
|
+
});
|
|
58
|
+
nodes.push(node('output', 'tensor', 'output'));
|
|
59
|
+
edges.push(edge(`e-${prev}-output`, prev, 'output', { dtype: 'f32' }));
|
|
60
|
+
return { format: MODEL_GRAPH_FORMAT, version: MODEL_GRAPH_VERSION, view: 'module', nodes, edges };
|
|
61
|
+
}
|
|
62
|
+
/** Build a module graph from any @dxo/nn Module (Linear or Sequential supported). */
|
|
63
|
+
export function moduleGraphFromModule(mod, path = 'model') {
|
|
64
|
+
if (mod instanceof Sequential)
|
|
65
|
+
return moduleGraphFromSequential(mod, path);
|
|
66
|
+
if (mod instanceof Linear)
|
|
67
|
+
return moduleGraphFromLinear(mod, path);
|
|
68
|
+
throw new Error(`moduleGraphFromModule: unsupported module ${mod.constructor.name}`);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=module-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-graph.js","sourceRoot":"","sources":["../src/module-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAsD,kBAAkB,EAAE,mBAAmB,EAAqB,MAAM,YAAY,CAAC;AAE5I,MAAM,UAAU,eAAe,CAAC,OAAsB,QAAQ;IAC1D,OAAO;QAC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,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAChE,IAAI,GAAG,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAEvE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AACtG,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,qBAAqB,CAAC,GAAW,EAAE,IAAI,GAAG,OAAO;IAC7D,IAAI,GAAG,YAAY,UAAU;QAAE,OAAO,yBAAyB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3E,IAAI,GAAG,YAAY,MAAM;QAAE,OAAO,qBAAqB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnE,MAAM,IAAI,KAAK,CAAC,6CAA6C,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;AACzF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
2
|
+
"name": "@dxo/graph",
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "DXO model graph IR — module / execution / kernel views (placeholder, API unstable)",
|
|
6
|
+
"license": "MIT OR Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@dxo/nn": "0.0.9"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"dxo",
|
|
27
|
+
"graph",
|
|
28
|
+
"model",
|
|
29
|
+
"netron",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/ai4waifu/dxo-framework.git"
|
|
38
|
+
}
|
|
10
39
|
}
|