SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2412.17619 · 2024

Kernel-Aware Graph Prompt Learning for Few-Shot Anomaly Detection

arXiv · PDF · Open in the Atlas

Code that ran

10 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 1 has no contract verdict; 8 failures of our instrument; 1 no recorded run), measured 2026-11-23; 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.17619.json · badge: /api/ran/2412.17619.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
cvl-hub/kag-prompt canonical (classifier label)
classifier basis not recorded on the link
10 ran · 1 no recorded run
FunctionStatusWhere it lives
apply_rotary_pos_emb Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
cvl-hub/kag-prompt/code/model/modeling_llama.py
code served (permissive licence) · get_code("9b4dff79d5e6102c")
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 tuple, ndim 5, 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

torch.manual_seed(0)

# Analyze the function to understand tensor shapes:
# q, k: used in element-wise operations with cos, sin
# cos, sin: gathered using position_ids, shape [batch, heads, seq_len, dim]
# position_ids: shape [batch, seq_len], used to gather from cos/sin at dim 2

batch_size = 2
num_heads = 3
seq_len = 4
head_dim = 4

# q and k: [batch, heads, seq_len, head_dim]
q = torch.randn(batch_size, num_heads, seq_len, head_dim)
k = torch.randn(batch_size, num_heads, seq_len, head_dim)

# cos and sin: [1, heads, seq_len, head_dim] (will be repeated to batch_size)
cos = torch.randn(1, num_heads, seq_len, head_dim)
sin = torch.randn(1, num_heads, seq_len, head_dim)

# position_ids: [batch, seq_len] with values in range [0, seq_len)
position_ids = torch.tensor([
    [0, 1, 2, 3],
    [0, 1, 2, 3]
], dtype=torch.long)

ARGS = {
    "q": q,
    "k": k,
    "cos": cos,
    "sin": sin,
    "position_ids": position_ids,
}
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 tuple, ndim 5, dtype family float — a tuple 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
cal_pro_score Ran
ran on a synthesized input
cvl-hub/kag-prompt/code/metrics.py
code served (permissive licence) · get_code("02ba2a3a7554f4c1")
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 float, 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 numpy as np

# Create small test arrays
# masks: binary masks indicating anomaly regions, shape (batch, height, width)
# amaps: anomaly maps with continuous values, shape (batch, height, width)

np.random.seed(0)

# Create masks (binary, indicating ground truth anomaly regions)
masks = np.random.randint(0, 2, size=(2, 4, 5)).astype(np.float32)

# Create amaps (continuous anomaly scores)
amaps = np.random.rand(2, 4, 5).astype(np.float32)

