pulsatrix 1.1.0
Loading...
Searching...
No Matches
point_cloud.hpp
Go to the documentation of this file.
1
19#pragma once
20
21#include <cstdint>
22#include <vector>
23
25#include "pulsatrix/node.hpp"
26#include "pulsatrix/tensor.hpp"
27
28namespace pulsatrix {
29
31enum class PointPooling {
33 Flatten,
37 Mean,
39 Max,
41 Last,
42};
43
56
60 int64_t sample = 0;
63 int64_t position = -1;
64};
65
87public:
93
103 void add(const Tensor& batch);
104
110 void add(const ActivationSnapshot& snapshot, NodeId node);
111
113 [[nodiscard]] int64_t size() const { return static_cast<int64_t>(origins_.size()); }
114
116 [[nodiscard]] int64_t dimension() const { return dimension_; }
117
119 [[nodiscard]] int64_t samples() const { return samples_; }
120
122 [[nodiscard]] const PointCloudOptions& options() const { return options_; }
123
125 [[nodiscard]] const std::vector<float>& values() const { return values_; }
126
128 [[nodiscard]] const std::vector<PointOrigin>& origins() const { return origins_; }
129
134 [[nodiscard]] Tensor ToTensor(DeviceBackend* backend) const;
135
136private:
137 PointCloudOptions options_;
138 int64_t dimension_ = 0;
139 int64_t samples_ = 0;
140 std::vector<float> values_;
141 std::vector<PointOrigin> origins_;
142};
143
148[[nodiscard]] PointCloud MakePointCloud(const std::vector<ActivationSnapshot>& snapshots, NodeId node,
149 PointCloudOptions options = {});
150
151} // namespace pulsatrix
Self-contained, enumerable copy of one forward pass's cached activations.
A copyable, self-contained record of every activation cached during one forward pass,...
Definition activation_snapshot.hpp:39
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:248
A set of points in R^dimension, built from activation batches.
Definition point_cloud.hpp:86
PointCloud(PointCloudOptions options={})
An empty cloud.
const std::vector< float > & values() const
The points, row-major: size() rows of dimension() values.
Definition point_cloud.hpp:125
const std::vector< PointOrigin > & origins() const
Where each point came from, in the same order as values().
Definition point_cloud.hpp:128
int64_t size() const
The number of points.
Definition point_cloud.hpp:113
int64_t samples() const
The number of samples added, over every batch.
Definition point_cloud.hpp:119
void add(const ActivationSnapshot &snapshot, NodeId node)
Adds one forward pass's activations at a node.
const PointCloudOptions & options() const
The settings it was built with.
Definition point_cloud.hpp:122
void add(const Tensor &batch)
Adds one batch.
Tensor ToTensor(DeviceBackend *backend) const
The points as a (size(), dimension()) tensor.
int64_t dimension() const
Each point's number of coordinates; 0 until the first batch.
Definition point_cloud.hpp:116
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
PointCloud MakePointCloud(const std::vector< ActivationSnapshot > &snapshots, NodeId node, PointCloudOptions options={})
A cloud from one node of several forward passes, such as one snapshot per batch.
PointPooling
How PointCloud turns one sample's activations into points.
Definition point_cloud.hpp:31
@ Mean
One point per sample: the mean over its positions.
@ Flatten
One point per sample: every dimension after the batch, flattened.
@ Max
One point per sample: the maximum over its positions, per feature.
@ PerPosition
One point per position (token, pixel): the feature axis is its coordinates.
@ Last
One point per sample: its last position, as a causal language model reads it.
Computation graph node – op type, shape, optional label, parent/child edges.
PointCloud's settings.
Definition point_cloud.hpp:45
int64_t feature_axis
The axis of an added tensor that holds the features, for every pooling but Flatten....
Definition point_cloud.hpp:54
PointPooling pooling
How each sample becomes points.
Definition point_cloud.hpp:47
Where one point of a PointCloud came from.
Definition point_cloud.hpp:58
int64_t sample
The sample: its index over every batch added, in the order they were added.
Definition point_cloud.hpp:60
int64_t position
The position within the sample (row-major over the position axes) for PerPosition and Last; -1 when t...
Definition point_cloud.hpp:63
N-dimensional tensor – owns a buffer via DeviceBackend*, RAII (Rule of Five).