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

Explaining a continuous diffusion sampler end to end (DIFF-5): trajectory LRP (design D1), which seeds a scalar of the final sample x_0 once and carries its relevance back through every reverse step to the starting noise x_T, the conditioning, and named sinks. More...

#include <cstdint>
#include <vector>
#include "pulsatrix/lrp_rule_config.hpp"
#include "pulsatrix/module.hpp"
#include "pulsatrix/noise_schedule.hpp"
Include dependency graph for trajectory_lrp.hpp:

Go to the source code of this file.

Classes

struct  pulsatrix::DenoiserRelevance
 Where the network's share of one step landed. More...
 
class  pulsatrix::ContinuousDenoiser
 The noise predictor eps_theta as the explainer sees it, with its conditioning fixed: a forward pass that keeps what the relevance pass needs, and the relevance pass. More...
 
class  pulsatrix::ConcatDenoiser
 A Module that reads [x_t, embedding(t), c] as one row, conditioned by concatenation as in tests/diffusion_integration_test.cpp: x_t, then a sinusoidal timestep embedding (SinusoidalTimestepEmbedding), then a fixed conditioning vector such as a one-hot class. Its input relevance is split back into those three parts. More...
 
struct  pulsatrix::ContinuousSamplerConfig
 
struct  pulsatrix::ContinuousTrajectory
 A reverse process, recorded so it can be explained: every state and every noise draw. More...
 
struct  pulsatrix::TrajectoryLrpConfig
 
struct  pulsatrix::TrajectoryHop
 One reverse step's split, aggregated over elements. More...
 
struct  pulsatrix::TrajectoryRelevance
 Where the seed's relevance went. The budget balances exactly: value = x_T + condition + time + noise + absorbed + leak. More...
 

Namespaces

namespace  pulsatrix
 

Enumerations

enum class  pulsatrix::ContinuousSampler { pulsatrix::Ddpm , pulsatrix::Ddim }
 Which reverse process to run. More...
 
enum class  pulsatrix::TrajectorySplit { pulsatrix::AbsoluteRatio , pulsatrix::SignedEpsilon , pulsatrix::SignedRatio }
 How the relevance on x_prev is split across skip, network and noise (h_1, h_2, h_3). More...
 

Functions

LRPRuleConfig pulsatrix::TrajectoryNetworkRules ()
 The network rules ConcatDenoiser uses unless told otherwise: the epsilon rule with the bias in the denominator (Zennit's), so the biases absorb their share. The codebase's default pre-bias rule divides by x W alone, which a hidden layer's bias can leave near zero while the unit is active; chained over the steps of a sampler its relevance blew up (DIFF-5's planted DDPM: conditioning shares up to 570 times the explained value).
 
ContinuousTrajectory pulsatrix::SampleContinuousDiffusion (ContinuousDenoiser &model, const NoiseSchedule &schedule, const std::vector< float > &x_T, const ContinuousSamplerConfig &config)
 Runs the reverse process from x_T and records it.
 
std::vector< float > pulsatrix::StandardNormal (size_t n, uint64_t seed)
 Draws n standard normal values from seed, as SampleContinuousDiffusion does.
 
std::vector< float > pulsatrix::RegionSeed (const std::vector< float > &sample, const std::vector< int64_t > &region)
 The sum of sample over region: relevance x0_i on the region's elements, 0 elsewhere.
 
std::vector< float > pulsatrix::ReconstructionSeed (const std::vector< float > &sample, const std::vector< float > &reference)
 The reconstruction error ||x_0 - reference||^2, as LRP for autoencoders seeds it (Kobayashi et al. 2023): relevance (x0_i - ref_i)^2 on each element.
 
TrajectoryRelevance pulsatrix::ExplainTrajectory (ContinuousDenoiser &model, const ContinuousTrajectory &trajectory, const std::vector< float > &seed, const TrajectoryLrpConfig &config={})
 Explains seed, relevance on the trajectory's sample x_0 (RegionSeed, ReconstructionSeed, or a downstream classifier's input relevance), back through trajectory, which SampleContinuousDiffusion produced with model.
 

Detailed Description

Explaining a continuous diffusion sampler end to end (DIFF-5): trajectory LRP (design D1), which seeds a scalar of the final sample x_0 once and carries its relevance back through every reverse step to the starting noise x_T, the conditioning, and named sinks.

A DDPM or DDIM step is x_prev = skip * x_t - network * eps_theta(x_t, t, c) + noise * z, a residual block with a third, injected-noise term. The relevance on each element of x_prev is split across the three terms, by default keeping each term's sign (TrajectorySplit::SignedRatio). The skip share goes straight to x_t; the network share runs through eps_theta with its own LRP rules onto x_t, the conditioning c and the timestep embedding (a sink); the noise share is a sink too, exactly zero under DDIM. Only the trajectory is stored, and each step's forward pass is rerun just before its relevance pass. See docs/interpretability/diffusion-lrp.md (D1) for the derivation and its limits.