SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.07487 · 2024

GLAD: Towards Better Reconstruction with Global and Local Adaptive Diffusion Models for Unsupervised Anomaly Detection

arXiv · PDF · Open in the Atlas

Code that ran

13 of 15 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; 5 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 7 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/2406.07487.json · badge: /api/ran/2406.07487.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
hyao1/glad canonical (classifier label)
classifier basis: census
13 ran · 2 no recorded run
FunctionStatusWhere it lives
betas_for_alpha_bar Ran
ran, honoured the contract we drafted
hyao1/glad/ddim_scheduling.py
pointer only (licence: MIT); the stored copy get_code serves, from jabir-zheng/TCD, is pointer only (licence: NONE) · get_code("f1e3f7493aad4745")
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 jabir-zheng/TCD, 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.

bool_flag Ran
ran, violated the contract we drafted
hyao1/glad/dino/utils.py
pointer only (licence: MIT); the stored copy get_code serves, from sthalles/MaSSL, is pointer only (licence: NONE) · get_code("c19231378e41dc5a")
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 sthalles/MaSSL, 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.

clip_gradients Ran
ran, honoured the contract we drafted
hyao1/glad/dino/utils.py
code served (permissive licence) · get_code("2b5489053b222e00")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 torch.nn as nn

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        return self.linear2(self.linear1(x))

model = SimpleModel()

# Create a simple forward pass and backward pass to populate gradients
x = torch.randn(2, 4)
y = torch.randn(2, 2)
output = model(x)
loss = nn.MSELoss()(output, y)
loss.backward()

clip = 1.0

ARGS = {
    "model": model,
    "clip": clip,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
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
cosine_scheduler Ran
ran, honoured the contract we drafted
hyao1/glad/dino/utils.py
code served (permissive licence) · get_code("361a6b24f11fc50a")
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) and returned ndarray, ndim 1, dtype family float, shape (500,) 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

