SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2311.18727 · ICLR · 2024

Automatic Functional Differentiation in JAX

Min Lin

arXiv · PDF · Open in the Atlas

Code that ran

5 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; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 4 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/2311.18727.json · badge: /api/ran/2311.18727.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
sail-sg/autofd canonical (classifier label)
classifier basis: census
5 ran · 4 no recorded run
FunctionStatusWhere it lives
Arg Ran
ran; our contract draft was wrong, not the code
sail-sg/autofd/autofd/general_array.py
code served (permissive licence) · get_code("81105f77efdc61f2")
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 GeneralDim. 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 jax
import jax.numpy as jnp
from jax._src import core as _core

class GeneralDim:
    """GeneralDim class, denotes either the input / output
  of a jaxtyping annotated python function.
  """

    def __init__(self, spec):
        self.spec = spec

    def __eq__(self, other):
        if isinstance(other, GeneralDim):
            return self.spec == other.spec
        else:
            return False

    def __gt__(self, other):
        return True

    def __ge__(self, other):
        return True

    def __repr__(self) -> str:
        return repr(self.spec)

    def __hash__(self) -> str:
        return hash(repr(self.spec))

    def evaluate(self, env):
        return self

    def dimension_as_value(self) -> int:
        pass

    def to_shaped_array(self):
        return jax.tree.map(lambda s: _core.ShapedArray(s.shape, dtype=s.dtype), self.spec)

def Arg(spec):
    return GeneralDim(spec)


class MockSpec:
    """Stand-in spec object with shape and dtype attributes."""
    def __init__(self, shape, dtype):
        self.shape = shape
        self.dtype = dtype


spec_obj = MockSpec(shape=(2, 4), dtype=jnp.float32)

ARGS = {
    "spec": spec_obj
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type GeneralDim — a GeneralDim output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a GeneralDim 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
Ret Ran
ran; our contract draft was wrong, not the code
sail-sg/autofd/autofd/general_array.py
code served (permissive licence) · get_code("544de4237a1f63c3")
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 GeneralDim. 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 jax
import jax.numpy as jnp
from jax._src import core as _core

# Create a simple spec - a mock object with shape and dtype attributes
class MockSpec:
    def __init__(self, shape, dtype):
        self.shape = shape
        self.dtype = dtype

# Create test spec objects
spec1 = MockSpec(shape=(2, 4), dtype=jnp.float32)
spec2 = MockSpec(shape=(3, 5), dtype=jnp.int32)

# ARGS dict mapping all parameters of Ret function
ARGS = {
    "spec": spec1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type GeneralDim — a GeneralDim output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a GeneralDim 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
complement_argnums Ran
ran, honoured the contract we drafted
sail-sg/autofd/autofd/utils.py
code served (permissive licence) · get_code("6ca86d5d7a6a9e4a")
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 tuple, ndim 1, 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 torch

torch.manual_seed(0)

# The function complement_argnums takes:
# - argnums: either an int or a tuple of ints representing argument indices
# - num_args: an int representing the total number of arguments

# Looking at the function body:
# - argnums can be an int or tuple of ints
# - num_args should be an int greater than or equal to max(argnums) + 1
# - The function returns a tuple of indices NOT in argnums

# Test case 1: argnums as int, num_args larger than it
argnums_value = 2
num_args_value = 5

ARGS = {
    "argnums": argnums_value,
    "num_args": num_args_value
}
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 tuple, ndim 1, dtype family int — 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
visualize_jaxpr Ran
ran; our contract draft was wrong, not the code
sail-sg/autofd/autofd/utils.py
code served (permissive licence) · get_code("5189d887912d9b47")
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 function. 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 jax
import jax.numpy as jnp
from jax import core

# Create a simple function to pass to the decorator
def simple_fn(x, y):
    return x + y

# Create another test function with multiple operations
def complex_fn(x):
    return jnp.sin(x) * jnp.cos(x)

# Test inputs for simple_fn
test_x = jnp.array([1.0, 2.0, 3.0, 4.0])
test_y = jnp.array([5.0, 6.0, 7.0, 8.0])

# Test input for complex_fn
test_z = jnp.array([0.1, 0.2, 0.3, 0.4])

ARGS = {
    'fn': simple_fn
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
graphviz, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
weak_lru Ran
ran; our contract draft was wrong, not the code
sail-sg/autofd/autofd/utils.py
code served (permissive licence) · get_code("e74ecb2cffb1cd39")
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 function. 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 weakref
from functools import lru_cache, wraps

# First, let's understand what weak_lru does:
# - It's a decorator factory that takes maxsize and typed parameters
# - It wraps a method that takes self as first argument
# - It uses weakref.ref(self) to avoid keeping strong references
# - The decorated function should work with self, *args, **kwargs

# Create a test class to demonstrate the decorator
class TestClass:
    def __init__(self, value):
        self.value = value
    
    @staticmethod
    def weak_lru(maxsize=128, typed=False):
        '''LRU Cache decorator that keeps a weak reference to "self"'''
        def wrapper(func):
            @lru_cache(maxsize, typed)
            def _func(_self, *args, **kwargs):
                return func(_self(), *args, **kwargs)
            
            @wraps(func)
            def inner(self, *args, **kwargs):
                return _func(weakref.ref(self), *args, **kwargs)
            return inner
        return wrapper
    
    @weak_lru(maxsize=128, typed=False)
    def compute(self, x, y=10):
        return self.value + x + y

# Test instantiation
torch.manual_seed(0)
test_obj = TestClass(value=5)

# The function weak_lru takes these parameters:
# - maxsize: int (default 128) - max cache size
# - typed: bool (default False) - whether to cache separately for different types

ARGS = {
    'maxsize': 128,
    'typed': 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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
compose Not yet run
unverified (harvested, no recorded run)
sail-sg/autofd/autofd/operators/transforms.py
code served (permissive licence) · get_code("f12c821c31198760")
How it ran

no invocation recorded.

permute_args Not yet run
unverified (harvested, no recorded run)
sail-sg/autofd/autofd/operators/operators.py
code served (permissive licence) · get_code("fedce67ab6d305e9")
How it ran

no invocation recorded.

permute_args Not yet run
unverified (harvested, no recorded run)
sail-sg/autofd/autofd/operators/transforms.py
code served (permissive licence) · get_code("34126dfb9cb22ec4")
How it ran

no invocation recorded.

return_at Not yet run
unverified (harvested, no recorded run)
sail-sg/autofd/autofd/operators/transforms.py
code served (permissive licence) · get_code("3cbf274470b38c2a")
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, 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 9 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-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

We extend JAX with the capability to automatically differentiate higher-order functions (functionals and operators). By representing functions as a generalization of arrays, we seamlessly use JAX's existing primitive system to implement higher-order functions. We present a set of primitive operators that serve as foundational building blocks for constructing several key types of functionals. For every introduced primitive operator, we derive and implement both linearization and transposition rules, aligning with JAX's internal protocols for forward and reverse mode automatic differentiation. This enhancement allows for functional differentiation in the same syntax traditionally use for functions. The resulting functional gradients are themselves functions ready to be invoked in python.

For agents

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

get_harvested_code_for_paper("2311.18727")
get_code_for_paper("2311.18727")
have("2311.18727")

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

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

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

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

Connect an agent — have() is free.