SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2310.12474 · ICLR · 2024

Enhancing High-Resolution 3D Generation through Pixel-wise Gradient Clipping

Jiachen Lu, Xiatian Zhu, Li Zhang, Zijie Pan

arXiv · PDF · Open in the Atlas

Code that ran

3 of 9 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; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 6 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/2310.12474.json · badge: /api/ran/2310.12474.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
fudan-zvg/pgc-3d marked official in Papers with Code
Papers with Code archive
3 ran · 6 no recorded run
FunctionStatusWhere it lives
CrossAttention Ran
ran on a synthesized input
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("93dcd06df2fc1896")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 5, 12) 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
from einops import repeat, rearrange
from inspect import isfunction
from torch import einsum

def default(val, d):
    if val is not None:
        return val
    return d() if isfunction(d) else d

def exists(val):
    return val is not None

class CrossAttention(nn.Module):

    def __init__(self, query_dim, context_dim=None, heads=8, dim_head=64, dropout=0.0):
        super().__init__()
        inner_dim = dim_head * heads
        context_dim = default(context_dim, query_dim)
        self.scale = dim_head ** (-0.5)
        self.heads = heads
        self.to_q = nn.Linear(query_dim, inner_dim, bias=False)
        self.to_k = nn.Linear(context_dim, inner_dim, bias=False)
        self.to_v = nn.Linear(context_dim, inner_dim, bias=False)
        self.to_out = nn.Sequential(nn.Linear(inner_dim, query_dim), nn.Dropout(dropout))

    def forward(self, x, context=None, mask=None):
        h = self.heads
        q = self.to_q(x)
        context = default(context, x)
        k = self.to_k(context)
        v = self.to_v(context)
        q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> (b h) n d', h=h), (q, k, v))
        sim = einsum('b i d, b j d -> b i j', q, k) * self.scale
        if exists(mask):
            mask = rearrange(mask, 'b ... -> b (...)')
            max_neg_value = -torch.finfo(sim.dtype).max
            mask = repeat(mask, 'b j -> (b h) () j', h=h)
            sim.masked_fill_(~mask, max_neg_value)
        attn = sim.softmax(dim=-1)
        out = einsum('b i j, b j d -> b i d', attn, v)
        out = rearrange(out, '(b h) n d -> b n (h d)', h=h)
        return self.to_out(out)

INIT_ARGS = {
    'query_dim': 12,
    'context_dim': 16,
    'heads': 2,
    'dim_head': 6,
    'dropout': 0.1,
}

ARGS = {
    'x': torch.randn(2, 5, 12),
    'context': torch.randn(2, 7, 16),
    'mask': torch.ones(2, 7, dtype=torch.bool),
}

if __name__ == '__main__':
    model = CrossAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 5, 12)")
    assert output.shape == (2, 5, 12), f"Shape mismatch: {output.shape}"
    print("Test passed!")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, 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, 5, 12) — shape (2, 5, 12) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
QKVAttention Ran
ran on a synthesized input
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("db5d8eda94db8878")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 4, 5) 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 math
import numpy as np
import torch as th
import torch.nn as nn

def count_flops_attn(model, _x, y):
    """
    A counter for the `thop` package to count the operations in an
    attention operation.
    Meant to be used like:
        macs, params = thop.profile(
            model,
            inputs=(inputs, timestamps),
            custom_ops={QKVAttention: QKVAttention.count_flops},
        )
    """
    b, c, *spatial = y[0].shape
    num_spatial = int(np.prod(spatial))
    matmul_ops = 2 * b * num_spatial ** 2 * c
    model.total_ops += th.DoubleTensor([matmul_ops])

class QKVAttention(nn.Module):
    """
    A module which performs QKV attention and splits in a different order.
    """

    def __init__(self, n_heads):
        super().__init__()
        self.n_heads = n_heads

    def forward(self, qkv):
        """
        Apply QKV attention.
        :param qkv: an [N x (3 * H * C) x T] tensor of Qs, Ks, and Vs.
        :return: an [N x (H * C) x T] tensor after attention.
        """
        bs, width, length = qkv.shape
        assert width % (3 * self.n_heads) == 0
        ch = width // (3 * self.n_heads)
        q, k, v = qkv.chunk(3, dim=1)
        scale = 1 / math.sqrt(math.sqrt(ch))
        weight = th.einsum('bct,bcs->bts', (q * scale).view(bs * self.n_heads, ch, length), (k * scale).view(bs * self.n_heads, ch, length))
        weight = th.softmax(weight.float(), dim=-1).type(weight.dtype)
        a = th.einsum('bts,bcs->bct', weight, v.reshape(bs * self.n_heads, ch, length))
        return a.reshape(bs, -1, length)

    @staticmethod
    def count_flops(model, _x, y):
        return count_flops_attn(model, _x, y)


INIT_ARGS = {
    'n_heads': 2,
}

ARGS = {
    'qkv': th.randn(2, 12, 5),
}

if __name__ == '__main__':
    model = QKVAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, 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, 4, 5) — shape (2, 4, 5) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
QKVAttentionLegacy Ran
ran on a synthesized input
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("d1535f9d0cc44355")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 8, 8) 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 math
import numpy as np
import torch as th
import torch.nn as nn

def count_flops_attn(model, _x, y):
    """
    A counter for the `thop` package to count the operations in an
    attention operation.
    Meant to be used like:
        macs, params = thop.profile(
            model,
            inputs=(inputs, timestamps),
            custom_ops={QKVAttention: QKVAttention.count_flops},
        )
    """
    b, c, *spatial = y[0].shape
    num_spatial = int(np.prod(spatial))
    matmul_ops = 2 * b * num_spatial ** 2 * c
    model.total_ops += th.DoubleTensor([matmul_ops])

