pulsatrix 1.1.0
Loading...
Searching...
No Matches
mlp_hook.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <functional>
9#include <stdexcept>
10
11#include "pulsatrix/tensor.hpp"
12
13namespace pulsatrix {
14
23using MlpHook = std::function<Tensor(const Tensor& mlp_input, const Tensor& mlp_output)>;
24
25namespace detail {
27inline Tensor ApplyMlpHook(const MlpHook& hook, const Tensor& input, const Tensor& output) {
28 Tensor out = hook(input, output);
29 if (out.shape() != output.shape()) throw std::invalid_argument("MLP hook: the replacement must keep the MLP output's shape");
30 return out;
31}
32} // namespace detail
33
34} // namespace pulsatrix
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
const Shape & shape() const
This tensor's shape.
Definition tensor.hpp:113
Tensor ApplyMlpHook(const MlpHook &hook, const Tensor &input, const Tensor &output)
Runs hook and checks its result keeps the shape.
Definition mlp_hook.hpp:27
Definition acquisition_functions.hpp:16
std::function< Tensor(const Tensor &mlp_input, const Tensor &mlp_output)> MlpHook
Called with an MLP's input (after the block's norm, where it has one) and its output (the branch adde...
Definition mlp_hook.hpp:23
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).