From b12d72fe5b87e775dc062e9867f5a7e4d51b55a9 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Sat, 1 Jun 2024 16:12:42 -0700 Subject: [PATCH 1/8] Update onednn.js --- source/onednn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/onednn.js b/source/onednn.js index 1ffb304964..778305ee1b 100644 --- a/source/onednn.js +++ b/source/onednn.js @@ -21,7 +21,7 @@ onednn.Model = class { constructor(metadata, symbol) { const version = symbol.version; - this.format = `oneDNN Graph${version ? ` v${version}` : ''}`; + this.format = `oneDNN${version ? ` v${version}` : ''}`; this.runtime = `${symbol.engine_kind} ${symbol.fpmath_mode}`; this.graphs = [new onednn.Graph(metadata, symbol)]; } From ccabbcd1c7c32cdac4eb5835d9d43fefe2dec6db Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Wed, 12 Jun 2024 22:45:10 -0400 Subject: [PATCH 2/8] implement tensor sparsity calculation --- source/view.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/source/view.js b/source/view.js index 59a13c1071..bbdd7be881 100644 --- a/source/view.js +++ b/source/view.js @@ -4119,11 +4119,33 @@ view.Tensor = class { } get metrics() { + const value = this.value; + const metrics = Array.from(this._tensor.metrics || []); const keys = new Set(metrics.map((metrics) => metrics.name)); if (!keys.has('sparisity')) { - // metrics.push(new view.Argument('sparisity', 0, 'float32')); + let num_zeros = 0; + let num_parameters = 0; + let stack = [value]; + while (stack.length > 0) { + const val = stack.pop(); + if (Array.isArray(val)) { + for (const element of val) { + stack.push(element); + } + } else { + num_zeros += Number(val == 0); + num_parameters += 1; + } + } + + if (num_parameters > 0) { + metrics.push(new view.Argument('sparisity', num_zeros / num_parameters, 'float32')); + } else { + metrics.push(new view.Argument('sparisity', 0, 'float32')); + } } + return metrics; } }; From eedb5f02d58facf814d92001d6328cabb84b3266 Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Thu, 13 Jun 2024 00:02:11 -0400 Subject: [PATCH 3/8] add tensor metrics view --- source/view.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/source/view.js b/source/view.js index bbdd7be881..aeb909efbf 100644 --- a/source/view.js +++ b/source/view.js @@ -2686,6 +2686,9 @@ view.ValueTextView = class extends view.Control { line.innerText = item; line.style.whiteSpace = style; break; + case 'percentage': + line.innerText = `${(item * 100).toFixed(3)}%`; + break; default: line.innerText = item; break; @@ -3162,7 +3165,16 @@ view.TensorSidebar = class extends view.ObjectSidebar { if (value.type) { const item = new view.ValueView(this._view, value, ''); this.add('type', item); - item.toggle(); + } + + if (value.initializer && value.initializer.category == 'Initializer') { + this.addHeader('Metrics'); + + const tensor = new view.Tensor(value.initializer); + const metrics = tensor.metrics; + for (const metric of metrics) { + this.addProperty(metric.name, [metric.value], metric.style); + } } } }; @@ -3623,10 +3635,11 @@ view.FindSidebar = class extends view.Control { view.Argument = class { - constructor(name, value, type) { + constructor(name, value, type, style) { this.name = name; this.value = value; this.type = type; + this.style = style } }; @@ -4123,7 +4136,7 @@ view.Tensor = class { const metrics = Array.from(this._tensor.metrics || []); const keys = new Set(metrics.map((metrics) => metrics.name)); - if (!keys.has('sparisity')) { + if (!keys.has('sparsity')) { let num_zeros = 0; let num_parameters = 0; let stack = [value]; @@ -4140,9 +4153,9 @@ view.Tensor = class { } if (num_parameters > 0) { - metrics.push(new view.Argument('sparisity', num_zeros / num_parameters, 'float32')); + metrics.push(new view.Argument('sparsity', num_zeros / num_parameters, 'float32', 'percentage')); } else { - metrics.push(new view.Argument('sparisity', 0, 'float32')); + metrics.push(new view.Argument('sparsity', 0, 'float32', 'percentage')); } } From 70272907e97261d2e7cfc229f4457d68a153c406 Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Thu, 13 Jun 2024 00:20:40 -0400 Subject: [PATCH 4/8] lint, only display one decimal place for percentage --- source/view.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/view.js b/source/view.js index aeb909efbf..a09ee96f50 100644 --- a/source/view.js +++ b/source/view.js @@ -2687,7 +2687,7 @@ view.ValueTextView = class extends view.Control { line.style.whiteSpace = style; break; case 'percentage': - line.innerText = `${(item * 100).toFixed(3)}%`; + line.innerText = `${(item * 100).toFixed(1)}%`; break; default: line.innerText = item; @@ -3167,7 +3167,7 @@ view.TensorSidebar = class extends view.ObjectSidebar { this.add('type', item); } - if (value.initializer && value.initializer.category == 'Initializer') { + if (value.initializer && value.initializer.category === 'Initializer') { this.addHeader('Metrics'); const tensor = new view.Tensor(value.initializer); @@ -3639,7 +3639,7 @@ view.Argument = class { this.name = name; this.value = value; this.type = type; - this.style = style + this.style = style; } }; @@ -4139,7 +4139,7 @@ view.Tensor = class { if (!keys.has('sparsity')) { let num_zeros = 0; let num_parameters = 0; - let stack = [value]; + const stack = [value]; while (stack.length > 0) { const val = stack.pop(); if (Array.isArray(val)) { @@ -4147,7 +4147,7 @@ view.Tensor = class { stack.push(element); } } else { - num_zeros += Number(val == 0); + num_zeros += Number(val === 0); num_parameters += 1; } } From a18ac8b8c45d7fef9f5bad5e641f242f31340a46 Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Thu, 13 Jun 2024 00:28:06 -0400 Subject: [PATCH 5/8] add note about double initialization --- source/view.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/view.js b/source/view.js index a09ee96f50..62daf5c4d3 100644 --- a/source/view.js +++ b/source/view.js @@ -3170,6 +3170,8 @@ view.TensorSidebar = class extends view.ObjectSidebar { if (value.initializer && value.initializer.category === 'Initializer') { this.addHeader('Metrics'); + // view.Tensor is also initialized in view.ValueView + // future work could cache the first initialization const tensor = new view.Tensor(value.initializer); const metrics = tensor.metrics; for (const metric of metrics) { From 97546a4e68262b0130afe46714e7ebc7c0eb8c56 Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Thu, 13 Jun 2024 09:02:45 -0400 Subject: [PATCH 6/8] remove trailing space --- source/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/view.js b/source/view.js index 62daf5c4d3..d086a60b11 100644 --- a/source/view.js +++ b/source/view.js @@ -3171,7 +3171,7 @@ view.TensorSidebar = class extends view.ObjectSidebar { this.addHeader('Metrics'); // view.Tensor is also initialized in view.ValueView - // future work could cache the first initialization + // future work could cache the first initialization const tensor = new view.Tensor(value.initializer); const metrics = tensor.metrics; for (const metric of metrics) { From 9a099b79eedf558f98e08ff1dcfecb398d96e241 Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Fri, 14 Jun 2024 02:03:59 -0400 Subject: [PATCH 7/8] remove comment about double initialization --- source/view.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/view.js b/source/view.js index d086a60b11..a09ee96f50 100644 --- a/source/view.js +++ b/source/view.js @@ -3170,8 +3170,6 @@ view.TensorSidebar = class extends view.ObjectSidebar { if (value.initializer && value.initializer.category === 'Initializer') { this.addHeader('Metrics'); - // view.Tensor is also initialized in view.ValueView - // future work could cache the first initialization const tensor = new view.Tensor(value.initializer); const metrics = tensor.metrics; for (const metric of metrics) { From 5fbe0128f05b7f5638f46e3e5b657f326987c5c4 Mon Sep 17 00:00:00 2001 From: Kyle Sayers Date: Sat, 15 Jun 2024 09:59:16 -0400 Subject: [PATCH 8/8] cache tensor metrics --- source/view.js | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/source/view.js b/source/view.js index a09ee96f50..46b691b804 100644 --- a/source/view.js +++ b/source/view.js @@ -3651,6 +3651,7 @@ view.Tensor = class { this._encoding = tensor.encoding; this._layout = tensor.type.layout; this._stride = tensor.stride; + this._metrics = null; switch (this._encoding) { case undefined: case '': @@ -4132,34 +4133,38 @@ view.Tensor = class { } get metrics() { - const value = this.value; - - const metrics = Array.from(this._tensor.metrics || []); - const keys = new Set(metrics.map((metrics) => metrics.name)); - if (!keys.has('sparsity')) { - let num_zeros = 0; - let num_parameters = 0; - const stack = [value]; - while (stack.length > 0) { - const val = stack.pop(); - if (Array.isArray(val)) { - for (const element of val) { - stack.push(element); + if (this._metrics === null) { + const value = this.value; + + const metrics = Array.from(this._tensor.metrics || []); + const keys = new Set(metrics.map((metrics) => metrics.name)); + if (!keys.has('sparsity')) { + let num_zeros = 0; + let num_parameters = 0; + const stack = [value]; + while (stack.length > 0) { + const val = stack.pop(); + if (Array.isArray(val)) { + for (const element of val) { + stack.push(element); + } + } else { + num_zeros += Number(val === 0); + num_parameters += 1; } + } + + if (num_parameters > 0) { + metrics.push(new view.Argument('sparsity', num_zeros / num_parameters, 'float32', 'percentage')); } else { - num_zeros += Number(val === 0); - num_parameters += 1; + metrics.push(new view.Argument('sparsity', 0, 'float32', 'percentage')); } } - if (num_parameters > 0) { - metrics.push(new view.Argument('sparsity', num_zeros / num_parameters, 'float32', 'percentage')); - } else { - metrics.push(new view.Argument('sparsity', 0, 'float32', 'percentage')); - } + this._metrics = metrics; } - return metrics; + return this._metrics; } };