pulsatrix
Loading...
Searching...
No Matches
activation_snapshot.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <optional>
8#include <string>
9#include <unordered_map>
10#include <utility>
11#include <vector>
12
13#include "pulsatrix/assert.hpp"
14#include "pulsatrix/node.hpp"
15#include "pulsatrix/op_type.hpp"
16#include "pulsatrix/tensor.hpp"
17
18namespace pulsatrix {
19
40public:
42 struct NodeMetadata {
45
47 std::optional<std::string> label;
48 };
49
61 ActivationSnapshot(std::unordered_map<NodeId, Tensor> activations, std::vector<NodeId> node_ids,
62 std::unordered_map<NodeId, NodeMetadata> metadata)
63 : activations_(std::move(activations)), node_ids_(std::move(node_ids)), metadata_(std::move(metadata)) {}
64
73 [[nodiscard]] const Tensor& activation(NodeId id) const {
74 auto it = activations_.find(id);
75 PULSATRIX_ASSERT(it != activations_.end());
76 return it->second;
77 }
78
84 [[nodiscard]] const std::vector<NodeId>& node_ids() const { return node_ids_; }
85
90 [[nodiscard]] OpType op_type(NodeId id) const {
91 auto it = metadata_.find(id);
92 PULSATRIX_ASSERT(it != metadata_.end());
93 return it->second.op_type;
94 }
95
101 [[nodiscard]] std::optional<std::string> label(NodeId id) const {
102 auto it = metadata_.find(id);
103 PULSATRIX_ASSERT(it != metadata_.end());
104 return it->second.label;
105 }
106
107private:
108 std::unordered_map<NodeId, Tensor> activations_;
109 std::vector<NodeId> node_ids_;
110 std::unordered_map<NodeId, NodeMetadata> metadata_;
111};
112
113} // namespace pulsatrix
PULSATRIX_ASSERT – debug-only invariant check for programmer errors, distinct from throw (used for ca...
#define PULSATRIX_ASSERT(cond)
Aborts with a diagnostic message if cond is false. Debug-only – use for conditions that indicate a bu...
Definition assert.hpp:22
A copyable, self-contained record of every activation cached during one forward pass,...
Definition activation_snapshot.hpp:39
OpType op_type(NodeId id) const
The op-type tag captured at a node.
Definition activation_snapshot.hpp:90
ActivationSnapshot(std::unordered_map< NodeId, Tensor > activations, std::vector< NodeId > node_ids, std::unordered_map< NodeId, NodeMetadata > metadata)
Constructs a snapshot from already-captured data.
Definition activation_snapshot.hpp:61
const std::vector< NodeId > & node_ids() const
Every captured node id, in topological order as of capture time.
Definition activation_snapshot.hpp:84
const Tensor & activation(NodeId id) const
The activation value captured at a node.
Definition activation_snapshot.hpp:73
std::optional< std::string > label(NodeId id) const
The optional label captured at a node.
Definition activation_snapshot.hpp:101
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Definition acquisition_functions.hpp:16
size_t NodeId
Stable identifier for a Node within its owning ComputationGraph.
Definition node.hpp:18
OpType
The op-type tag a Node carries. Charter Part 2 §3: nodes are tagged by a small closed set of op types...
Definition op_type.hpp:19
Computation graph node – op type, shape, optional label, parent/child edges.
Closed set of operation categories every graph Node is tagged with.
Per-node metadata captured alongside the activation value.
Definition activation_snapshot.hpp:42
OpType op_type
The node's op-type tag, as of capture time.
Definition activation_snapshot.hpp:44
std::optional< std::string > label
The node's optional human-readable label (e.g. a layer name).
Definition activation_snapshot.hpp:47
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).