Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/CI-Python.yml

This file was deleted.

36 changes: 17 additions & 19 deletions .github/workflows/CI-Julia.yml → .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI-Julia
name: CI
on:
push:
branches:
Expand All @@ -7,43 +7,41 @@ on:
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
name: Julia ${{ matrix.version }} (${{ matrix.group }})
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
actions: write
contents: read
strategy:
fail-fast: false
matrix:
version:
- 'lts'
os:
- ubuntu-latest
arch:
- x64
- '1'

steps:
- uses: actions/checkout@v5
- uses: julia-actions/setup-julia@v2
- uses: actions/checkout@v7
- uses: julia-actions/setup-julia@v3
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- name: Install dependencies & run tests
run: julia --project=./julia --color=yes -e '
using Pkg;
Pkg.test("SmoothedDifferentiation"; coverage=true);'
arch: x64
- uses: julia-actions/cache@v3
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
with:
directories: ./julia/src
- uses: codecov/codecov-action@v5
directories: src,ext
- uses: codecov/codecov-action@v7
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: false
runic:
name: Runic formatting
Expand Down
176 changes: 1 addition & 175 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,179 +2,5 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
/julia/Manifest.toml
/julia/test/Manifest.toml
*/Manifest.toml
settings.json

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
*.lock

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# PyPI configuration file
.pypirc
File renamed without changes.
57 changes: 3 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,5 @@
# SmoothDiff
# SmoothDiff.jl

Code for the NeurIPS 2025 paper *"Smoothed Differentiation Efficiently Mitigates Shattered Gradients in Explanations"*.
Julia reference implementation of SmoothDiff for the NeurIPS 2025 paper *"Smoothed Differentiation Efficiently Mitigates Shattered Gradients in Explanations"*.

## Code

* The Julia reference implementation of SmoothDiff can be found in the [`/julia`](/julia) folder, which contains a Julia package called `SmoothedDifferentiation.jl`.
* The PyTorch reference implementation of SmoothDiff can be found in [`/python`](/python) folder.

## Installation

1. [Install Julia](https://julialang.org/downloads/) `v1.11`. On Unix systems, this requires running
```bash
curl -fsSL https://install.julialang.org | sh
```
2. Start a [Julia REPL](https://docs.julialang.org/en/v1/stdlib/REPL/) session by typing `julia` in your terminal
3. Install [DrWatson.jl](https://github.com/JuliaDynamics/DrWatson.jl) by typing the following in your Julia REPL:
```julia-repl
]add DrWatson
```
4. Run the experiments and plotting scripts listed below by typing `include("path/to/file.jl")` in your REPL, replacing the string with the correct path.

## Experiments

> [!NOTE]
> The experiment code refers to the state of the repository at the time of publication.
> See the [`neurips25`](https://github.com/adrhill/smoothdiff-experiments/tree/neurips25) tag for the exact code used in the paper.

We provide all code and virtual environments required to reproduce our experiments and figures.

### Running experiments

The following steps need to be run in sequence:

1. [Download the ImageNet dataset](https://image-net.org/download.php) by agreeing to its terms of access and run the script [`/experiments/heatmaps/save_input.jl`](/experiments/heatmaps/save_input.jl) to save preprocessed input tensors.
2. Compute explanations by running [`/experiments/cluster/run_analyzers/run.jl`](/experiments/cluster/run_analyzers/run.jl) as well as the $n=10^6$ sample SmoothGrad run in [`/experiments/cluster/run_analyzers/run_100k.jl`](/experiments/cluster/run_analyzers/run_100k.jl).
3. Compute benchmarks by running [`/experiments/cluster/run_analyzers/run.jl`](/experiments/cluster/run_analyzers/run_benchmarks.jl).
4. After having computed explanations in step 3, evaluate them using pixel-flipping by running [`/experiments/cluster/pixelflipping/run.jl`](/experiments/cluster/pixelflipping/run.jl).
5. The raw quantitative results from Appendix F can be found in [`/experiments/cluster/quantus-eval/results`](/experiments/cluster/quantus-eval/results) and are computed by running [`/experiments/cluster/quantus-eval/run.sh`](/experiments/cluster/quantus-eval/run.sh).

### Reproducing figures

After having computed explanations and pixel-flipping results, the following plots and tables can be reproduced by running the respective file:

- **Figure 1 (a)**: create data by running [`/experiments/shattered_gradient_1d/run_fig_1a.jl`](/experiments/shattered_gradient_1d/run_fig_1a.jl), then plot using [`/experiments/shattered_gradient_1d/plot_fig_1a.jl`](/experiments/shattered_gradient_1d/plot_fig_1a.jl)
- **Figure 1 (b)**: run [`/experiments/heatmaps/grid_fig_1b.jl`](/experiments/heatmaps/grid_fig_1b.jl)
- **Figure 2**: run [`/experiments/ssim_convergence/convergence_ssim_combined.jl`](/experiments/ssim_convergence/convergence_ssim_combined.jl)
- **Figure 3** and **Figure 15**: run [`/experiments/heatmaps/grid_convergence.jl`](/experiments/heatmaps/grid_convergence.jl)
- **Figure 4** and **Table 1**: run [`/experiments/pixelflipping_plots/srg_plot.jl`](/experiments/pixelflipping_plots/srg_plot.jl)
- **Figure 5**: run [`/experiments/colormaps/jetvsbatlow.jl`](/experiments/colormaps/jetvsbatlow.jl)
- **Figure 6**: run [`/experiments/heatmaps/grid_pipeline_comparison.jl`](/experiments/heatmaps/grid_pipeline_comparison.jl)
- **Figure 7**: run [`/experiments/ssim_convergence/convergence_cosine_sim.jl`](/experiments/ssim_convergence/convergence_cosine_sim.jl)
- **Figures 8 to 13**: run [`/experiments/cluster/quantus-eval/plot.jl`](/experiments/cluster/quantus-eval/plot.jl)
- **Figure 14**: run [`/experiments/beta-smoothing/plot_beta_smoothing.jl`](/experiments/beta-smoothing/plot_beta_smoothing.jl)
- **Figure 16**: run [`/experiments/heatmaps/grid_multiclass.jl`](/experiments/heatmaps/grid_multiclass.jl)
- **Figure 17**: run [`/experiments/heatmaps/grid_appendix.jl`](/experiments/heatmaps/grid_appendix.jl)
The full experiments can be found here: https://github.com/adrhill/smoothdiff-experiments/
Loading
Loading