Skip to content

Commit 73c0a26

Browse files
author
Brandyn Tucknott
committed
Small activation function bug fixes.
1 parent f025771 commit 73c0a26

3 files changed

Lines changed: 10 additions & 21 deletions

File tree

lib/Layer.chpl

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,6 @@ module Layer {
245245
return new moduleAttributes("Hardswish", moduleName);
246246
}
247247

248-
class Hardsigmoid : Module(?) {
249-
250-
proc init(type eltType = defaultEltType) {
251-
super.init(eltType);
252-
init this;
253-
this.moduleName = "Hardsigmoid";
254-
}
255-
256-
override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do
257-
return input.hardsigmoid();
258-
259-
override proc attributes(): moduleAttributes do
260-
return new moduleAttributes("Hardsigmoid", moduleName);
261-
}
262-
263248
class Hardshrink : Module(?) {
264249
var alpha: eltType;
265250

@@ -271,7 +256,7 @@ module Layer {
271256
}
272257

273258
override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do
274-
return input.hardShrink(beta, threshold);
259+
return input.hardShrink(alpha);
275260

276261
override proc attributes(): moduleAttributes do
277262
return new moduleAttributes(
@@ -290,7 +275,7 @@ module Layer {
290275
this.minVal = minVal;
291276
this.maxVal = maxVal;
292277
init this;
293-
this.moduleName = "Hardtanh";
278+
this.moduleName = "Hardtanh";
294279
}
295280

296281
override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do
@@ -348,16 +333,16 @@ module Layer {
348333
return new moduleAttributes(
349334
"Threshold",
350335
moduleName,
351-
("threshold",lower),
352-
("value",upper)
336+
("threshold",threshold),
337+
("value",value)
353338
);
354339
}
355340

356341
class CELU : Module(?) {
357342
var alpha: eltType;
358343

359344
proc init(type eltType = defaultEltType, alpha: eltType=1.0) {
360-
super.init(eltType)
345+
super.init(eltType);
361346
this.alpha = alpha;
362347
init this;
363348
this.moduleName = "CELU";

lib/NDArray.chpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ inline proc ndarray.leakyrelu(negativeSlope: eltType=0.01) {
12611261
ref rld = rl.data;
12621262
forall i in dom.every() {
12631263
const x = thisData[i];
1264-
rld[i] = Math.max(0, x) + negativeSlope * Math.min(0, x);
1264+
rld[i] = Math.max(0.0, x) + negativeSlope * Math.min(0.0, x);
12651265
}
12661266
return rl;
12671267
}

test/tiny/brandyn_relu.chpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ proc main() {
66
var relu = new shared ReLU();
77
writeln(relu(Tensor.zeros(4) - 1));
88
writeln("Should be: [0, 0, 0, 0]"); // output according to pytorch
9+
10+
relu = new shared ReLU();
11+
writeln(relu(Tensor.zeros(4) + 1.5));
12+
writeln("Should be: [1.5, 1.5, 1.5, 1.5]"); // output according to pytorch
913
}

0 commit comments

Comments
 (0)