use burn::prelude::*;
use burn::nn::{Linear, LinearConfig};
use burn::tensor::activation::gelu;
use crate::model::norm::LunaLayerNorm;
#[derive(Module, Debug)]
pub struct FeedForward<B: Backend> {
pub fc1: Linear<B>,
pub fc2: Linear<B>,
pub norm: LunaLayerNorm<B>,
}
impl<B: Backend> FeedForward<B> {
pub fn new(dim: usize, hidden_dim: usize, norm_eps: f64, device: &B::Device) -> Self {
Self {
fc1: LinearConfig::new(dim, hidden_dim).with_bias(true).init(device),
fc2: LinearConfig::new(hidden_dim, dim).with_bias(true).init(device),
norm: LunaLayerNorm::new(hidden_dim, norm_eps, device),
}
}
pub fn forward(&self, x: Tensor<B, 3>) -> Tensor<B, 3> {
let h = gelu(self.fc1.forward(x));
let h = self.norm.forward(h);
self.fc2.forward(h)
}
}