SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2110.15072 · NeurIPS · 2021

Leveraging Recursive Gumbel-Max Trick for Approximate Inference in Combinatorial Spaces

Dmitry Vetrov, Kirill Struminsky, Artyom Gadetsky, Denis Rakitin, Karpushkin Danil

arXiv · PDF · Open in the Atlas

Code that ran

9 of 10 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 9 have no contract verdict; 0 failures of our instrument; 1 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/2110.15072.json · badge: /api/ran/2110.15072.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
RakitinDen/pytorch-recursive-gumbel-max-trick canonical (classifier label)
classifier basis not recorded on the link
9 ran · 1 no recorded run
FunctionStatusWhere it lives
E_reinforce Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/estimators.py
code served (permissive licence) · get_code("991472e4dbd1145d")
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 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
import torch.nn as nn

torch.manual_seed(0)

# Analyze the function signature and body:
# - loss_value: tensor, detached and used with unsqueeze for broadcasting
# - logits: tensor, shape used to determine batch_size and ndimension
# - exp: tensor, detached and used in log/exp computation
# - plus_samples: int, defaults to 1
# - mask_unused_values: optional callable that takes log_prob and **kwargs
# - **kwargs: passed to mask_unused_values

# Set up basic dimensions
batch_size = 2
plus_samples = 1
logits_dim = 4

# Create loss_value: shape (batch_size * plus_samples,)
loss_value = torch.randn(batch_size * plus_samples)

# Create logits: shape (batch_size * plus_samples, logits_dim)
logits = torch.randn(batch_size * plus_samples, logits_dim, requires_grad=True)

# Create exp: shape matching logits
exp = torch.exp(torch.randn(batch_size * plus_samples, logits_dim))

# Create mask_unused_values: a callable that processes log_prob
def mask_unused_values(log_prob, **kwargs):
    # Simple pass-through masking function
    return log_prob

ARGS = {
    "loss_value": loss_value,
    "logits": logits,
    "exp": exp,
    "plus_samples": plus_samples,
    "mask_unused_values": mask_unused_values,
}
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 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
arb_mask_unused_values Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/arborescence/utils.py
code served (permissive licence) · get_code("e624124dad9508c4")
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, 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 torch

torch.manual_seed(0)

# Construct a small batch of values tensors (batch_size=2, dim=4)
values = torch.randn(2, 4, 4)

# Define root node index
root = 0

# Define lengths for graphs in batch (both graphs have full dimension)
lengths = torch.tensor([4, 4])

# Map all parameters
ARGS = {
    "values": values,
    "root": root,
    "lengths": lengths,
}
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, 4, 4) — shape (2, 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
bin_tree_log_prob Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/binary_tree/functions.py
code served (permissive licence) · get_code("d476d67388e3ef41")
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 1, dtype family float, shape (2,) 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)

class BinaryTree:
    """Stand-in BinaryTree class with masks attribute"""
    def __init__(self, masks):
        self.masks = masks

batch_size = 2
dim = 4

logits = torch.randn(batch_size, dim)

masks = torch.randn(batch_size, dim, dim)

struct_var = BinaryTree(masks=masks)

ARGS = {
    "struct_var": struct_var,
    "logits": logits,
}
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 1, dtype family float, shape (2,) — shape (2,) 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
bin_tree_mask_unused_values Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/binary_tree/utils.py
code served (permissive licence) · get_code("ca8b8c5f518da92f")
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 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)

# Construct arguments for bin_tree_mask_unused_values
batch_size = 2
dim = 4

# values: torch.Tensor of shape [batch_size x dim]
values = torch.randn(batch_size, dim)

# lengths: torch.Tensor of shape [batch_size]
# Each element indicates how many elements in the corresponding batch are valid
lengths = torch.tensor([3, 2])

ARGS = {
    "values": values,
    "lengths": lengths,
}
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 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
build_tree Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/binary_tree/utils.py
code served (permissive licence) · get_code("7c52becd20da3056")
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 Node. 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 numpy as np

class Node:
    def __init__(self, value=None):
        self.value = value
        self.left = None
        self.right = None
        self.depth = None

torch.manual_seed(0)

# Set up small tensors with distinct dimensions
batch_size = 2
dim = 4

# exp: batch_size x dim tensor containing values to find minimum from
exp = torch.tensor([
    [5.0, 2.0, 8.0, 1.0],
    [3.0, 7.0, 1.0, 4.0]
])

# masks: batch_size x dim x dim tensor
masks = torch.ones(batch_size, dim, dim)

# heights: batch_size tensor
heights = torch.zeros(batch_size, dtype=torch.long)

# Parameters for a single batch element
batch_idx = 0
left = 0
right = dim
level = 0

