pulsatrix 1.1.0
Loading...
Searching...
No Matches
fine_tune_diff.hpp File Reference

What did a fine-tune change? The fine-tuned model's relevance minus the base model's for the same prediction, input by input and token by token across a dataset, and intruder dimensions: new top singular directions in the fine-tuned weights (TRN-11). More...

#include <cstdint>
#include <map>
#include <string>
#include <vector>
#include "pulsatrix/lrp_rule_config.hpp"
#include "pulsatrix/module.hpp"
#include "pulsatrix/tensor.hpp"
Include dependency graph for fine_tune_diff.hpp:

Go to the source code of this file.

Classes

struct  pulsatrix::DiffTarget
 Which output both models are asked to explain. More...
 
struct  pulsatrix::RelevanceDiff
 The two explanations of the same prediction, and their difference. More...
 
struct  pulsatrix::TokenShift
 One token's relevance shift, averaged over every occurrence seen. More...
 
class  pulsatrix::TokenRelevanceShift
 Collects RelevanceDiff results over a dataset by input token: which tokens a fine-tune made the model rely on more, and which less. More...
 
struct  pulsatrix::IntruderResult
 Intruder dimensions of one weight matrix (Shuttleworth et al., 2024, Definition 3.1). More...
 
struct  pulsatrix::LayerIntruders
 IntruderDimensions() for one named layer. More...
 

Namespaces

namespace  pulsatrix
 

Functions

RelevanceDiff pulsatrix::DiffRelevance (Module &base, Module &tuned, const Tensor &input, const DiffTarget &target={}, const LRPRuleConfig &config={})
 Explains the same prediction in both models: forward() on input, then relevance seeded with each model's own score for the class, at the class only.
 
RelevanceDiff pulsatrix::DiffAdapterRelevance (Module &model, const Tensor &input, const DiffTarget &target={}, const LRPRuleConfig &config={})
 DiffRelevance() for a fine-tune held as adapters on model: the tuned run with its LoRA adapters, IA³ vectors and (for a CausalLM) interventions on, the base run with them off. They are back on afterwards, even if a call throws.
 
IntruderResult pulsatrix::IntruderDimensions (const Tensor &base, const Tensor &tuned, int64_t k=10, double epsilon=0.6)
 Counts the top-k singular vectors of tuned that no singular vector of base resembles: |cos| < epsilon against every one of them.
 
std::vector< LayerIntruders > pulsatrix::LoraIntruderDimensions (Module &model, int64_t k=10, double epsilon=0.6)
 Intruder dimensions of every LoRA layer: its base weight W against W + (alpha / r) A B.
 
std::vector< LayerIntruders > pulsatrix::IntruderDimensions (Module &base, Module &tuned, int64_t k=10, double epsilon=0.6)
 Intruder dimensions of every LinearModule the two models share by name and shape: a full fine-tune against its base.
 

Detailed Description

What did a fine-tune change? The fine-tuned model's relevance minus the base model's for the same prediction, input by input and token by token across a dataset, and intruder dimensions: new top singular directions in the fine-tuned weights (TRN-11).

Works for a fine-tune held as adapters on the base model (LoRA, IA³, LoReFT), which DiffAdapterRelevance() switches off and on, and for two separate models of the same architecture, such as a full fine-tune and its base, with DiffRelevance().