forked from tracel-ai/burn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a84df25
commit fe5ed0d
Showing
6 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::super::TestBackend; | ||
use burn_tensor::activation; | ||
use burn_tensor::{Data, Tensor}; | ||
|
||
#[test] | ||
fn test_gelu() { | ||
let data = Data::from([[ | ||
0.5447, 0.9809, 0.4114, 0.1398, 0.8045, 0.4103, 0.2388, 0.5262, 0.6677, 0.6737, | ||
]]); | ||
let tensor = Tensor::<TestBackend, 2>::from_data(data); | ||
|
||
let data_actual = activation::gelu(&tensor).to_data(); | ||
|
||
let data_expected = Data::from([[ | ||
0.3851, 0.8207, 0.2714, 0.0777, 0.6351, 0.2704, 0.1419, 0.3687, 0.4993, 0.5051, | ||
]]); | ||
data_expected.assert_approx_eq(&data_actual, 3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod gelu; | ||
mod relu; | ||
mod softmax; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::module::Forward; | ||
use crate::tensor::backend::Backend; | ||
use crate::tensor::Tensor; | ||
|
||
/// Applies the Gaussian Error Linear Units function element-wise. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct GELU {} | ||
|
||
impl GELU { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl<B: Backend, const D: usize> Forward<Tensor<B, D>, Tensor<B, D>> for GELU { | ||
fn forward(&self, input: Tensor<B, D>) -> Tensor<B, D> { | ||
crate::tensor::activation::gelu(&input) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod dropout; | ||
mod gelu; | ||
mod layer_norm; | ||
mod linear; | ||
mod relu; | ||
|
||
pub use dropout::*; | ||
pub use gelu::*; | ||
pub use layer_norm::*; | ||
pub use linear::*; | ||
pub use relu::*; |