ARGS = {
    "base_value": 0.1,
    "final_value": 0.001,
    "epochs": 10,
    "niter_per_ep": 50,
    "warmup_epochs": 2,
    "start_warmup_value": 0.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 (500,) — shape (500,) 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
drop_path Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
hyao1/glad/dino/vision_transformer.py
pointer only (licence: MIT); the stored copy get_code serves, from gladzhang/Xformer, is pointer only (licence: NONE) · get_code("55120f2026b56aa2")
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 gladzhang/Xformer, 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.

encode_prompt Ran
ran; our contract draft was wrong, not the code
hyao1/glad/main_multi.py
code served (permissive licence) · get_code("d846bc783d914e10")
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 Tensor, ndim 3, dtype family float, shape (2, 3, 4) 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 torch
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal text encoder that accepts input_ids and attention_mask
class MinimalTextEncoder(nn.Module):
    def __init__(self, hidden_size=4):
        super().__init__()
        self.hidden_size = hidden_size
        self.embedding = nn.Embedding(num_embeddings=100, embedding_dim=hidden_size)
        self.linear = nn.Linear(hidden_size, hidden_size)
    
    def forward(self, input_ids, attention_mask=None):
        # Return a tuple where first element is the embeddings
        embeds = self.embedding(input_ids)
        output = self.linear(embeds)
        return (output,)

# Create instances
text_encoder = MinimalTextEncoder(hidden_size=4)
text_inputs_ids = torch.randint(0, 100, (2, 3), dtype=torch.long)  # batch_size=2, seq_len=3
device = 'cpu'

ARGS = {
    'text_encoder': text_encoder,
    'text_inputs_ids': text_inputs_ids,
    'device': device
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) 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
generate_fractal_noise_2d Ran
ran; our contract draft was wrong, not the code
hyao1/glad/dataset/perlin_noise.py
pointer only (licence: MIT); the stored copy get_code serves, from anindyasdas/adl4vad, is pointer only (licence: NONE) · get_code("293a2b1189b747fd")
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 anindyasdas/adl4vad, 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.

generate_perlin_noise_2d Ran
ran; our contract draft was wrong, not the code
hyao1/glad/dataset/perlin_noise.py
pointer only (licence: MIT); the stored copy get_code serves, from anindyasdas/adl4vad, is pointer only (licence: NONE) · get_code("ed9e127befc02046")
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 anindyasdas/adl4vad, 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.

lerp_np Ran
ran, honoured the contract we drafted
hyao1/glad/dataset/perlin_noise.py
pointer only (licence: MIT); the stored copy get_code serves, from Chhro123/fast-foreground-aware-anomaly-synthesis, is pointer only (licence: NONE) · get_code("4de91a4627a51ea2")
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 Chhro123/fast-foreground-aware-anomaly-synthesis, 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.

loss_fucntion Ran
ran, honoured the contract we drafted
hyao1/glad/train_dino.py
code served (permissive licence) · get_code("1606edd39398af6c")
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 Tensor, ndim 0, dtype family float, shape () 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 torch

torch.manual_seed(0)

# Create small tensors for the lists i, r, fi, fr
# The function expects lists of tensors where each tensor has shape (batch_size, ...)
# It reshapes them to (batch_size, -1), so we need at least 2D tensors

# Create 3 items in each list with different shapes to be distinct
i = [
    torch.randn(2, 4),      # batch_size=2, flattened_dim=4
    torch.randn(2, 3),      # batch_size=2, flattened_dim=3
    torch.randn(2, 5),      # batch_size=2, flattened_dim=5
]

r = [
    torch.randn(2, 4),
    torch.randn(2, 3),
    torch.randn(2, 5),
]

fi = [
    torch.randn(2, 4),
    torch.randn(2, 3),
    torch.randn(2, 5),
]

fr = [
    torch.randn(2, 4),
    torch.randn(2, 3),
    torch.randn(2, 5),
]

lmd = 0.5

ARGS = {
    "i": i,
    "r": r,
    "fi": fi,
    "fr": fr,
    "lmd": lmd,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () 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
rescale_noise_cfg Ran
ran; our contract draft was wrong, not the code
hyao1/glad/pipeline.py
code served (permissive licence) · get_code("bea2d776a332f2b0")
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) and returned Tensor, ndim 4, dtype family float, shape (2, 4, 3, 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 torch

torch.manual_seed(0)

# Create small tensors with distinct dimensions
# noise_cfg: shape (batch=2, channels=4, height=3, width=3)
noise_cfg = torch.randn(2, 4, 3, 3)

# noise_pred_text: shape (batch=2, channels=4, height=3, width=3)
noise_pred_text = torch.randn(2, 4, 3, 3)

# guidance_rescale: float between 0 and 1
guidance_rescale = 0.7

ARGS = {
    "noise_cfg": noise_cfg,
    "noise_pred_text": noise_pred_text,
    "guidance_rescale": guidance_rescale,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 4, 3, 3) — shape (2, 4, 3, 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
rescale_zero_terminal_snr Ran
ran; our contract draft was wrong, not the code
hyao1/glad/ddim_scheduling.py
pointer only (licence: MIT); the stored copy get_code serves, from siqi0905/gardiff, is pointer only (licence: NONE) · get_code("6b47c0cd573d42ff")
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 siqi0905/gardiff, 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.

tokenize_prompt Ran
ran; our contract draft was wrong, not the code
hyao1/glad/dataset/dataset_multiclass.py
pointer only (licence: MIT); the stored copy get_code serves, from 120l020904/ace, is pointer only (licence: NONE) · get_code("a67a2074238bd9ef")
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 120l020904/ace, 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.

compute_text_embeddings Not yet run
unverified (harvested, no recorded run)
hyao1/glad/main_multi.py
code served (permissive licence) · get_code("551bb566734184cc")
How it ran

no invocation recorded.

parse_args Not yet run
unverified (harvested, no recorded run)
hyao1/glad/main_multi.py
code served (permissive licence) · get_code("752b8d77518927c2")
How it ran

no invocation recorded.

Also present in other papers' code

Of 15 samples lifted from this paper's linked repositories, 15 carry a function identity and 0 do not. Of the 15 distinct functions with an identity, 11 are also present in other papers whose code we hold (11 with at least one paper dated earlier, 5 the same month, 11 later) and 4 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
drop_path 224 other papers
169 dated earlier, 4 the same month, 43 later, 7 same year, order not determinable, 1 undated · 38 only as an assembly brick
2003.12039 (2020-03)
RAFT: Recurrent All-Pairs Field Transforms for Optical Flow
2007.09384 (2020-07)
Multi-Scale Positive Sample Refinement for Few-Shot Object Detection
2010.11929 (2020-10)
An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
and 221 more not named here
rescale_noise_cfg 62 other papers
26 dated earlier, 3 the same month, 32 later, 1 same year, order not determinable
2206.02779 (2022-06)
Blended Latent Diffusion
2304.06720 (2023-04)
Expressive Text-to-Image Generation with Rich Text
2309.06380 (2023-09)
InstaFlow: One Step is Enough for High-Quality Diffusion-Based Text-to-Image Generation
and 59 more not named here
cosine_scheduler 37 other papers
30 dated earlier, 1 the same month, 5 later, 1 same year, order not determinable
2005.10242 (2020-05)
Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere
2103.15375 (2021-03)
AlignMixup: Improving Representations By Interpolating Aligned Features
2106.09681 (2021-06)
XCiT: Cross-Covariance Image Transformers
and 34 more not named here
bool_flag 31 other papers
25 dated earlier, 1 the same month, 4 later, 1 same year, order not determinable
2106.09681 (2021-06)
XCiT: Cross-Covariance Image Transformers
2109.13228 (2021-09)
PASS: An ImageNet replacement for self-supervised pretraining without humans
2111.12958 (2021-11)
Self-Distilled Self-Supervised Representation Learning
and 28 more not named here
clip_gradients 28 other papers
22 dated earlier, 1 the same month, 4 later, 1 same year, order not determinable
2106.09681 (2021-06)
XCiT: Cross-Covariance Image Transformers
2109.13228 (2021-09)
PASS: An ImageNet replacement for self-supervised pretraining without humans
2111.12958 (2021-11)
Self-Distilled Self-Supervised Representation Learning
and 25 more not named here
betas_for_alpha_bar 14 other papers
8 dated earlier, 5 later, 1 same year, order not determinable
2303.01469 (2023-03)
Consistency Models
2311.15908 (2023-11)
Enhancing Perceptual Quality in Video Super-Resolution through Temporally-Consistent Detail Synthesis using Diffusion Models
2311.18832 (2023-11)
Exploiting Diffusion Prior for Generalizable Dense Prediction
and 11 more not named here
rescale_zero_terminal_snr 9 other papers
4 dated earlier, 5 later
2311.18832 (2023-11)
Exploiting Diffusion Prior for Generalizable Dense Prediction
2403.14468 (2024-03)
AnyV2V: A Tuning-Free Framework For Any Video-to-Video Editing Tasks
2404.06025 (2024-04)
Greedy-DiM: Greedy Algorithms for Unreasonably Effective Face Morphs
and 6 more not named here
lerp_np 8 other papers
4 dated earlier, 4 later
Zavrtanik_DRAEM_-_A_Discriminatively_Trained_Reconstruction_Embedding_for_Surface_Anomaly_ICCV_2021_paper (2021 (year only))
DRAEM -A discriminatively trained reconstruction embedding for surface anomaly detection
2108.07610 (2021-08)
DRAEM -- A discriminatively trained reconstruction embedding for surface anomaly detection
2308.06748 (2023-08)
Target before Shooting: Accurate Anomaly Detection and Localization under One Millisecond via Cascade Patch Retrieval
and 5 more not named here
tokenize_prompt 6 other papers
2 dated earlier, 4 later
2401.06442 (2024-01)
RotationDrag: Point-based Image Editing with Rotated Diffusion Features
2403.06741 (2024-03)
Distribution-Aware Data Expansion with Diffusion Models
2407.10910 (2024-07)
DataDream: Few-shot Guided Dataset Generation
and 3 more not named here
generate_fractal_noise_2d 5 other papers
3 dated earlier, 2 later
Zavrtanik_DRAEM_-_A_Discriminatively_Trained_Reconstruction_Embedding_for_Surface_Anomaly_ICCV_2021_paper (2021 (year only))
DRAEM -A discriminatively trained reconstruction embedding for surface anomaly detection
2108.07610 (2021-08)
DRAEM -- A discriminatively trained reconstruction embedding for surface anomaly detection
2308.06748 (2023-08)
Target before Shooting: Accurate Anomaly Detection and Localization under One Millisecond via Cascade Patch Retrieval
and 2 more not named here
generate_perlin_noise_2d 5 other papers
3 dated earlier, 2 later
Zavrtanik_DRAEM_-_A_Discriminatively_Trained_Reconstruction_Embedding_for_Surface_Anomaly_ICCV_2021_paper (2021 (year only))
DRAEM -A discriminatively trained reconstruction embedding for surface anomaly detection
2108.07610 (2021-08)
DRAEM -- A discriminatively trained reconstruction embedding for surface anomaly detection
2308.06748 (2023-08)
Target before Shooting: Accurate Anomaly Detection and Localization under One Millisecond via Cascade Patch Retrieval
and 2 more not named here

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

Diffusion models have shown superior performance on unsupervised anomaly detection tasks. Since trained with normal data only, diffusion models tend to reconstruct normal counterparts of test images with certain noises added. However, these methods treat all potential anomalies equally, which may cause two main problems. From the global perspective, the difficulty of reconstructing images with different anomalies is uneven. Therefore, instead of utilizing the same setting for all samples, we propose to predict a particular denoising step for each sample by evaluating the difference between image contents and the priors extracted from diffusion models. From the local perspective, reconstructing abnormal regions differs from normal areas even in the same image. Theoretically, the diffusion model predicts a noise for each step, typically following a standard Gaussian distribution. However, due to the difference between the anomaly and its potential normal counterpart, the predicted noise in abnormal regions will inevitably deviate from the standard Gaussian distribution. To this end, we propose introducing synthetic abnormal samples in training to encourage the diffusion models to break through the limitation of standard Gaussian distribution, and a spatial-adaptive feature fusion scheme is utilized during inference. With the above modifications, we propose a global and local adaptive diffusion model (abbreviated to GLAD) for unsupervised anomaly detection, which introduces appealing flexibility and achieves anomaly-free reconstruction while retaining as much normal information as possible. Extensive experiments are conducted on three commonly used anomaly detection datasets (MVTec-AD, MPDD, and VisA) and a printed circuit board dataset (PCB-Bank) we integrated, showing the effectiveness of the proposed method.

For agents

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

get_harvested_code_for_paper("2406.07487")
get_code_for_paper("2406.07487")
have("2406.07487")

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

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

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

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

Connect an agent — have() is free.