Add MA-GIG explainer - #177
Open
leekwoon wants to merge 1 commit into
Open
Conversation
MA-GIG (Manifold-Aligned Guided Integrated Gradients, ICML 2026) builds the integration path in the latent space of a pretrained VAE rather than in pixel space. An axis-aligned step in latent space is mapped by the decoder Jacobian into a correlated, tangent-aligned step in pixel space, so the decoded path stays close to the data manifold and gradients are evaluated on plausible images instead of on uniformly-dimmed ones. - pnpxai/explainers/magig.py: the explainer, self-contained - tutorials/MAGIG_example_all_explainers.md: worked example on Oxford-IIIT Pet with the paper's fine-tuned ResNet-18, compared against IntegratedGradients - unit tests using a stub autoencoder, so they need no download - API docs page, mkdocs nav and README entries Verified against the reference implementation at the paper's configuration (n_steps=200, fraction=0.05, slerp, black baseline): attributions are bit-identical on ResNet-18 and GoogLeNet. MAGIG is exported but deliberately left out of AVAILABLE_EXPLAINERS, since constructing it downloads an autoencoder and a single explanation runs 200 decoder passes. The tutorial adds it explicitly via manager.add_explainer, as the LEAR tutorial does. Reference: https://arxiv.org/abs/2605.02167
leekwoon
force-pushed
the
feat/magig-explainer
branch
from
July 28, 2026 09:43
1f7b866 to
716d917
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds MA-GIG (Manifold-Aligned Guided Integrated Gradients, ICML 2026) as a PnPXAI explainer, with a worked tutorial.
Paper: https://arxiv.org/abs/2605.02167 · Reference code: https://github.com/leekwoon/ma-gig
What it does
Guided IG picks the features with the smallest gradients at each step and moves them toward the input. That update is axis-aligned in pixel space, and the tangent space of natural images is not, so the path drifts off the data manifold and the error accumulates along it. MA-GIG runs the same greedy selection inside the latent space of a pretrained VAE: an axis-aligned step in latent space becomes a column of the decoder Jacobian in pixel space, i.e. a tangent vector, so the decoded path stays close to the manifold and gradients are read off plausible images.
Contents
pnpxai/explainers/magig.pytutorials/MAGIG_example_all_explainers.mdtests/explainers/test_explainers.pydocs/api/explainer/magig.md,mkdocs.yml,README.mdVerification
Attributions are bit-identical to the reference implementation at the paper's configuration (
n_steps=200,fraction=0.05, slerp, black baseline) —max|diff| = 0.0, Pearsonr = 1.0on ResNet-18 and GoogLeNet.On the tutorial's 50-image benchmark, DiffID is 0.476 for MA-GIG against 0.347 for
IntegratedGradientsstarted from the same baseline: a gap of +0.129, against the +0.085 the paper reports for this dataset and classifier.Notes for review
Not in
AVAILABLE_EXPLAINERS. ConstructingMAGIGdownloads an autoencoder, and one explanation runs 200 decoder passes, so including it in auto-recommendation would make everyAutoExplanationheavy. The tutorial adds it explicitly withmanager.add_explainer, as the LEAR tutorial does. Happy to change this if you would rather it be recommended.No new checkpoints hosted. The paper uses the Stable Diffusion 2.1 autoencoder;
stabilityai/sd-vae-ft-msepublishes weights identical to it (verified: maximum parameter difference 0.0), so it loads from there — the same patterngfgp.pyuses for its generative model. The tutorial's classifier comes from the paper's own repository.cudnn.deterministicmatters for this method. The greedy step selects latent dimensions by a low quantile of gradient magnitude, where the distribution is dense — roughly 130 of 4096 dimensions sit within1e-7of the threshold — so a last-bit difference flips which dimensions move and the rest of the path diverges. Under PyTorch's default non-deterministic cuDNN setting, two identical calls return visibly different maps; withtorch.backends.cudnn.deterministic = Truethey are bit-identical. The constructor warns when the flag is unset on CUDA, and the tutorial sets it.