SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.04329 · NeurIPS · 2024

Simplified and Generalized Masked Diffusion for Discrete Data

Zhe Wang, Jiaxin Shi, Arnaud Doucet, Michalis Titsias, Kehang Han

arXiv · PDF · Open in the Atlas

Code that ran

6 of 21 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; 4 failures of our instrument; 15 no recorded run), measured 2026-11-22; 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.04329.json · badge: /api/ran/2406.04329.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
google-deepmind/md4 canonical (classifier label)
classifier basis: classifier_2025
6 ran · 15 no recorded run
FunctionStatusWhere it lives
MaskingSchedule Ran
ran on a synthesized input
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("66a81c44aa3c341b")
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 ArrayImpl, 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 math
import jax
import jax.numpy as jnp
import flax.linen as nn

class MaskingSchedule(nn.Module):
    """Masking noise schedule."""
    data_shape: tuple[int, ...]
    schedule_fn_type: str = 'cosine'
    eps: float = 0.0001

    def __call__(self, t):
        return jnp.log(self.alpha(t) / (1.0 - self.alpha(t)))

    def _dalpha(self, t):
        if self.schedule_fn_type == 'cosine':
            return -math.pi / 2.0 * jax.lax.sin(math.pi / 2.0 * (1.0 - t))
        elif self.schedule_fn_type == 'linear':
            return -jnp.ones_like(t)
        elif 'poly' in self.schedule_fn_type:
            exponent = float(self.schedule_fn_type.replace('poly', ''))
            return -exponent * t ** (exponent - 1.0)
        else:
            raise NotImplementedError()

    def dalpha(self, t):
        return (1.0 - 2 * self.eps) * self._dalpha(t)

    def _alpha(self, t):
        if self.schedule_fn_type == 'linear':
            return 1.0 - t
        elif 'poly' in self.schedule_fn_type:
            exponent = float(self.schedule_fn_type.replace('poly', ''))
            return 1.0 - t ** exponent
        elif self.schedule_fn_type == 'cosine':
            return 1.0 - jax.lax.cos(math.pi / 2.0 * (1.0 - t))
        else:
            raise NotImplementedError()

    def alpha(self, t):
        return (1.0 - 2 * self.eps) * self._alpha(t) + self.eps

    def dgamma_times_alpha(self, t):
        return self.dalpha(t) / (1.0 - self.alpha(t))


INIT_ARGS = {
    'data_shape': (2, 4, 3),
    'schedule_fn_type': 'cosine',
    'eps': 0.0001,
}

ARGS = {
    't': jnp.array([0.25, 0.5, 0.75]),
}

if __name__ == '__main__':
    schedule = MaskingSchedule(**INIT_ARGS)
    result = schedule(**ARGS)
    print("Result shape:", result.shape)
    print("Result:", result)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
