Repository navigation
Add 2D Autoencoder and GMM Integration on Siracusa Target #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
3e6c32a
8768f3f
23ef45c
aef02cf
fbbab36
ef73cb9
ab145b3
c1f10da
0040308
5f8e95d
d469b51
2a95209
4b42679
e72b6b1
481079b
4ba354b
bb503f9
7541920
3efa174
7fa704e
e09cf7e
93b1a01
25a1eef
dfa7cb9
1ccdb76
7f05097
3cc17dc
f951959
b6504a2
5e7c432
7b858c1
22cad38
6681277
e3d6b4f
1ade616
83dffff
d07ad80
3906285
8dc9d40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from itertools import zip_longest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import List, Tuple | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -337,13 +338,18 @@ class MulLayer(SingleOperationPerElementLayer): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorRepresentation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| channels_first) -> Tuple[Shape, Shape]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if inputShapes[1] == () or inputShapes[1] == []: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[1] = (1,) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lhsShape = tuple(inputShapes[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rhsShape = tuple(inputShapes[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| broadcastShape = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(inputShapes[0]) > len(inputShapes[1]): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[1] = inputShapes[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[0] = inputShapes[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for lhsDim, rhsDim in zip_longest(reversed(lhsShape), reversed(rhsShape), fillvalue = 1): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if lhsDim != rhsDim and lhsDim != 1 and rhsDim != 1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Cannot broadcast Mul input shapes {lhsShape} and {rhsShape}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| broadcastShape.append(rhsDim if lhsDim == 1 else lhsDim) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| broadcastShape = tuple(reversed(broadcastShape)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[0] = broadcastShape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[1] = rhsShape if np.prod(rhsShape) == 1 else broadcastShape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (inputShapes, outputShapes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -355,7 +361,7 @@ def __init__(self, maps: List[NodeMapper]): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorRepresentation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| channels_first) -> Tuple[Shape, Shape]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(inputShapes) == 3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[2] = inputShapes[1][0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShapes[2] = (inputShapes[1][0],) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (inputShapes, outputShapes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def computeOps(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -435,6 +441,28 @@ def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorReprese | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (inputShapes, outputShapes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ReduceLogSumExpLayer(ONNXLayer): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self, maps: List[NodeMapper]): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| super().__init__(maps) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def computeShapes(self, inputShapes: Shape, outputShapes: Shape, operatorRepresentation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| channels_first) -> Tuple[Shape, Shape]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| axes = [int(axis) for axis in operatorRepresentation['axes']] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inputShape = list(inputShapes[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if operatorRepresentation['keepdims']: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputShape = list(inputShape) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for axis in axes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputShape[axis] = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputShape = [dim for idx, dim in enumerate(inputShape) if idx not in axes] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(outputShape) == 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| outputShape = [1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (inputShapes, [outputShape]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+449
to
+463
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
# Confirm the copy import in the layers module.
rg -n '^\s*import copy|^\s*from copy import' Deeploy/Targets/Generic/Layers.pyRepository: pulp-platform/Deeploy Length of output: 173 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- matching declarations and callers ---'
rg -n -C 8 'class ReduceLogSumExp(Parser|Layer)|ReduceLogSumExp|def broadcast|def parseNodeCtxt|computeShapes\(' Deeploy
printf '%s\n' '--- relevant Layers.py ranges ---'
sed -n '1,25p' Deeploy/Targets/Generic/Layers.py
sed -n '425,475p' Deeploy/Targets/Generic/Layers.py
printf '%s\n' '--- parser and parse/broadcast implementation locations ---'
rg -l 'class ReduceLogSumExpParser|def broadcast|def parseNodeCtxt' Deeploy | head -20Repository: pulp-platform/Deeploy Length of output: 42014 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- exact symbol matches ---'
rg -n -C 12 'ReduceLogSumExp|def broadcast|def parseNodeCtxt' Deeploy/Targets/Generic Deeploy | head -240
printf '%s\n' '--- layer source ---'
sed -n '440,470p' Deeploy/Targets/Generic/Layers.py
printf '%s\n' '--- copy import ---'
sed -n '1,10p' Deeploy/Targets/Generic/Layers.pyRepository: pulp-platform/Deeploy Length of output: 24719 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- ReduceLogSumExp parser ---'
sed -n '660,790p' Deeploy/Targets/Generic/Parsers.py
printf '%s\n' '--- broadcast and shape hook ---'
sed -n '1845,1930p' Deeploy/DeeployTypes.pyRepository: pulp-platform/Deeploy Length of output: 8609 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- broadcast callers ---'
rg -n -C 10 '\.broadcast\(|broadcast\(ctxt' Deeploy
printf '%s\n' '--- parseNodeCtxt callers ---'
rg -n -C 10 'parseNodeCtxt\(' Deeploy/DeeployTypes.py Deeploy | head -220Repository: pulp-platform/Deeploy Length of output: 15891 Compute all reduction axes in
🐛 Suggested fix- axis = operatorRepresentation['axes'][0]
- inputShape = list(copy.deepcopy(inputShapes[0]))
-
- if operatorRepresentation['keepdims']:
- outputShape = inputShape
- outputShape[axis] = 1
- else:
- outputShape = inputShape[:axis] + inputShape[axis + 1:]
+ axes = [int(axis) for axis in operatorRepresentation['axes']]
+ inputShape = list(inputShapes[0])
+
+ if operatorRepresentation['keepdims']:
+ outputShape = list(inputShape)
+ for axis in axes:
+ outputShape[axis] = 1
+ else:
+ outputShape = [dim for idx, dim in enumerate(inputShape) if idx not in axes]
if len(outputShape) == 0:
outputShape = [1]📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ReluLayer(SingleOperationPerElementLayer): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this assert been removed just for a test to pass? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been addressed