class QKVAttentionLegacy(nn.Module):
    """
    A module which performs QKV attention. Matches legacy QKVAttention + input/output heads shaping
    """

    def __init__(self, n_heads):
        super().__init__()
        self.n_heads = n_heads

    def forward(self, qkv):
        """
        Apply QKV attention.
        :param qkv: an [N x (H * 3 * C) x T] tensor of Qs, Ks, and Vs.
        :return: an [N x (H * C) x T] tensor after attention.
        """
        bs, width, length = qkv.shape
        assert width % (3 * self.n_heads) == 0
        ch = width // (3 * self.n_heads)
        q, k, v = qkv.reshape(bs * self.n_heads, ch * 3, length).split(ch, dim=1)
        scale = 1 / math.sqrt(math.sqrt(ch))
        weight = th.einsum('bct,bcs->bts', q * scale, k * scale)
        weight = th.softmax(weight.float(), dim=-1).type(weight.dtype)
        a = th.einsum('bts,bcs->bct', weight, v)
        return a.reshape(bs, -1, length)

    @staticmethod
    def count_flops(model, _x, y):
        return count_flops_attn(model, _x, y)


INIT_ARGS = {
    'n_heads': 2,
}

ARGS = {
    'qkv': th.randn(2, 24, 8),
}

if __name__ == '__main__':
    model = QKVAttentionLegacy(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, 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, 8, 8) — shape (2, 8, 8) 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
AttentionBlock Not yet run
unverified (harvested, no recorded run)
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("d9fb5e776204ff16")
How it ran

no invocation recorded.

BasicTransformerBlock Not yet run
unverified (harvested, no recorded run)
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("ddc045dc2824caf3")
How it ran

no invocation recorded.

ResBlock Not yet run
unverified (harvested, no recorded run)
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("dd36a5c7a3b8451c")
How it ran

no invocation recorded.

SpatialTransformer Not yet run
unverified (harvested, no recorded run)
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("1967b733828c7686")
How it ran

no invocation recorded.

TimestepEmbedSequential Not yet run
unverified (harvested, no recorded run)
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("52958f7c2c3d2f92")
How it ran

no invocation recorded.

UNetModel Not yet run
unverified (harvested, no recorded run)
fudan-zvg/pgc-3d/ldm/modules/diffusionmodules/openaimodel.py
code served (permissive licence) · get_code("ac7c0c0e36a9cb38")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 6 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 0 the same month, 6 later) and 3 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
QKVAttention
brick of this paper's assembly: model
17 other papers
11 dated earlier, 6 later · 7 only as an assembly brick
2006.11239 (2020-06)
Denoising Diffusion Probabilistic Models
2209.15264 (2022-09)
Diffusion-based Image Translation using Disentangled Style and Content Representation
2301.05225 (2023-01)
Domain Expansion of Image Generators
and 14 more not named here
QKVAttentionLegacy
brick of this paper's assembly: helper
15 other papers
10 dated earlier, 5 later · 6 only as an assembly brick
2006.11239 (2020-06)
Denoising Diffusion Probabilistic Models
2209.15264 (2022-09)
Diffusion-based Image Translation using Disentangled Style and Content Representation
2301.05225 (2023-01)
Domain Expansion of Image Generators
and 12 more not named here
AttentionBlock
brick of this paper's assembly: model
12 other papers
7 dated earlier, 5 later · 2 only as an assembly brick
2209.15264 (2022-09)
Diffusion-based Image Translation using Disentangled Style and Content Representation
2301.05225 (2023-01)
Domain Expansion of Image Generators
2302.04304 (2023-02)
Q-Diffusion: Quantizing Diffusion Models
and 9 more not named here
ResBlock
brick of this paper's assembly: model
11 other papers
7 dated earlier, 4 later · 4 only as an assembly brick
2209.15264 (2022-09)
Diffusion-based Image Translation using Disentangled Style and Content Representation
2301.05225 (2023-01)
Domain Expansion of Image Generators
2302.07685 (2023-02)
Video Probabilistic Diffusion Models in Projected Latent Space
and 8 more not named here
TimestepEmbedSequential
brick of this paper's assembly: helper
8 other papers
4 dated earlier, 4 later
2301.05225 (2023-01)
Domain Expansion of Image Generators
2302.07685 (2023-02)
Video Probabilistic Diffusion Models in Projected Latent Space
2304.02012 (2023-04)
EGC: Image Generation and Classification via a Diffusion Energy-Based Model
and 5 more not named here
CrossAttention
brick of this paper's assembly: helper
7 other papers
3 dated earlier, 4 later · 1 only as an assembly brick
2208.01626 (2022-08)
Prompt-to-Prompt Image Editing with Cross Attention Control
2211.05556 (2022-11)
Generating astronomical spectra from photometry with conditional diffusion models
2304.02012 (2023-04)
EGC: Image Generation and Classification via a Diffusion Energy-Based Model
and 4 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

Published as a conference paper at ICLR 2024 ulated gradients adversely affect the 3D model's capacity in acquiring texturerelated information from the image generative model, leading to poor quality appearance synthesis. To address this overarching challenge, we propose an innovative operation termed Pixel-wise Gradient Clipping (PGC) designed for seamless integration into existing 3D generative models, thereby enhancing their synthesis quality. Specifically, we control the magnitude of stochastic gradients by clipping the pixel-wise gradients efficiently, while preserving crucial texture-related gradient directions. Despite this simplicity and minimal extra cost, extensive experiments demonstrate the efficacy of our PGC in enhancing the performance of existing 3D generative models for high-resolution object rendering.

For agents

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

get_harvested_code_for_paper("2310.12474")
get_code_for_paper("2310.12474")
have("2310.12474")

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

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

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

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

Connect an agent — have() is free.