SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2211.15841 · 2022

MegaBlocks: Efficient Sparse Training with Mixture-of-Experts

arXiv · PDF · Open in the Atlas

Code that ran

5 of 6 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 4 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/2211.15841.json · badge: /api/ran/2211.15841.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
stanford-futuredata/megablocks canonical (classifier label)
classifier basis: plan_row
3 ran · 1 no recorded run
stanford-futuredata/stk community (classifier label)
classifier basis not recorded on the link
2 ran · 0 no recorded run
FunctionStatusWhere it lives
all_to_all Ran
ran on a synthesized input
stanford-futuredata/megablocks/megablocks/layers/all_to_all.py
code served (permissive licence) · get_code("ff4365d4474af465")
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. 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 torch.distributed as dist

torch.manual_seed(0)

# Initialize a minimal distributed process group for CPU
# We need to set up distributed backend
import os
os.environ['MASTER_ADDR'] = 'localhost'
os.environ['MASTER_PORT'] = '29500'

# Initialize the default process group with gloo backend (CPU-compatible)
try:
    dist.init_process_group(backend='gloo', rank=0, world_size=1)
except RuntimeError:
    # Already initialized or running in non-distributed context
    pass

# Create tensors for all_to_all
# x shape: (total_size, feature_dim)
# The function splits x according to input_split_sizes
x = torch.randn(6, 4)  # 6 elements total, 4 feature dimensions

# output_split_sizes: how to split the output across ranks
# For a single rank setup, this is just the total size
output_split_sizes = [6]

# input_split_sizes: how to split the input across ranks
# For a single rank setup, this is just the total size
input_split_sizes = [6]

# group: the process group for communication
group = dist.GroupMember.WORLD

# async_op: whether to use asynchronous operation
async_op = False

ARGS = {
    'x': x,
    'output_split_sizes': output_split_sizes,
    'input_split_sizes': input_split_sizes,
    'group': group,
    'async_op': async_op,
}
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 — a tuple output has no array shape of its own; none is 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
custom_bwd Ran
ran on a synthesized input
stanford-futuredata/stk/stk/backend/autocast.py
code served (permissive licence) · get_code("f7f77603a13afc09")
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. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 torch.nn as nn
import functools

torch.manual_seed(0)

def custom_bwd(bwd):
    @functools.wraps(bwd)
    def decorate_bwd(*args, **kwargs):
        with torch.autocast(device_type='cuda', enabled=False):
            return bwd(*args, **kwargs)
    return decorate_bwd

# Create a simple backward function that takes context and grad_output
def sample_bwd(ctx, grad_output):
    # Simple backward function that returns gradients
    return grad_output, None

# Test that it can be called
test_grad = torch.randn(2, 4)
ctx = None

ARGS = {
    'bwd': sample_bwd
}
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
custom_fwd Ran
ran on a synthesized input
stanford-futuredata/stk/stk/backend/autocast.py
code served (permissive licence) · get_code("21b97d84ed7189c2")
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. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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 functools

torch.manual_seed(0)

# The function custom_fwd takes one parameter: fwd
# fwd should be a callable that will be wrapped
# Looking at the code, fwd is called with *args and **kwargs
# We need to create a simple function to wrap

def simple_forward_function(*args, **kwargs):
    """A simple function to be wrapped by custom_fwd."""
    # This function receives casted tensors and returns a result
    if args:
        # If we receive a tensor, do something simple with it
        if isinstance(args[0], torch.Tensor):
            return args[0] * 2
    return torch.tensor(1.0)

ARGS = {
    "fwd": simple_forward_function
}
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
promote_scalar Ran
ran, honoured the contract we drafted
stanford-futuredata/megablocks/megablocks/layers/dmoe.py
code served (permissive licence) · get_code("7630a3eb1f9be798")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Sonnet 4.5, prompt python_fixture_v1) and returned Tensor, ndim 1, dtype family float, shape (1,) 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 promotes a scalar (0-dimensional tensor) to a 1-dimensional tensor
# If the tensor already has dimensions, it returns it as-is
# We'll test with a scalar tensor (0-dimensional)
x = torch.tensor(5.0)

ARGS = {
    'x': x
}
Setup block drafted by
a language model, Claude Sonnet 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 1, dtype family float, shape (1,) — shape (1,) 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
resolve_dtensor Ran
ran on a synthesized input
stanford-futuredata/megablocks/megablocks/layers/mlp.py
code served (permissive licence) · get_code("4f0acf1e8190175f")
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
from packaging import version

torch.manual_seed(0)

# Create a simple tensor to pass to resolve_dtensor
weight = torch.randn(2, 4)

ARGS = {
    "weight": weight
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
packaging, 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
benchmark_function Not yet run
unverified (harvested, no recorded run)
stanford-futuredata/megablocks/megablocks/benchmark_util.py
code served (permissive licence) · get_code("70684f54abfa3a86")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 5 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
promote_scalar 2 other papers
2 dated earlier
2202.08906 (2022-02)
ST-MoE: Designing Stable and Transferable Sparse Expert Models
2210.05144 (2022-10)
Mixture of Attention Heads: Selecting Attention Heads Per Token

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

We present MegaBlocks, a system for efficient Mixture-of-Experts (MoE) training on GPUs. Our system is motivated by the limitations of current frameworks, which restrict the dynamic routing in MoE layers to satisfy the constraints of existing software and hardware. These formulations force a tradeoff between model quality and hardware efficiency, as users must choose between dropping tokens from the computation or wasting computation and memory on padding. To address these limitations, we reformulate MoE computation in terms of block-sparse operations and develop new block-sparse GPU kernels that efficiently handle the dynamism present in MoEs. Our approach never drops tokens and maps efficiently to modern hardware, enabling end-to-end training speedups of up to 40% over MoEs trained with the state-of-the-art Tutel library and 2.4x over DNNs trained with the highly-optimized Megatron-LM framework.

For agents

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

get_harvested_code_for_paper("2211.15841")
get_code_for_paper("2211.15841")
have("2211.15841")

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

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

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

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

Connect an agent — have() is free.