From 903f3ebafb48604c050e403975bc916bf6b11f92 Mon Sep 17 00:00:00 2001 From: Brandyn Tucknott Date: Thu, 27 Mar 2025 14:03:51 -0700 Subject: [PATCH 1/6] Fix hardswish and leakyrelu activation functions. --- lib/DynamicTensor.chpl | 2 +- lib/NDArray.chpl | 34 ++++++++++++++++--- lib/StaticTensor.chpl | 2 +- .../activation/leakyrelu/leakyrelu.chpl | 3 ++ .../activation/leakyrelu/leakyrelu.py | 3 ++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/DynamicTensor.chpl b/lib/DynamicTensor.chpl index 0aab02802..0585946fe 100644 --- a/lib/DynamicTensor.chpl +++ b/lib/DynamicTensor.chpl @@ -566,7 +566,7 @@ proc dynamicTensor.celu(alpha: eltType = 1.0): dynamicTensor(eltType) { return new dynamicTensor(eltType); } -proc dynamicTensor.leakyrelu(negativeSlope: eltType = 1.0): dynamicTensor(eltType) { +proc dynamicTensor.leakyrelu(negativeSlope: eltType = 0.01): dynamicTensor(eltType) { for param rank in 1..maxRank { if this.checkRank(rank) then return this.forceRank(rank).leakyrelu(negativeSlope).eraseRank(); diff --git a/lib/NDArray.chpl b/lib/NDArray.chpl index 265e87998..1e2883ef3 100644 --- a/lib/NDArray.chpl +++ b/lib/NDArray.chpl @@ -1057,13 +1057,39 @@ inline proc ndarray.hardswish() { const dom = this.domain; var rl = new ndarray(dom, eltType); ref rld = rl.data; + forall i in dom.every() { const x = thisData[i]; const floatMax: eltType = Types.max(eltType); - const xgeq3: eltType = Math.ceil(1.0 / floatMax); // x >= 3: 1 if true, 0 otherwise - const xleqn3: eltType = Math.ceil(1.0 / floatMax); // x <= -3: 1 if true, 0 otherwise - rld[i] = x * xgeq3 + x * (x + 3) / 6.0 * (1 - xgeq3) * xleqn3; + const xgeq3: eltType = Math.ceil((x - 3.0) / floatMax); // x >= 3: 1 if true, 0 otherwise + const xleqn3: eltType = Math.ceil((-x - 3.0) / floatMax); // x <= -3: 1 if true, 0 otherwise + rld[i] = x * xgeq3 + x * (x + 3) / 6.0 * (1 - xgeq3) * (1 - xleqn3); } + + // use CTypes only c_sizeof, c_ptrTo; + // use OS.POSIX only memcpy; + + // type intType = int(numBits(eltType)); // integer w/ same #ofbits as real + // forall i in dom.every() { + // const x = thisData[i]; // negative x + // const threshold: eltType = 20.0; + + // var func: eltType = ; // result after applying hardswish(x) activation function + // var lin: eltType = x; + + // var func_bits: intType; + // var lin_bits: intType; + // memcpy(c_ptrTo(func_bits), c_ptrTo(func), c_sizeof(eltType)); + // memcpy(c_ptrTo(lin_bits), c_ptrTo(lin), c_sizeof(eltType)); + + // const condition: intType = (-x > threshold); + // const mask: intType = 0 - condition; + + // var result_bits: intType = (mask & lin_bits) | (~mask & func_bits); + + // // rld[i] = output; + // memcpy(c_ptrTo(rld[i]), c_ptrTo(result_bits), c_sizeof(eltType)); + // } return rl; } @@ -1205,7 +1231,7 @@ inline proc ndarray.celu(alpha: eltType=1.0) { return rl; } -inline proc ndarray.leakyrelu(negativeSlope: eltType=Math.exp(-2)) { +inline proc ndarray.leakyrelu(negativeSlope: eltType=0.01) { const ref thisData = data; const dom = this.domain; var rl = new ndarray(dom, eltType); diff --git a/lib/StaticTensor.chpl b/lib/StaticTensor.chpl index d8531408b..cd2c52593 100644 --- a/lib/StaticTensor.chpl +++ b/lib/StaticTensor.chpl @@ -318,7 +318,7 @@ proc staticTensor.celu(alpha: eltType = 1.0) { return tensorFromCtx(rank, eltType, ctx); } -proc staticTensor.leakyrelu(negativeSlope: eltType = exp(-2.0)) { +proc staticTensor.leakyrelu(negativeSlope: eltType = 0.01) { var ctx = new leakyreluOp(meta, negativeSlope); return tensorFromCtx(rank, eltType, ctx); } diff --git a/test/correspondence/activation/leakyrelu/leakyrelu.chpl b/test/correspondence/activation/leakyrelu/leakyrelu.chpl index 4a42b330b..0baa510f5 100644 --- a/test/correspondence/activation/leakyrelu/leakyrelu.chpl +++ b/test/correspondence/activation/leakyrelu/leakyrelu.chpl @@ -6,6 +6,9 @@ Testing.numericPrint(a); var b = (Tensor.zeros(2,3,4) - 60.0).leakyrelu(); Testing.numericPrint(b); +b = (Tensor.zeros(2,3,4) - 1.0).leakyrelu(); +Testing.numericPrint(b); + var c = (Tensor.zeros(10) + 40.0).leakyrelu(); Testing.numericPrint(c); diff --git a/test/correspondence/activation/leakyrelu/leakyrelu.py b/test/correspondence/activation/leakyrelu/leakyrelu.py index ee9b37ff8..4f11243ce 100644 --- a/test/correspondence/activation/leakyrelu/leakyrelu.py +++ b/test/correspondence/activation/leakyrelu/leakyrelu.py @@ -8,6 +8,9 @@ def test(imports): b = torch.nn.LeakyReLU()(torch.zeros(2,3,4) - 60.0) print(b) + + b = torch.nn.LeakyReLU()(torch.zeros(2,3,4) - 1.0) + print(b) c = torch.nn.LeakyReLU()(torch.zeros(10) + 40.0) print(c) From 2b86f4d31228f18fa2b1c35676a5448cc6204233 Mon Sep 17 00:00:00 2001 From: Brandyn Tucknott Date: Sat, 24 May 2025 17:37:48 -0700 Subject: [PATCH 2/6] Add activation functions to Layer.chpl. --- lib/Layer.chpl | 340 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 340 insertions(+) diff --git a/lib/Layer.chpl b/lib/Layer.chpl index db5639acf..5ca7cf6e1 100644 --- a/lib/Layer.chpl +++ b/lib/Layer.chpl @@ -80,6 +80,346 @@ module Layer { ); } + class SiLU : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "SiLU"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.silu(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("SiLU", moduleName); + } + + class Mish : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Mish"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.mish(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Mish", moduleName); + } + + class Sigmoid : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Sigmoid"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.sigmoid(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Sigmoid", moduleName); + } + + class Tanh : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Tanh"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.tanh(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Tanh", moduleName); + } + + class ReLU6 : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "ReLU6"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.relu6(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("ReLU6", moduleName); + } + + class SELU : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "SELU"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.selu(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("SELU", moduleName); + } + + class Hardsigmoid : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Hardsigmoid"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.hardsigmoid(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Hardsigmoid", moduleName); + } + + class LogSigmoid : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "LogSigmoid"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.logsigmoid(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("LogSigmoid", moduleName); + } + + class Tanhshrink : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Tanhshrink"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.tanhshrink(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Tanhshrink", moduleName); + } + + class SoftSign : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "SoftSign"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.softsign(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("SoftSign", moduleName); + } + + class Hardswish : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Hardswish"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.hardswish(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Hardswish", moduleName); + } + + class Hardsigmoid : Module(?) { + + proc init(type eltType = defaultEltType) { + super.init(eltType); + init this; + this.moduleName = "Hardsigmoid"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.hardsigmoid(); + + override proc attributes(): moduleAttributes do + return new moduleAttributes("Hardsigmoid", moduleName); + } + + class Hardshrink : Module(?) { + var alpha: eltType; + + proc init(type eltType = defaultEltType, alpha: eltType = 0.5) { + super.init(eltType); + this.alpha = alpha; + init this; + this.moduleName = "Hardshrink"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.hardShrink(beta, threshold); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "Hardshrink", + moduleName, + ("alpha", alpha) + ); + } + + class Hardtanh : Module(?) { + var minVal: eltType; + var maxVal: eltType; + + proc init(type eltType = defaultEltType, minVal: eltType = -1.0, maxVal: eltType = 1.0) { + super.init(eltType); + this.minVal = minVal; + this.maxVal = maxVal; + init this; + this.moduleName = "Hardtanh"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.hardtanh(minVal, maxVal); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "Hardtanh", + moduleName, + ("minVal", minVal), + ("maxVal", maxVal) + ); + } + + class Softplus : Module(?) { + var beta: eltType; + var threshold: eltType; + + proc init(type eltType = defaultEltType, beta: eltType = 1.0, threshold: eltType = 20.0) { + super.init(eltType); + this.beta = beta; + this.threshold = threshold; + init this; + this.moduleName = "Softplus"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.softplus(beta, threshold); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "Softplus", + moduleName, + ("beta", beta), + ("threshold", threshold) + ); + } + + class Threshold : Module(?) { + var threshold: eltType; + var value: eltType; + + proc init(type eltType = defaultEltType, threshold: eltType, value: eltType) { + super.init(eltType); + this.threshold = threshold; + this.value = value; + init this; + this.moduleName = "Threshold"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.threshold(threshold, value); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "Threshold", + moduleName, + ("threshold",lower), + ("value",upper) + ); + } + + class CELU : Module(?) { + var alpha: eltType; + + proc init(type eltType = defaultEltType, alpha: eltType=1.0) { + super.init(eltType) + this.alpha = alpha; + init this; + this.moduleName = "CELU"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.celu(alpha); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "CELU", + moduleName, + ("alpha", alpha) + ); + } + + class LeakyReLU : Module(?) { + var negativeSlope: eltType; + + proc init(type eltType = defaultEltType, negativeSlope: eltType=0.01) { + super.init(eltType); + this.negativeSlope = negativeSlope; + init this; + this.moduleName = "LeakyReLU"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.leakyrelu(negativeSlope); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "LeakyReLU", + moduleName, + ("negativeSlope", negativeSlope) + ); + } + + class Softshrink : Module(?) { + var alpha: eltType; + + proc init(type eltType = defaultEltType, alpha: eltType=0.5) { + super.init(eltType); + this.alpha = alpha; + init this; + this.moduleName = "Softshrink"; + } + + override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do + return input.softshrink(alpha); + + override proc attributes(): moduleAttributes do + return new moduleAttributes( + "Softshrink", + moduleName, + ("alpha", alpha) + ); + } + + + + + class Flatten : Module(?) { proc init(type eltType = defaultEltType) { super.init(eltType); From f025771d3d4ffbaf2f1048bcf694fcd7d9a7998e Mon Sep 17 00:00:00 2001 From: Brandyn Tucknott Date: Sun, 25 May 2025 00:11:13 -0700 Subject: [PATCH 3/6] Add sanity check cases for activation functions (for lib/Layer.chpl). --- test/tiny/CMakeLists.txt | 389 +++++++++++++++++++++++++++++ test/tiny/brandyn_celu.chpl | 14 ++ test/tiny/brandyn_elu.chpl | 13 + test/tiny/brandyn_gelu.chpl | 9 + test/tiny/brandyn_hardshrink.chpl | 13 + test/tiny/brandyn_hardsigmoid.chpl | 9 + test/tiny/brandyn_hardswish.chpl | 9 + test/tiny/brandyn_hardtanh.chpl | 17 ++ test/tiny/brandyn_leakyrelu.chpl | 18 ++ test/tiny/brandyn_logsigmoid.chpl | 9 + test/tiny/brandyn_mish.chpl | 9 + test/tiny/brandyn_relu.chpl | 9 + test/tiny/brandyn_relu6.chpl | 9 + test/tiny/brandyn_rrelu.chpl | 20 ++ test/tiny/brandyn_selu.chpl | 9 + test/tiny/brandyn_sigmoid.chpl | 9 + test/tiny/brandyn_silu.chpl | 9 + test/tiny/brandyn_softplus.chpl | 17 ++ test/tiny/brandyn_softshrink.chpl | 12 + test/tiny/brandyn_softsign.chpl | 9 + test/tiny/brandyn_tanh.chpl | 9 + test/tiny/brandyn_tanhshrink.chpl | 9 + test/tiny/brandyn_threshold.chpl | 14 ++ 23 files changed, 644 insertions(+) create mode 100644 test/tiny/brandyn_celu.chpl create mode 100644 test/tiny/brandyn_elu.chpl create mode 100644 test/tiny/brandyn_gelu.chpl create mode 100644 test/tiny/brandyn_hardshrink.chpl create mode 100644 test/tiny/brandyn_hardsigmoid.chpl create mode 100644 test/tiny/brandyn_hardswish.chpl create mode 100644 test/tiny/brandyn_hardtanh.chpl create mode 100644 test/tiny/brandyn_leakyrelu.chpl create mode 100644 test/tiny/brandyn_logsigmoid.chpl create mode 100644 test/tiny/brandyn_mish.chpl create mode 100644 test/tiny/brandyn_relu.chpl create mode 100644 test/tiny/brandyn_relu6.chpl create mode 100644 test/tiny/brandyn_rrelu.chpl create mode 100644 test/tiny/brandyn_selu.chpl create mode 100644 test/tiny/brandyn_sigmoid.chpl create mode 100644 test/tiny/brandyn_silu.chpl create mode 100644 test/tiny/brandyn_softplus.chpl create mode 100644 test/tiny/brandyn_softshrink.chpl create mode 100644 test/tiny/brandyn_softsign.chpl create mode 100644 test/tiny/brandyn_tanh.chpl create mode 100644 test/tiny/brandyn_tanhshrink.chpl create mode 100644 test/tiny/brandyn_threshold.chpl diff --git a/test/tiny/CMakeLists.txt b/test/tiny/CMakeLists.txt index b28b04f64..cee105f4a 100644 --- a/test/tiny/CMakeLists.txt +++ b/test/tiny/CMakeLists.txt @@ -1,3 +1,392 @@ +add_executable(BrandynReLU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_relu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynReLU bridge) +add_dependencies(BrandynReLU ChAI) +target_link_options(BrandynReLU + PRIVATE + ${CHAI_LINKER_ARGS} +) +set_target_properties(BrandynReLU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + +add_executable(BrandynGELU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_gelu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynGELU bridge) +add_dependencies(BrandynGELU ChAI) +target_link_options(BrandynGELU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynGELU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynELU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_elu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynELU bridge) +add_dependencies(BrandynELU ChAI) +target_link_options(BrandynELU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynELU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynRReLU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_rrelu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynRReLU bridge) +add_dependencies(BrandynRReLU ChAI) +target_link_options(BrandynRReLU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynRReLU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynSiLU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_silu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynSiLU bridge) +add_dependencies(BrandynSiLU ChAI) +target_link_options(BrandynSiLU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynSiLU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynMish + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_mish.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynMish bridge) +add_dependencies(BrandynMish ChAI) +target_link_options(BrandynMish + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynMish PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynSigmoid + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_sigmoid.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynSigmoid bridge) +add_dependencies(BrandynSigmoid ChAI) +target_link_options(BrandynSigmoid + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynSigmoid PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynTanh + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_tanh.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynTanh bridge) +add_dependencies(BrandynTanh ChAI) +target_link_options(BrandynTanh + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynTanh PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynReLU6 + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_relu6.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynReLU6 bridge) +add_dependencies(BrandynReLU6 ChAI) +target_link_options(BrandynReLU6 + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynReLU6 PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynSELU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_selu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynSELU bridge) +add_dependencies(BrandynSELU ChAI) +target_link_options(BrandynSELU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynSELU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynHardsigmoid + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_hardsigmoid.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynHardsigmoid bridge) +add_dependencies(BrandynHardsigmoid ChAI) +target_link_options(BrandynHardsigmoid + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynHardsigmoid PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynLogSigmoid + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_logsigmoid.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynLogSigmoid bridge) +add_dependencies(BrandynLogSigmoid ChAI) +target_link_options(BrandynLogSigmoid + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynLogSigmoid PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynTanhshrink + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_tanhshrink.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynTanhshrink bridge) +add_dependencies(BrandynTanhshrink ChAI) +target_link_options(BrandynTanhshrink + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynTanhshrink PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynSoftsign + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_softsign.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynSoftsign bridge) +add_dependencies(BrandynSoftsign ChAI) +target_link_options(BrandynSoftsign + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynSoftsign PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynHardswish + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_hardswish.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynHardswish bridge) +add_dependencies(BrandynHardswish ChAI) +target_link_options(BrandynHardswish + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynHardswish PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynHardshrink + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_hardshrink.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynHardshrink bridge) +add_dependencies(BrandynHardshrink ChAI) +target_link_options(BrandynHardshrink + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynHardshrink PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynHardtanh + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_hardtanh.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynHardtanh bridge) +add_dependencies(BrandynHardtanh ChAI) +target_link_options(BrandynHardtanh + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynHardtanh PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynSoftplus + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_softplus.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynSoftplus bridge) +add_dependencies(BrandynSoftplus ChAI) +target_link_options(BrandynSoftplus + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynSoftplus PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynThreshold + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_threshold.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynThreshold bridge) +add_dependencies(BrandynThreshold ChAI) +target_link_options(BrandynThreshold + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynThreshold PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynCELU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_celu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynCELU bridge) +add_dependencies(BrandynCELU ChAI) +target_link_options(BrandynCELU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynCELU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynLeakyReLU + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_leakyrelu.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynLeakyReLU bridge) +add_dependencies(BrandynLeakyReLU ChAI) +target_link_options(BrandynLeakyReLU + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynLeakyReLU PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) + + + + +add_executable(BrandynSoftshrink + ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_softshrink.chpl + ${CHAI_LIB_FILES} +) +add_dependencies(BrandynSoftshrink bridge) +add_dependencies(BrandynSoftshrink ChAI) +target_link_options(BrandynSoftshrink + PRIVATE + ${CHAI_LINKER_ARGS} +) + +set_target_properties(BrandynSoftshrink PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} +) \ No newline at end of file diff --git a/test/tiny/brandyn_celu.chpl b/test/tiny/brandyn_celu.chpl new file mode 100644 index 000000000..d249319a2 --- /dev/null +++ b/test/tiny/brandyn_celu.chpl @@ -0,0 +1,14 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small CELU test. "); + + var celu = new shared CELU(); + writeln(celu(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.6321, -0.6321, -0.6321, -0.6321]"); // output according to pytorch + + celu = new shared CELU(alpha=0.5); + writeln(celu(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.4323, -0.4323, -0.4323, -0.4323]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_elu.chpl b/test/tiny/brandyn_elu.chpl new file mode 100644 index 000000000..9cc7a7284 --- /dev/null +++ b/test/tiny/brandyn_elu.chpl @@ -0,0 +1,13 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small ELU test. "); + var elu = new shared ELU(); + writeln(elu(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.6321, -0.6321, -0.6321, -0.6321]"); // output according to pytorch + + elu = new shared ELU(alpha=0.1); + writeln(elu(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.0632, -0.0632, -0.0632, -0.0632]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_gelu.chpl b/test/tiny/brandyn_gelu.chpl new file mode 100644 index 000000000..ff559d44a --- /dev/null +++ b/test/tiny/brandyn_gelu.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small GELU test. "); + var gelu = new shared GELU(); + writeln(gelu(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.1587, -0.1587, -0.1587, -0.1587]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_hardshrink.chpl b/test/tiny/brandyn_hardshrink.chpl new file mode 100644 index 000000000..c26343040 --- /dev/null +++ b/test/tiny/brandyn_hardshrink.chpl @@ -0,0 +1,13 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Hardshrink test. "); + var hardshrink = new shared Hardshrink(); + writeln(hardshrink(Tensor.zeros(4) - 1)); + writeln("Should be: [-1, -1, -1, -1]"); // output according to pytorch + + hardshrink = new shared Hardshrink(alpha=1.0); + writeln(hardshrink(Tensor.zeros(4) - 1)); + writeln("Should be: [0, 0, 0, 0]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_hardsigmoid.chpl b/test/tiny/brandyn_hardsigmoid.chpl new file mode 100644 index 000000000..6114ba168 --- /dev/null +++ b/test/tiny/brandyn_hardsigmoid.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Hardsigmoid test. "); + var hardsigmoid = new shared Hardsigmoid(); + writeln(hardsigmoid(Tensor.zeros(4) - 1)); + writeln("Should be: [0.3333, 0.3333, 0.3333, 0.3333]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_hardswish.chpl b/test/tiny/brandyn_hardswish.chpl new file mode 100644 index 000000000..20817bb3e --- /dev/null +++ b/test/tiny/brandyn_hardswish.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Hardswish test. "); + var hardswish = new shared Hardswish(); + writeln(hardswish(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.3333, -0.3333, -0.3333, -0.3333]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_hardtanh.chpl b/test/tiny/brandyn_hardtanh.chpl new file mode 100644 index 000000000..26f5c63fc --- /dev/null +++ b/test/tiny/brandyn_hardtanh.chpl @@ -0,0 +1,17 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Hardtanh test. "); + var hardtanh = new shared Hardtanh(); + writeln(hardtanh(Tensor.zeros(4) - 1)); + writeln("Should be: [-1, -1, -1, -1]"); // output according to pytorch + + hardtanh = new shared Hardtanh(minVal=0); + writeln(hardtanh(Tensor.zeros(4) - 1)); + writeln("Should be: [0, 0, 0, 0]"); // output according to pytorch + + hardtanh = new shared Hardtanh(minVal=0, maxVal=0.1); + writeln(hardtanh(Tensor.zeros(4) + 1)); + writeln("Should be: [0.1, 0.1, 0.1, 0.1]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_leakyrelu.chpl b/test/tiny/brandyn_leakyrelu.chpl new file mode 100644 index 000000000..149adaab1 --- /dev/null +++ b/test/tiny/brandyn_leakyrelu.chpl @@ -0,0 +1,18 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small LeakyReLU test. "); + + var leakyrelu = new shared LeakyReLU(); + writeln(leakyrelu(Tensor.zeros(4) - 100)); + writeln("Should be: [-1, -1, -1, -1]"); // output according to pytorch + + leakyrelu = new shared LeakyReLU(negativeSlope=1.5); + writeln(leakyrelu(Tensor.zeros(4) - 1)); + writeln("Should be: [-1.5, -1.5, -1.5, -1.5]"); // output according to pytorch + + leakyrelu = new shared LeakyReLU(negativeSlope=0.5); + writeln(leakyrelu(Tensor.zeros(4) + 0.5)); + writeln("Should be: [0.5, 0.5, 0.5, 0.5]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_logsigmoid.chpl b/test/tiny/brandyn_logsigmoid.chpl new file mode 100644 index 000000000..fac8b33dc --- /dev/null +++ b/test/tiny/brandyn_logsigmoid.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small LogSigmoid test. "); + var logsigmoid = new shared LogSigmoid(); + writeln(logsigmoid(Tensor.zeros(4) - 1)); + writeln("Should be: [-1.3133, -1.3133, -1.3133, -1.3133]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_mish.chpl b/test/tiny/brandyn_mish.chpl new file mode 100644 index 000000000..1bbf5c046 --- /dev/null +++ b/test/tiny/brandyn_mish.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Mish test. "); + var mish = new shared Mish(); + writeln(mish(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.3034, -0.3034, -0.3034, -0.3034]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_relu.chpl b/test/tiny/brandyn_relu.chpl new file mode 100644 index 000000000..341d723de --- /dev/null +++ b/test/tiny/brandyn_relu.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small ReLU test. "); + var relu = new shared ReLU(); + writeln(relu(Tensor.zeros(4) - 1)); + writeln("Should be: [0, 0, 0, 0]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_relu6.chpl b/test/tiny/brandyn_relu6.chpl new file mode 100644 index 000000000..dd3ccd7f1 --- /dev/null +++ b/test/tiny/brandyn_relu6.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small ReLU6 test. "); + var relu6 = new shared ReLU6(); + writeln(relu6(Tensor.zeros(4) - 1)); + writeln("Should be: [0, 0, 0, 0]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_rrelu.chpl b/test/tiny/brandyn_rrelu.chpl new file mode 100644 index 000000000..4d1d93d47 --- /dev/null +++ b/test/tiny/brandyn_rrelu.chpl @@ -0,0 +1,20 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small RReLU test. "); + var rrelu = new shared RReLU(); + writeln(rrelu(Tensor.zeros(4) - 1)); + + rrelu = new shared RReLU(lower=0.1); + writeln(rrelu(Tensor.zeros(4) - 1)); + + rrelu = new shared RReLU(upper=1.0); + writeln(rrelu(Tensor.zeros(4) - 1)); + + rrelu = new shared RReLU(lower=0.6, upper=0.8); + writeln(rrelu(Tensor.zeros(4) + 1)); + + + writeln("RReLU has no pytorch comparison b/c there is randomness involved. "); +} \ No newline at end of file diff --git a/test/tiny/brandyn_selu.chpl b/test/tiny/brandyn_selu.chpl new file mode 100644 index 000000000..8a2aa9a77 --- /dev/null +++ b/test/tiny/brandyn_selu.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small SELU test. "); + var selu = new shared selu(); + writeln(selu(Tensor.zeros(4) - 1)); + writeln("Should be: [-1.1113, -1.1113, -1.1113, -1.1113]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_sigmoid.chpl b/test/tiny/brandyn_sigmoid.chpl new file mode 100644 index 000000000..895459226 --- /dev/null +++ b/test/tiny/brandyn_sigmoid.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Sigmoid test. "); + var sigmoid = new shared Sigmoid(); + writeln(sigmoid(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.2689, -0.2689, -0.2689, -0.2689]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_silu.chpl b/test/tiny/brandyn_silu.chpl new file mode 100644 index 000000000..5884c4b69 --- /dev/null +++ b/test/tiny/brandyn_silu.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small SiLU test. "); + var silu = new shared SiLU(); + writeln(silu(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.2689, -0.2689, -0.2689, -0.2689]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_softplus.chpl b/test/tiny/brandyn_softplus.chpl new file mode 100644 index 000000000..ac5a56a1c --- /dev/null +++ b/test/tiny/brandyn_softplus.chpl @@ -0,0 +1,17 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Softplus test. "); + var softplus = new shared Softplus(); + writeln(softplus(Tensor.zeros(4) - 1)); + writeln("Should be: [0.3133, 0.3133, 0.3133, 0.3133]"); // output according to pytorch + + softplus = new shared Softplus(beta=0.2); + writeln(softplus(Tensor.zeros(4) - 1)); + writeln("Should be: [2.9907, 2.9907, 2.9907, 2.9907]"); // output according to pytorch + + softplus = new shared Softplus(beta=0.3, threshold=1.5); + writeln(softplus(Tensor.zeros(4) - 1)); + writeln("Should be: [1.8479, 1.8479, 1.8479, 1.8479]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_softshrink.chpl b/test/tiny/brandyn_softshrink.chpl new file mode 100644 index 000000000..48975465b --- /dev/null +++ b/test/tiny/brandyn_softshrink.chpl @@ -0,0 +1,12 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Softshrink test. "); + var softshrink = new shared Softshrink(); + writeln(softshrink(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.5, -0.5, -0.5, -0.5]"); // output according to pytorch + softshrink = new shared Softshrink(alpha=0.1); + writeln(softshrink(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.9, -0.9, -0.9, -0.9]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_softsign.chpl b/test/tiny/brandyn_softsign.chpl new file mode 100644 index 000000000..79fde010c --- /dev/null +++ b/test/tiny/brandyn_softsign.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Softsign test. "); + var softsign = new shared Softsign(); + writeln(softsign(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.5, -0.5, -0.5, -0.5]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_tanh.chpl b/test/tiny/brandyn_tanh.chpl new file mode 100644 index 000000000..65a1887f2 --- /dev/null +++ b/test/tiny/brandyn_tanh.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Tanh test. "); + var tanh = new shared Tanh(); + writeln(tanh(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.7616, -0.7616, -0.7616, -0.7616]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_tanhshrink.chpl b/test/tiny/brandyn_tanhshrink.chpl new file mode 100644 index 000000000..bfc117651 --- /dev/null +++ b/test/tiny/brandyn_tanhshrink.chpl @@ -0,0 +1,9 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Tanhshrink test. "); + var tanhshrink = new shared Tanhshrink(); + writeln(tanhshrink(Tensor.zeros(4) - 1)); + writeln("Should be: [-0.2384, -0.2384, -0.2384, -0.2384]"); // output according to pytorch +} \ No newline at end of file diff --git a/test/tiny/brandyn_threshold.chpl b/test/tiny/brandyn_threshold.chpl new file mode 100644 index 000000000..02f1a6abf --- /dev/null +++ b/test/tiny/brandyn_threshold.chpl @@ -0,0 +1,14 @@ +use Tensor; +use Layer; + +proc main() { + writeln("Small Threshold test. "); + + var threshold = new shared Threshold(value=0.1, threshold=1.0); + writeln(threshold(Tensor.zeros(4) - 1)); + writeln("Should be: [0.1, 0.1, 0.1, 0.1]"); // output according to pytorch + + threshold = new shared Threshold(value=0.5, threshold=2.0); + writeln(threshold(Tensor.zeros(4) + 1)); + writeln("Should be: [0.5, 0.5, 0.5, 0.5]"); // output according to pytorch +} \ No newline at end of file From 73c0a26a9abecbc362ab08c471bfbac8e35c6b0c Mon Sep 17 00:00:00 2001 From: Brandyn Tucknott Date: Sun, 25 May 2025 00:18:51 -0700 Subject: [PATCH 4/6] Small activation function bug fixes. --- lib/Layer.chpl | 25 +++++-------------------- lib/NDArray.chpl | 2 +- test/tiny/brandyn_relu.chpl | 4 ++++ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/Layer.chpl b/lib/Layer.chpl index 5ca7cf6e1..f87e88d1c 100644 --- a/lib/Layer.chpl +++ b/lib/Layer.chpl @@ -245,21 +245,6 @@ module Layer { return new moduleAttributes("Hardswish", moduleName); } - class Hardsigmoid : Module(?) { - - proc init(type eltType = defaultEltType) { - super.init(eltType); - init this; - this.moduleName = "Hardsigmoid"; - } - - override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do - return input.hardsigmoid(); - - override proc attributes(): moduleAttributes do - return new moduleAttributes("Hardsigmoid", moduleName); - } - class Hardshrink : Module(?) { var alpha: eltType; @@ -271,7 +256,7 @@ module Layer { } override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do - return input.hardShrink(beta, threshold); + return input.hardShrink(alpha); override proc attributes(): moduleAttributes do return new moduleAttributes( @@ -290,7 +275,7 @@ module Layer { this.minVal = minVal; this.maxVal = maxVal; init this; - this.moduleName = "Hardtanh"; + this.moduleName = "Hardtanh"; } override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do @@ -348,8 +333,8 @@ module Layer { return new moduleAttributes( "Threshold", moduleName, - ("threshold",lower), - ("value",upper) + ("threshold",threshold), + ("value",value) ); } @@ -357,7 +342,7 @@ module Layer { var alpha: eltType; proc init(type eltType = defaultEltType, alpha: eltType=1.0) { - super.init(eltType) + super.init(eltType); this.alpha = alpha; init this; this.moduleName = "CELU"; diff --git a/lib/NDArray.chpl b/lib/NDArray.chpl index a21fb2e26..a7c5ac3b3 100644 --- a/lib/NDArray.chpl +++ b/lib/NDArray.chpl @@ -1261,7 +1261,7 @@ inline proc ndarray.leakyrelu(negativeSlope: eltType=0.01) { ref rld = rl.data; forall i in dom.every() { const x = thisData[i]; - rld[i] = Math.max(0, x) + negativeSlope * Math.min(0, x); + rld[i] = Math.max(0.0, x) + negativeSlope * Math.min(0.0, x); } return rl; } diff --git a/test/tiny/brandyn_relu.chpl b/test/tiny/brandyn_relu.chpl index 341d723de..c6a1333d7 100644 --- a/test/tiny/brandyn_relu.chpl +++ b/test/tiny/brandyn_relu.chpl @@ -6,4 +6,8 @@ proc main() { var relu = new shared ReLU(); writeln(relu(Tensor.zeros(4) - 1)); writeln("Should be: [0, 0, 0, 0]"); // output according to pytorch + + relu = new shared ReLU(); + writeln(relu(Tensor.zeros(4) + 1.5)); + writeln("Should be: [1.5, 1.5, 1.5, 1.5]"); // output according to pytorch } \ No newline at end of file From ae6c7f319284c79f0be9784a8eeaf8c89031d53f Mon Sep 17 00:00:00 2001 From: Brandyn Tucknott Date: Sun, 25 May 2025 00:20:07 -0700 Subject: [PATCH 5/6] Iain's changes made on my computer. --- CMakeLists.txt | 4 ++-- lib/Bridge.chpl | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4a2d1d4b..09e8c5e87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -280,9 +280,9 @@ add_custom_command( # add_subdirectory(bridge) -add_subdirectory(examples) +# add_subdirectory(examples) add_subdirectory("test") -add_subdirectory(demos) +# add_subdirectory(demos) diff --git a/lib/Bridge.chpl b/lib/Bridge.chpl index fd1e6c208..72b4d74cf 100644 --- a/lib/Bridge.chpl +++ b/lib/Bridge.chpl @@ -111,11 +111,6 @@ module Bridge { in a: bridge_tensor_t, in b: bridge_tensor_t): bridge_tensor_t; - extern "split_loop" proc splitLoop(idx: int(64), n: int(64)): void; - - extern "split_loop_filler" proc splitLoopFiller(n: int(64),ret: c_ptr(int(64))): void; - - extern "show_webcam" proc showWebcam(): void; // extern "capture_webcam_bridge" proc captureWebcam( // in cam_index: int(32)): bridge_tensor_t; From 6bdda378ed8016972e31243e2e1b449b58bbdcce Mon Sep 17 00:00:00 2001 From: Brandyn Tucknott Date: Sun, 25 May 2025 02:15:26 -0700 Subject: [PATCH 6/6] Fix spelling errors. --- lib/Layer.chpl | 2 +- test/tiny/CMakeLists.txt | 10 +++++----- test/tiny/brandyn_elu.chpl | 4 ++-- test/tiny/brandyn_relu.chpl | 4 ++++ test/tiny/brandyn_selu.chpl | 2 +- test/tiny/brandyn_softsign.chpl | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Layer.chpl b/lib/Layer.chpl index f87e88d1c..1cedb8275 100644 --- a/lib/Layer.chpl +++ b/lib/Layer.chpl @@ -279,7 +279,7 @@ module Layer { } override proc forward(input: dynamicTensor(eltType)): dynamicTensor(eltType) do - return input.hardtanh(minVal, maxVal); + return input.hardTanh(minVal, maxVal); override proc attributes(): moduleAttributes do return new moduleAttributes( diff --git a/test/tiny/CMakeLists.txt b/test/tiny/CMakeLists.txt index cee105f4a..cc0f8990a 100644 --- a/test/tiny/CMakeLists.txt +++ b/test/tiny/CMakeLists.txt @@ -232,18 +232,18 @@ set_target_properties(BrandynTanhshrink PROPERTIES -add_executable(BrandynSoftsign +add_executable(BrandynSoftSign ${CMAKE_CURRENT_SOURCE_DIR}/brandyn_softsign.chpl ${CHAI_LIB_FILES} ) -add_dependencies(BrandynSoftsign bridge) -add_dependencies(BrandynSoftsign ChAI) -target_link_options(BrandynSoftsign +add_dependencies(BrandynSoftSign bridge) +add_dependencies(BrandynSoftSign ChAI) +target_link_options(BrandynSoftSign PRIVATE ${CHAI_LINKER_ARGS} ) -set_target_properties(BrandynSoftsign PROPERTIES +set_target_properties(BrandynSoftSign PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) diff --git a/test/tiny/brandyn_elu.chpl b/test/tiny/brandyn_elu.chpl index 9cc7a7284..dbf4ab462 100644 --- a/test/tiny/brandyn_elu.chpl +++ b/test/tiny/brandyn_elu.chpl @@ -4,10 +4,10 @@ use Layer; proc main() { writeln("Small ELU test. "); var elu = new shared ELU(); - writeln(elu(Tensor.zeros(4) - 1)); + writeln(elu(Tensor.zeros(4) - 1).toNDArray(1)); writeln("Should be: [-0.6321, -0.6321, -0.6321, -0.6321]"); // output according to pytorch elu = new shared ELU(alpha=0.1); - writeln(elu(Tensor.zeros(4) - 1)); + writeln(elu(Tensor.zeros(4) - 1).toNDArray(1)); writeln("Should be: [-0.0632, -0.0632, -0.0632, -0.0632]"); // output according to pytorch } \ No newline at end of file diff --git a/test/tiny/brandyn_relu.chpl b/test/tiny/brandyn_relu.chpl index c6a1333d7..6a734cd50 100644 --- a/test/tiny/brandyn_relu.chpl +++ b/test/tiny/brandyn_relu.chpl @@ -10,4 +10,8 @@ proc main() { relu = new shared ReLU(); writeln(relu(Tensor.zeros(4) + 1.5)); writeln("Should be: [1.5, 1.5, 1.5, 1.5]"); // output according to pytorch + + relu = new shared ReLU(); + writeln(relu(Tensor.zeros(4) + 2.4903)); + writeln("Should be: [2.4903, 2.4903, 2.4903, 2.4903]"); // output according to pytorch } \ No newline at end of file diff --git a/test/tiny/brandyn_selu.chpl b/test/tiny/brandyn_selu.chpl index 8a2aa9a77..c76ae7d4f 100644 --- a/test/tiny/brandyn_selu.chpl +++ b/test/tiny/brandyn_selu.chpl @@ -3,7 +3,7 @@ use Layer; proc main() { writeln("Small SELU test. "); - var selu = new shared selu(); + var selu = new shared SELU(); writeln(selu(Tensor.zeros(4) - 1)); writeln("Should be: [-1.1113, -1.1113, -1.1113, -1.1113]"); // output according to pytorch } \ No newline at end of file diff --git a/test/tiny/brandyn_softsign.chpl b/test/tiny/brandyn_softsign.chpl index 79fde010c..11e5bbd85 100644 --- a/test/tiny/brandyn_softsign.chpl +++ b/test/tiny/brandyn_softsign.chpl @@ -2,8 +2,8 @@ use Tensor; use Layer; proc main() { - writeln("Small Softsign test. "); - var softsign = new shared Softsign(); + writeln("Small SoftSign test. "); + var softsign = new shared SoftSign(); writeln(softsign(Tensor.zeros(4) - 1)); writeln("Should be: [-0.5, -0.5, -0.5, -0.5]"); // output according to pytorch } \ No newline at end of file