Skip to content

Commit 6e60e95

Browse files
committed
Add ExecuTorch test file (#1175)
1 parent eedae23 commit 6e60e95

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

source/executorch.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ executorch.Graph = class {
5050
this.outputs = [];
5151
this.nodes = [];
5252
const values = new Map();
53+
values.tensors = (index, items) => {
54+
const list = [];
55+
for (let i = 0; i < items.length; i++) {
56+
const item = items[i];
57+
const type = item ? new executorch.TensorType(item) : null;
58+
let initializer = null;
59+
if (item && item.data_buffer_idx > 0) {
60+
initializer = new executorch.Tensor(item, target);
61+
}
62+
const identifier = items.length > 1 ? `${index}.${i}` : index.toString();
63+
const value = new executorch.Value(identifier, type, initializer);
64+
list.push(value);
65+
}
66+
return list;
67+
};
5368
values.map = (index, output) => {
5469
if (!values.has(index)) {
5570
const executorch_flatbuffer = executorch.schema.executorch_flatbuffer;
@@ -58,34 +73,32 @@ executorch.Graph = class {
5873
if (output && !tensor) {
5974
const value = [new executorch.Value(index.toString(), null, null)];
6075
values.set(index, { type: null, value });
61-
} else if (tensor) {
62-
const tensors = val instanceof executorch_flatbuffer.Tensor ? [val] : Array.from(val.items).map((arg) => plan.values[arg].val);
63-
const list = [];
64-
for (let i = 0; i < tensors.length; i++) {
65-
const tensor = tensors[i];
66-
const type = new executorch.TensorType(tensor);
67-
let initializer = null;
68-
if (val.data_buffer_idx > 0) {
69-
initializer = new executorch.Tensor(tensor, target);
70-
}
71-
const identifier = tensors.length > 1 ? `${index}.${i}` : index.toString();
72-
const value = new executorch.Value(identifier, type, initializer);
73-
list.push(value);
74-
}
75-
values.set(index, { type: null, value: list });
76-
} else if (val instanceof executorch_flatbuffer.Bool) {
77-
values.set(index, { type: 'int64', value: val.bool_val });
76+
} else if (val instanceof executorch_flatbuffer.Null) {
77+
values.set(index, { type: 'attribute', value: null });
7878
} else if (val instanceof executorch_flatbuffer.Int) {
7979
values.set(index, { type: 'int64', value: val.int_val });
80-
} else if (val instanceof executorch_flatbuffer.IntList) {
81-
const list = val.items.map((index) => plan.values[index].val.int_val);
82-
values.set(index, { type: 'int64[]', value: list });
80+
} else if (val instanceof executorch_flatbuffer.Bool) {
81+
values.set(index, { type: 'int64', value: val.bool_val });
8382
} else if (val instanceof executorch_flatbuffer.Double) {
8483
values.set(index, { type: 'float64', value: val.double_val });
84+
} else if (val instanceof executorch_flatbuffer.Tensor) {
85+
const items = [val];
86+
values.set(index, { type: null, value: values.tensors(index, items) });
8587
} else if (val instanceof executorch_flatbuffer.String) {
8688
values.set(index, { type: 'string', value: val.string_val });
87-
} else if (val instanceof executorch_flatbuffer.Null) {
88-
values.set(index, { type: 'attribute', value: null });
89+
} else if (val instanceof executorch_flatbuffer.IntList) {
90+
const list = val.items.map((index) => plan.values[index].val.int_val);
91+
values.set(index, { type: 'int64[]', value: list });
92+
} else if (val instanceof executorch_flatbuffer.DoubleList) {
93+
throw new executorch.Error('executorch_flatbuffer.DoubleList not implemented.');
94+
} else if (val instanceof executorch_flatbuffer.BoolList) {
95+
throw new executorch.Error('executorch_flatbuffer.BoolList not implemented.');
96+
} else if (val instanceof executorch_flatbuffer.TensorList) {
97+
const items = Array.from(val.items).map((arg) => arg === -1 ? null : plan.values[arg].val);
98+
values.set(index, { type: null, value: values.tensors(index, items) });
99+
} else if (val instanceof executorch_flatbuffer.OptionalTensorList) {
100+
const items = Array.from(val.items).map((arg) => arg === -1 ? null : plan.values[arg].val);
101+
values.set(index, { type: null, value: values.tensors(index, items) });
89102
} else {
90103
throw new Error(`Value type '${val.constructor.name}' not implemented.`);
91104
}

test/models.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,7 @@
21602160
"target": "mobilenet_v2.pte",
21612161
"source": "https://github.com/user-attachments/files/18462557/mobilenet_v2.pte.zip[mobilenet_v2.pte]",
21622162
"format": "ExecuTorch v0",
2163+
"tags": "validation",
21632164
"link": "https://github.com/lutzroeder/netron/issues/1211"
21642165
},
21652166
{
@@ -2176,6 +2177,13 @@
21762177
"format": "ExecuTorch v0",
21772178
"link": "https://github.com/lutzroeder/netron/issues/1175"
21782179
},
2180+
{
2181+
"type": "executorch",
2182+
"target": "nanogpt.pte.zip",
2183+
"source": "https://github.com/user-attachments/files/19726086/nanogpt.pte.zip",
2184+
"format": "ExecuTorch v0",
2185+
"link": "https://github.com/lutzroeder/netron/issues/1175"
2186+
},
21792187
{
21802188
"type": "executorch",
21812189
"target": "style_transfer_candy_coreml.pte",

0 commit comments

Comments
 (0)