get_timestep_embedding Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("84db74ee09e0bda4")
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 ArrayImpl, ndim 2, dtype family float, shape (4, 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 jax
import jax.numpy as jnp

# Set seed for reproducibility
jax.config.update('jax_default_prng_impl', 'threefry2x32')

# Create small test inputs
timesteps = jnp.array([0, 1, 2, 3], dtype='int32')
embedding_dim = 4
dtype = 'float32'

ARGS = {
    'timesteps': timesteps,
    'embedding_dim': embedding_dim,
    'dtype': dtype,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, ndim 2, dtype family float, shape (4, 4) — shape (4, 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
jax_unstack Ran
ran; our contract draft was wrong, not the code
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("b6960d9da81c946a")
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 list, ndim 3, dtype family int; 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 jax
import jax.numpy as jnp

# Create a small JAX array with distinct dimensions for testing
x = jnp.arange(24).reshape(2, 3, 4)

# Define ARGS dict with all parameters
ARGS = {
    "x": x,
    "axis": 0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 3, dtype family int — 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
precompute_freqs_cis Ran
ran, honoured the contract we drafted
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("8873a5201399b10b")
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 3, 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 jax.numpy as jnp

# The function precompute_freqs_cis takes three parameters:
# - dim: an integer representing the dimension
# - end: an integer representing the sequence length
# - theta: a float with default value 10000.0

# Looking at the function body:
# - dim is used in arange(0, dim, 2) and dim // 2, so it should be an integer
# - end is used in arange(end), so it should be an integer
# - theta is used in the computation, so it should be a float

# We'll use small values to keep tensors tiny
ARGS = {
    "dim": 4,
    "end": 2,
    "theta": 10000.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 3, 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
repeat_kv Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("4a1c75a9a5f46c4f")
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 ArrayImpl, ndim 4, dtype family float, shape (2, 3, 8, 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 jax.numpy as jnp
import numpy as np

# Create a small JAX array with shape (bs, slen, n_kv_heads, head_dim)
# Using distinct sizes: batch=2, sequence_length=3, n_kv_heads=4, head_dim=5
x = jnp.ones((2, 3, 4, 5))

# n_rep is the repetition factor
n_rep = 2

ARGS = {
    "x": x,
    "n_rep": n_rep,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
jax, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ArrayImpl, ndim 4, dtype family float, shape (2, 3, 8, 5) — shape (2, 3, 8, 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: none by the harness; any seed is in the setup block
reshape_for_broadcast Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("0dc13509bbb03398")
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 3, dtype family float, shape (1, 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

torch.manual_seed(0)

# The function expects:
# - freqs_cis: a tensor with shape (x.shape[1], x.shape[-1])
# - x: a tensor with ndim > 1

# Let's construct x with shape (batch=2, seq_len=3, hidden_dim=4)
# This gives us ndim=3
x = torch.randn(2, 3, 4)

# freqs_cis should have shape (x.shape[1], x.shape[-1]) = (3, 4)
freqs_cis = torch.randn(3, 4)

ARGS = {
    "freqs_cis": freqs_cis,
    "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 3, dtype family float, shape (1, 3, 4) — shape (1, 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
Attention Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("b5d57c4d33c17740")
How it ran

no invocation recorded.

CondEmbedding Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("e341090d86d921b9")
How it ran

no invocation recorded.

DiscreteClassifier Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("b74decb1e729d273")
How it ran

no invocation recorded.

Dropout1d Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("d8f8ff9226830df3")
How it ran

no invocation recorded.

FeedForward Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("170abc34ff9d4f81")
How it ran

no invocation recorded.

MD4 Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("4b01cbf6a3ec21a6")
How it ran

no invocation recorded.

ModelArgs Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("be5a00527b2e82e0")
How it ran

no invocation recorded.

RMSNorm Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("a75e172eea6d85f1")
How it ran

no invocation recorded.

ResBlock Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("2db631aa126ebf6e")
How it ran

no invocation recorded.

SelfAttention Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("daf4ef755a1978a3")
How it ran

no invocation recorded.

Transformer Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("87a69858dd77c308")
How it ran

no invocation recorded.

TransformerBlock Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("7a351fb6b29e26ac")
How it ran

no invocation recorded.

UNet Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("35c08ff52d7e2f6b")
How it ran

no invocation recorded.

UNet5DWrapper Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("a2d820814fa59452")
How it ran

no invocation recorded.

apply_rotary_emb Not yet run
unverified (harvested, no recorded run)
google-deepmind/md4/md4/models/diffusion/md4.py
code served (permissive licence) · get_code("582256db3844c9de")
How it ran

no invocation recorded.

Also present in other papers' code

Of 21 samples lifted from this paper's linked repositories, 21 carry a function identity and 0 do not. Of the 21 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 21 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.

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

Masked (or absorbing) diffusion is actively explored as an alternative to autoregressive models for generative modeling of discrete data. However, existing work in this area has been hindered by unnecessarily complex model formulations and unclear relationships between different perspectives, leading to suboptimal parameterization, training objectives, and ad hoc adjustments to counteract these issues. In this work, we aim to provide a simple and general framework that unlocks the full potential of masked diffusion models. We show that the continuous-time variational objective of masked diffusion models is a simple weighted integral of cross-entropy losses. Our framework also enables training generalized masked diffusion models with state-dependent masking schedules. When evaluated by perplexity, our models trained on OpenWebText surpass prior diffusion language models at GPT-2 scale and demonstrate superior performance on 4 out of 5 zero-shot language modeling tasks. Furthermore, our models vastly outperform previous discrete diffusion models on pixel-level image modeling, achieving 2.75 (CIFAR-10) and 3.40 (ImageNet 64×64) bits per dimension that are better than autoregressive models of similar sizes. Our code is available at https://github.com/google-deepmind/md4.

For agents

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

get_harvested_code_for_paper("2406.04329")
get_code_for_paper("2406.04329")
have("2406.04329")

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

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

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

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

Connect an agent — have() is free.