You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/design/attribute.md
+21-38Lines changed: 21 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,14 @@
1
-
# Design Doc about operator attribute
1
+
# Design Doc: Operator Attributes
2
2
3
-
## background
3
+
## Background
4
4
5
-
In a neural network, each operator could contain some configurable attributes. For example, a cosine similarity operator may contain an attribute named `scale`. The default cosine similarity returns a value in range [-1.0, 1.0]. But the user can set range scale manually, e.g., user set `scale=5.0`, then that cosine operator will return a value in the range [-5.0, 5.0].
5
+
An operator could have attributes. For example, CosineOp could have a float typed attribute scale, which changes the output range from [-1,1] to [-scale,scale]. The default value of scale is `1.0`.
6
6
7
-
The configurable attributes could be various types. Some operators need `float` value to configure; some need `string`value. We need a data structure to represent different types.
7
+
Attributes is defined by a name and a type. An instance of an attribute has a value of that type.
8
8
9
-
Each operator contains different configurable attributes. The names of attributes are not same. We need an associate map from attribute name to attribute value for `Operator`.
9
+
As part of the network description, attribute need to be serialized. So we need a protobuf message that describes an attribute, say `Attribute`.
10
10
11
-
Also as we want to use `protobuf` to serialize and deserialize our model, we need to implement the attribute value and the associated map from attribute name to attribute value in `protobuf`.
12
-
13
-
In conclusion, there are four things we know as background.
14
-
15
-
1. We need an attribute type for Operator.
16
-
1. That attribute type could represent different types.
17
-
1. That attribute value should be associated with an attribute name, like a map<string, Attribute>.
18
-
1. We need to implement them in `protobuf`.
11
+
An operator could parse the Attribute and save them into its private data member.
PADDLE_ENFORCE(scale_ > 0.0f, "Scale of consine op should be larger than 0.0");
105
92
}
106
93
107
94
private:
108
95
float scale_ {1.0};
109
96
};
110
97
```
111
98
112
-
When `NetworkBase` invokes `CreateOperator(const OperatorDescription& desc)`, it create an operator first. Then `CreateOperator` will invoke `InitializeAttribute` and returns error code. The implementation of `CreateOperator` could be
99
+
When `NetworkBase` invokes `CreateOperator(const OperatorDescription& desc)`, it create an operator first. Then `CreateOperator` will invoke `InitializeAttribute·. The implementation of `CreateOperator` could be
`InitializeAttribute` will validation the user's configuration, and might return an `Error`. It is clearer to invoke the method `InitializeAttribute` and return an `Error` than let each operator's constructor implement this logic because the constructor cannot return a value.
0 commit comments