ARGS = {
    "batch_idx": batch_idx,
    "exp": exp,
    "left": left,
    "right": right,
    "level": level,
    "masks": masks,
    "heights": heights
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Node — a Node output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Node 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
expand_mask Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/arborescence/utils.py
code served (permissive licence) · get_code("ca07a89fcbf4abf8")
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, 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 torch

torch.manual_seed(0)

# Analyze the function:
# - expand_mask takes a single parameter 'mask'
# - mask is used with bitwise NOT (~) operator, so it must be a boolean tensor
# - mask is indexed as mask[:, None, :] and mask[:, :, None]
# - This suggests mask is a 3D boolean tensor or can be treated as 2D
# - The operation performs: ~mask (bitwise NOT) and then multiplies along different axes
# - Result: mask[:, None, :] * out[:, :, None] where out = ~mask
# - This is a broadcasting operation between shapes (batch, 1, dim) and (batch, dim, 1)

# Create a small boolean tensor with shape (batch=2, dim=4)
mask = torch.tensor([
    [True, False, True, False],
    [False, True, False, True]
], dtype=torch.bool)

ARGS = {
    "mask": mask
}
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, 4, 4) — shape (2, 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
matching_log_prob Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/matching/functions.py
code served (permissive licence) · get_code("f62fb7898212df4f")
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 1, dtype family float, shape (2,) 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 a stand-in Matching class that mimics the expected structure
class Matching:
    def __init__(self, matching_tensor, mask_tensor):
        self.matching = matching_tensor
        self.trace = {'mask': mask_tensor}

# Set up dimensions: batch_size=2, dim=4
batch_size = 2
dim = 4

# Create logits tensor: batch_size x dim x dim
logits = torch.randn(batch_size, dim, dim)

# Create matching tensor: batch_size x dim x dim (binary mask for perfect matching)
matching = torch.zeros(batch_size, dim, dim)
# Set some entries to 1 to represent the matching
matching[0, 0, 1] = 1
matching[0, 1, 2] = 1
matching[0, 2, 3] = 1
matching[0, 3, 0] = 1
matching[1, 0, 2] = 1
matching[1, 1, 3] = 1
matching[1, 2, 0] = 1
matching[1, 3, 1] = 1

# Create mask tensor: batch_size x 1 x dim x dim
# This is used in the logsumexp call with None indexing
mask = torch.zeros(batch_size, 1, dim, dim)
mask[:, :, :, :] = float('-inf')
for i in range(batch_size):
    for j in range(dim):
        mask[i, 0, j, (j + 1) % dim] = 0

# Create the struct_var object
struct_var = Matching(matching, mask)

ARGS = {
    'struct_var': struct_var,
    'logits': logits,
}
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 1, dtype family float, shape (2,) — shape (2,) 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
reattach_exp_to_new_logits Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/estimators.py
code served (permissive licence) · get_code("a48be52c9f177d0b")
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 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)

# Create small tensors for the function
# logits: tensor that will be used in arithmetic operations
logits = torch.randn(2, 4, requires_grad=True)

# exp: tensor that will be transformed
# It should be a positive tensor since we take log of its detached version
exp = torch.exp(torch.randn(2, 4))

ARGS = {
    "logits": logits,
    "exp": exp,
}
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 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
uniform_to_exp Ran
ran on a synthesized input
RakitinDen/pytorch-recursive-gumbel-max-trick/estimators.py
code served (permissive licence) · get_code("e6843d775acab6e8")
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 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)

# Create a small logits tensor (log-means of exponential distributions)
logits = torch.randn(2, 4)

# Create a uniform tensor with same shape as logits
# clamp_probs will ensure values are in valid range
uniform = torch.rand(2, 4)

# Define ARGS dict with all parameters
ARGS = {
    "logits": logits,
    "uniform": uniform,
    "enable_grad": False
}
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 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
calc_trace_log_prob Not yet run
unverified (harvested, no recorded run)
RakitinDen/pytorch-recursive-gumbel-max-trick/arborescence/utils.py
code served (permissive licence) · get_code("b6a193a098c58bcf")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 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 10 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

Structured latent variables allow incorporating meaningful prior knowledge into deep learning models. However, learning with such variables remains challenging because of their discrete nature. Nowadays, the standard learning approach is to define a latent variable as a perturbed algorithm output and to use a differentiable surrogate for training. In general, the surrogate puts additional constraints on the model and inevitably leads to biased gradients. To alleviate these shortcomings, we extend the Gumbel-Max trick to define distributions over structured domains. We avoid the differentiable surrogates by leveraging the score function estimators for optimization. In particular, we highlight a family of recursive algorithms with a common feature we call stochastic invariant. The feature allows us to construct reliable gradient estimates and control variates without additional constraints on the model. In our experiments, we consider various structured latent variable models and achieve results competitive with relaxation-based counterparts.

For agents

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

get_harvested_code_for_paper("2110.15072")
get_code_for_paper("2110.15072")
have("2110.15072")

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

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

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

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

Connect an agent — have() is free.