SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2412.08480 · 2024

InvDiff: Invariant Guidance for Bias Mitigation in Diffusion Models

arXiv · PDF · Open in the Atlas

Code that ran

9 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 8 failures of our instrument; 2 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2412.08480.json · badge: /api/ran/2412.08480.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
hundredl/invdiff canonical (classifier label)
classifier basis: census
9 ran · 2 no recorded run
FunctionStatusWhere it lives
calculate_debias_score Ran
ran; our contract draft was wrong, not the code
hundredl/invdiff/src/utils/score/bias_score.py
code served (permissive licence) · get_code("ad2e2a000b9c7682")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family float, shape (3,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Analyze the function to understand what it needs:
# - K: an integer representing number of classes/categories
# - prompts_count: an integer representing number of prompts
# - prompt_indexs: a list/array of indices into prompts (should have values 0 to prompts_count-1)
# - pred_results: a list/array of predicted results (should have values 0 to K-1)
# The function creates a matrix of shape (prompts_count, K) and fills it based on
# the correspondence between prompt_indexs and pred_results

# Set up small but valid arguments
K = 4  # number of classes
prompts_count = 3  # number of prompts
num_samples = 6  # total number of predictions (should be multiple of prompts_count for generate_nums to work well)

# Create prompt_indexs: indices that cycle through prompts
# For 6 samples and 3 prompts, we get [0, 1, 2, 0, 1, 2]
prompt_indexs = np.array([i % prompts_count for i in range(num_samples)])

# Create pred_results: random predictions from 0 to K-1
np.random.seed(0)
pred_results = np.random.randint(0, K, size=num_samples)

ARGS = {
    "K": K,
    "prompts_count": prompts_count,
    "prompt_indexs": prompt_indexs,
    "pred_results": pred_results
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family float, shape (3,) — shape (3,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
compute_pairwise_distances Ran
ran, honoured the contract we drafted
hundredl/invdiff/src/utils/score/improved_prd.py
code served (permissive licence) · get_code("af985ecf236605b0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 2, dtype family float, shape (2, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Set random seed for reproducibility
np.random.seed(0)

# Create small numpy arrays for testing
# X: shape (2, 4) - 2 samples, 4 dimensions
X = np.array([
    [1.0, 2.0, 3.0, 4.0],
    [5.0, 6.0, 7.0, 8.0]
], dtype=np.float64)

# Y: shape (3, 4) - 3 samples, 4 dimensions (different from X to show non-square output)
Y = np.array([
    [1.5, 2.5, 3.5, 4.5],
    [5.5, 6.5, 7.5, 8.5],
    [9.0, 10.0, 11.0, 12.0]
], dtype=np.float64)

ARGS = {
    "X": X,
    "Y": Y
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family float, shape (2, 3) — shape (2, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
distances2radii Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
hundredl/invdiff/src/utils/score/improved_prd.py
pointer only (licence: MIT); the stored copy get_code serves, from AlexVerine/PrecisionRecallGan, is pointer only (licence: NONE) · get_code("321ebed484cb3298")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from AlexVerine/PrecisionRecallGan, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_kth_value Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
hundredl/invdiff/src/utils/score/improved_prd.py
pointer only (licence: MIT); the stored copy get_code serves, from AlexVerine/PrecisionRecallGan, is pointer only (licence: NONE) · get_code("bcc716018b80b027")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from AlexVerine/PrecisionRecallGan, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

load_pic_dataset Ran
ran; our contract draft was wrong, not the code
hundredl/invdiff/src/utils/score/bias_score.py
code served (permissive licence) · get_code("3615d4cc8893f913")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import tempfile
import os
from PIL import Image
import shutil

torch.manual_seed(0)

# Create a temporary directory with fake image data
temp_dir = tempfile.mkdtemp()
class_dir = os.path.join(temp_dir, "class_0")
os.makedirs(class_dir, exist_ok=True)

# Create a small fake image file
fake_image = Image.new('RGB', (100, 100), color='red')
fake_image.save(os.path.join(class_dir, "image_0.jpg"))

image_path = temp_dir

ARGS = {
    "image_path": image_path,
    "need_transform": True,
    "batch_size": 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_pic_dataset Ran
ran; our contract draft was wrong, not the code
hundredl/invdiff/src/utils/score/clip_score.py
code served (permissive licence) · get_code("44f09524879d9935")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import tempfile
import os
from PIL import Image
from pathlib import Path

torch.manual_seed(0)

# Create a temporary directory with a valid ImageFolder structure
temp_dir = tempfile.mkdtemp()
class1_dir = os.path.join(temp_dir, 'class1')
os.makedirs(class1_dir, exist_ok=True)

# Create a small dummy image (224x224 RGB)
img = Image.new('RGB', (224, 224), color=(73, 109, 137))
img_path = os.path.join(class1_dir, 'dummy.jpg')
img.save(img_path)

ARGS = {
    'image_path': temp_dir,
    'need_transform': True,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
process_train Ran
ran; our contract draft was wrong, not the code
hundredl/invdiff/src/train_classifier.py
code served (permissive licence) · get_code("3957a0589de806cc")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import argparse
from PIL import Image
import numpy as np

torch.manual_seed(0)

# Create a mock args object
class MockArgs:
    def __init__(self):
        self.label_name = 'Male'

args = MockArgs()

# Create sample image data
def create_dummy_image():
    """Create a small dummy PIL image"""
    img_array = np.random.randint(0, 256, (64, 64, 3), dtype=np.uint8)
    return Image.fromarray(img_array, 'RGB')

# Build the data dict for celeba dataset
data = {
    'image': [create_dummy_image() for _ in range(2)],
    'dataset_name': ['celeba'],
    'Blond_Hair': ['1', '0'],
    'Male': ['1', '0'],
    'label': torch.tensor([1, 0])
}

ARGS = {
    'data': data
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
process_train_for_one Ran
ran; our contract draft was wrong, not the code
hundredl/invdiff/src/train_classifier.py
code served (permissive licence) · get_code("ccf2fa49689a52e5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from PIL import Image
import numpy as np

torch.manual_seed(0)

# Create a minimal single_data dict that the function expects
# The function expects a dict with 'image' (PIL Image) and 'place' (numeric label)
pil_image = Image.fromarray(np.random.randint(0, 256, (224, 224, 3), dtype=np.uint8))

single_data = {
    'image': pil_image,
    'place': 5
}

ARGS = {
    'single_data': single_data
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
process_val_for_one Ran
ran; our contract draft was wrong, not the code
hundredl/invdiff/src/train_classifier.py
code served (permissive licence) · get_code("3ca1e034cf9f7749")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from PIL import Image
import numpy as np

torch.manual_seed(0)

# Create a minimal single_data dict with the required structure
# The function expects 'image' to be a PIL Image with a convert method
# and 'place' to be a label value

# Create a small PIL Image (4x3 RGB)
img_array = np.random.randint(0, 256, (4, 3, 3), dtype=np.uint8)
pil_image = Image.fromarray(img_array, mode='RGB')

single_data = {
    'image': pil_image,
    'place': 1
}

ARGS = {
    'single_data': single_data
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_clip_score Not yet run
unverified (harvested, no recorded run)
hundredl/invdiff/src/utils/score/clip_score.py
code served (permissive licence) · get_code("e2b97b3cd45e225a")
How it ran

no invocation recorded.

load_classifier_model Not yet run
unverified (harvested, no recorded run)
hundredl/invdiff/src/utils/score/bias_score.py
code served (permissive licence) · get_code("e33d88ba86e28104")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 3 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 0 later) and 8 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
compute_pairwise_distances 2 other papers
2 dated earlier
1904.06991 (2019-04)
Improved Precision and Recall Metric for Assessing Generative Models
2304.07574 (2023-04)
Exploring Incompatible Knowledge Transfer in Few-shot Image Generation
distances2radii 2 other papers
2 dated earlier
1904.06991 (2019-04)
Improved Precision and Recall Metric for Assessing Generative Models
2304.07574 (2023-04)
Exploring Incompatible Knowledge Transfer in Few-shot Image Generation
get_kth_value 2 other papers
2 dated earlier
1904.06991 (2019-04)
Improved Precision and Recall Metric for Assessing Generative Models
2304.07574 (2023-04)
Exploring Incompatible Knowledge Transfer in Few-shot Image Generation

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

As one of the most successful generative models, diffusion models have demonstrated remarkable efficacy in synthesizing high-quality images. These models learn the underlying high-dimensional data distribution in an unsupervised manner. Despite their success, diffusion models are highly data-driven and prone to inheriting the imbalances and biases present in real-world data. Some studies have attempted to address these issues by designing text prompts for known biases or using bias labels to construct unbiased data. While these methods have shown improved results, real-world scenarios often contain various unknown biases, and obtaining bias labels is particularly challenging. In this paper, we emphasize the necessity of mitigating bias in pre-trained diffusion models without relying on auxiliary bias annotations. To tackle this problem, we propose a framework, InvDiff, which aims to learn invariant semantic information for diffusion guidance. Specifically, we propose identifying underlying biases in the training data and designing a novel debiasing training objective. Then, we employ a lightweight trainable module that automatically preserves invariant semantic information and uses it to guide the diffusion model's sampling process toward unbiased outcomes simultaneously. Notably, we only need to learn a small number of parameters in the lightweight learnable module without altering the pre-trained diffusion model. Furthermore, we provide a theoretical guarantee that the implementation of InvDiff is equivalent to reducing the error upper bound of generalization. Extensive experimental results on three publicly available benchmarks demonstrate that InvDiff effectively reduces biases while maintaining the quality of image generation. Our code is available at https://github.com/Hundredl/InvDiff.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2412.08480")
get_code_for_paper("2412.08480")
have("2412.08480")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2412.08480.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2412.08480.svg)](https://syntology.ai/paper/2412.08480)

Connect an agent — have() is free.