pulsatrix 1.1.0
Loading...
Searching...
No Matches
steering.hpp
Go to the documentation of this file.
1
13#pragma once
14
15#include <cstdint>
16#include <functional>
17#include <vector>
18
19#include "pulsatrix/causal_lm.hpp" // HiddenStateHook
21
22namespace pulsatrix {
23
29[[nodiscard]] std::vector<float> DifferenceOfMeans(const std::vector<float>& positive, const std::vector<float>& negative, int64_t d);
30
33[[nodiscard]] std::vector<float> FeaturizerDirection(Featurizer& featurizer, int64_t feature);
34
42[[nodiscard]] HiddenStateHook SteeringHook(int64_t position, std::vector<float> direction, float coefficient, std::vector<bool> rows = {});
43
48 std::vector<double> coefficients = {-0.5, -0.25, 0.0, 0.25, 0.5};
50 int64_t random_directions = 3;
51 uint64_t seed = 0;
52};
53
56 std::vector<double> coefficients;
58 std::vector<double> mean_behavior;
60 std::vector<double> random_mean_behavior;
63 std::vector<double> steerability;
65 double steerability_sd = 0;
73 double over_random = 0;
74};
75
85[[nodiscard]] SteeringReport MeasureSteering(const std::function<double(int64_t i, const HiddenStateHook& hook)>& behavior,
86 int64_t num_inputs, int64_t position, const std::vector<float>& direction,
87 const SteeringOptions& options = {});
88
89} // namespace pulsatrix
A Llama-family decoder-only language model built from a Hugging Face config, and loading its Hugging ...
A featurizer maps activations x, (N, input_dim), to codes f = encode(x), (N, num_features),...
Definition featurizer.hpp:45
The featurizer family's common interface (FEAT-1): models that rewrite activations as sparse codes ov...
Definition acquisition_functions.hpp:16
SteeringReport MeasureSteering(const std::function< double(int64_t i, const HiddenStateHook &hook)> &behavior, int64_t num_inputs, int64_t position, const std::vector< float > &direction, const SteeringOptions &options={})
Measures steering along direction, and along random directions of the same norm.
HiddenStateHook SteeringHook(int64_t position, std::vector< float > direction, float coefficient, std::vector< bool > rows={})
A hook that adds coefficient * direction to the hidden states at position (0 is the embeddings,...
std::function< Tensor(int64_t position, const Tensor &hidden)> HiddenStateHook
Reads or replaces a language model's residual stream during forward() (FEAT-3): called with a positio...
Definition causal_lm.hpp:37
std::vector< float > FeaturizerDirection(Featurizer &featurizer, int64_t feature)
Feature feature's decoder direction, as a steering direction (unit length for a featurizer with unit-...
@ DifferenceOfMeans
The difference of the two sets' mean activations. It needs no fitting, and doesn't rotate towards dim...
Definition steering.hpp:44
std::vector< double > coefficients
The coefficients the direction is scaled by, 0 included as the unsteered baseline....
Definition steering.hpp:48
int64_t random_directions
Random directions of the same norm, the control.
Definition steering.hpp:50
uint64_t seed
Definition steering.hpp:51
MeasureSteering()'s result.
Definition steering.hpp:55
std::vector< double > mean_behavior
The behavior averaged over inputs, per coefficient.
Definition steering.hpp:58
double random_max_abs_steerability
Definition steering.hpp:70
std::vector< double > coefficients
Definition steering.hpp:56
std::vector< double > random_mean_behavior
The same, averaged over the random directions too.
Definition steering.hpp:60
double steerability_sd
Definition steering.hpp:65
double mean_steerability
Definition steering.hpp:64
double over_random
mean_steerability over the largest random magnitude: how far the direction stands above directions wi...
Definition steering.hpp:73
double anti_steerable_fraction
The share of inputs with negative steerability: steering moves them the wrong way.
Definition steering.hpp:67
std::vector< double > steerability
Each input's steerability: the least-squares slope of its behavior against the coefficient (Tan et al...
Definition steering.hpp:63
double random_mean_steerability
The random directions' mean steerability, and the largest of their magnitudes.
Definition steering.hpp:69