ARGS = {
    "masks": masks,
    "amaps": amaps,
    "max_step": 200,
    "expect_fpr": 0.3,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, skimage, sklearn — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, 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
find_contours Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
cvl-hub/kag-prompt/code/datasets/all_supervised_with_cn.py
pointer only (licence: MIT); the stored copy get_code serves, from casia-iva-lab/anomalygpt, is pointer only (licence: NOASSERTION) · get_code("f3e7a5a2f243754f")
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 casia-iva-lab/anomalygpt, and GitHub could not classify the licence of that repository (NOASSERTION). 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.

find_first_file_in_directory Ran
ran; our contract draft was wrong, not the code
cvl-hub/kag-prompt/code/model/openllama.py
pointer only (licence: MIT); the stored copy get_code serves, from tzjtatata/myriad, is pointer only (licence: NONE) · get_code("b902e006ef57cdcb")
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 tzjtatata/myriad, 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_fractal_noise_2d Ran
ran; our contract draft was wrong, not the code
cvl-hub/kag-prompt/code/datasets/perlin.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
cvl-hub/kag-prompt/code/datasets/perlin.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.

get_class_name Ran
ran; our contract draft was wrong, not the code
cvl-hub/kag-prompt/code/datasets/all_supervised_with_cn.py
pointer only (licence: MIT); the stored copy get_code serves, from casia-iva-lab/anomalygpt, is pointer only (licence: NOASSERTION) · get_code("565be006d0d7d202")
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 casia-iva-lab/anomalygpt, and GitHub could not classify the licence of that repository (NOASSERTION). 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_class_name_cn Ran
ran; our contract draft was wrong, not the code
cvl-hub/kag-prompt/code/datasets/all_supervised_with_cn.py
pointer only (licence: MIT); the stored copy get_code serves, from casia-iva-lab/anomalygpt, is pointer only (licence: NOASSERTION) · get_code("f6cfd32b2ad4e94b")
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 casia-iva-lab/anomalygpt, and GitHub could not classify the licence of that repository (NOASSERTION). 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
cvl-hub/kag-prompt/code/datasets/perlin.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.

rotate_half Ran
ran; our contract draft was wrong, not the code
cvl-hub/kag-prompt/code/model/modeling_llama.py
code served (permissive licence) · get_code("b99eea6376d1e212")
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 2, dtype family float, shape (2, 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

torch.manual_seed(0)

# The function rotate_half takes a single parameter 'x' which is a tensor
# It accesses x.shape[-1] to get the last dimension
# It uses indexing with [..., :] slicing notation
# It calls torch.cat() to concatenate tensors

# Create a small tensor with shape (2, 4) - batch size 2, hidden dim 4
x = torch.randn(2, 4)

ARGS = {
    "x": x
}
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 2, dtype family float, shape (2, 4) — shape (2, 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
encode_text_with_prompt_ensemble Not yet run
unverified (harvested, no recorded run)
cvl-hub/kag-prompt/code/model/openllama.py
pointer only (licence: MIT); the stored copy get_code serves, from tzjtatata/myriad, is pointer only (licence: NONE) · get_code("b7db790f54abfb17")
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 tzjtatata/myriad, 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. 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, 10 are also present in other papers whose code we hold (10 with at least one paper dated earlier, 1 the same month, 3 later) and 1 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
rotate_half 360 other papers
217 dated earlier, 10 the same month, 124 later, 6 same year, order not determinable, 3 undated · 30 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2203.08913 (2022-03)
Memorizing Transformers
2302.13971 (2023-02)
LLaMA: Open and Efficient Foundation Language Models
and 357 more not named here
apply_rotary_pos_emb 47 other papers
40 dated earlier, 4 later, 3 same year, order not determinable
2305.14167 (2023-05)
DetGPT: Detect What You Need via Reasoning
2305.16103 (2023-05)
ChatBridge: Bridging Modalities with Large Language Model as a Language Catalyst
2305.16355 (2023-05)
PandaGPT: One Model To Instruction-Follow Them All
and 44 more not named here
lerp_np 8 other papers
7 dated earlier, 1 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
generate_fractal_noise_2d 5 other papers
5 dated earlier
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
5 dated earlier
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
encode_text_with_prompt_ensemble 2 other papers
2 dated earlier
2308.15366 (2023-08)
AnomalyGPT: Detecting Industrial Anomalies Using Large Vision-Language Models
2310.19070 (2023-10)
Myriad: Large Multimodal Model by Applying Vision Experts for Industrial Anomaly Detection
find_contours 1 other paper
1 dated earlier
2308.15366 (2023-08)
AnomalyGPT: Detecting Industrial Anomalies Using Large Vision-Language Models
find_first_file_in_directory 1 other paper
1 dated earlier
2310.19070 (2023-10)
Myriad: Large Multimodal Model by Applying Vision Experts for Industrial Anomaly Detection
get_class_name 1 other paper
1 dated earlier
2308.15366 (2023-08)
AnomalyGPT: Detecting Industrial Anomalies Using Large Vision-Language Models
get_class_name_cn 1 other paper
1 dated earlier
2308.15366 (2023-08)
AnomalyGPT: Detecting Industrial Anomalies Using Large Vision-Language Models

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-23.

Repositories linked to this paper

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

Abstract

Few-shot anomaly detection (FSAD) aims to detect unseen anomaly regions with the guidance of very few normal support images from the same class. Existing FSAD methods usually find anomalies by directly designing complex text prompts to align them with visual features under the prevailing large vision-language model paradigm. However, these methods, almost always, neglect intrinsic contextual information in visual features, e.g., the interaction relationships between different vision layers, which is an important clue for detecting anomalies comprehensively. To this end, we propose a kernel-aware graph prompt learning framework, termed as KAG-prompt, by reasoning the cross-layer relations among visual features for FSAD. Specifically, a kernel-aware hierarchical graph is built by taking the different layer features focusing on anomalous regions of different sizes as nodes, meanwhile, the relationships between arbitrary pairs of nodes stand for the edges of the graph. By message passing over this graph, KAG-prompt can capture cross-layer contextual information, thus leading to more accurate anomaly prediction. Moreover, to integrate the information of multiple important anomaly signals in the prediction map, we propose a novel image-level scoring method based on multi-level information fusion. Extensive experiments on MVTecAD and VisA datasets show that KAG-prompt achieves state-of-the-art FSAD results for image-level/pixel-level anomaly detection. Code is available at https://github.com/CVL-hub/KAG-prompt.git.

For agents

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

get_harvested_code_for_paper("2412.17619")
get_code_for_paper("2412.17619")
have("2412.17619")

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

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

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

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

Connect an agent — have() is free.