| Encoder |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("ad464810b30d6d25") How it ranRan 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 an instance of its own class, Encoder: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
import math
torch.manual_seed(0)
class Config:
def __init__(self):
self.d_model = 4
self.n_head = 2
self.d_ff = 8
self.dropout = 0.1
self.n_layers = 2
config = Config()
batch_size = 2
seq_len = 3
x = torch.randn(batch_size, seq_len, config.d_model)
mask = torch.ones(batch_size, seq_len)
ARGS = {
"config": config,
}
- 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 Encoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Encoder 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
|
| EncoderBlock |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("2b2a73a9b0d3825e") How it ranRan 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 an instance of its own class, EncoderBlock: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
from copy import deepcopy as cp
import math
import torch.nn.functional as F
torch.manual_seed(0)
# Helper functions needed by the module
def clones(module, N):
return nn.ModuleList([cp(module) for _ in range(N)])
def attention(query, key, value, mask=None, dropout=None):
d_k = query.size(-1)
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k)
if mask is not None:
scores = scores.masked_fill(mask == 0, -1000000000.0)
attn = F.softmax(scores, dim=-1)
if dropout is not None:
attn = dropout(attn)
return (torch.matmul(attn, value), attn)
# Define the config class
class Config:
def __init__(self):
self.d_model = 8
self.n_head = 2
self.d_ff = 16
self.dropout = 0.1
# Define the building block classes
class PositionwiseFeedForward(nn.Module):
def __init__(self, config):
super(PositionwiseFeedForward, self).__init__()
self.w_1 = nn.Linear(config.d_model, config.d_ff)
self.w_2 = nn.Linear(config.d_ff, config.d_model)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, x):
return self.w_2(self.dropout(F.relu(self.w_1(x))))
class MultiHeadAttention(nn.Module):
def __init__(self, config):
super(MultiHeadAttention, self).__init__()
self.d_model = config.d_model
self.n_head = config.n_head
self.d_k = config.d_model // config.n_head
self.linears = clones(nn.Linear(self.d_model, self.d_model), 4)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, query, key, value, mask=None):
if mask is not None:
mask = mask.unsqueeze(1)
batch_size = query.size(0)
query, key, value = [l(x).view(batch_size, -1, self.n_head, self.d_k).transpose(1, 2) for l, x in zip(self.linears, (query, key, value))]
x, attn = attention(query, key, value, mask=mask, dropout=self.dropout)
x = x.transpose(1, 2).contiguous().view(batch_size, -1, self.n_head * self.d_k)
return (self.linears[3](x), attn)
class FeedForwardBlock(nn.Module):
def __init__(self, config):
super(FeedForwardBlock, self).__init__()
self.norm = nn.LayerNorm(config.d_model)
self.feed_forward = PositionwiseFeedForward(config)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, x):
x_ = self.norm(x)
x_ = self.feed_forward(x_)
return self.dropout(x_) + x
class SelfAttentionBlock(nn.Module):
def __init__(self, config):
super(SelfAttentionBlock, self).__init__()
self.norm = nn.LayerNorm(config.d_model)
self.attn = MultiHeadAttention(config)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, x, mask):
x_ = self.norm(x)
x_, attn = self.attn(x_, x_, x_, mask)
return (self.dropout(x_) + x, attn)
class EncoderBlock(nn.Module):
def __init__(self, config):
super(EncoderBlock, self).__init__()
self.self_attn = SelfAttentionBlock(config)
self.feed_forward = FeedForwardBlock(config)
def forward(self, x, mask):
x, attn = self.self_attn(x, mask)
x = self.feed_forward(x)
return (x, attn)
# Create config
config = Config()
# Create sample inputs
batch_size = 2
seq_len = 3
d_model = 8
x = torch.randn(batch_size, seq_len, d_model)
mask = torch.ones(batch_size, 1, seq_len, seq_len)
ARGS = {
"config": config
}
- 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 EncoderBlock — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a EncoderBlock 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
|
| FeedForwardBlock |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("9e5a8995a0d0b684") How it ranRan 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 an instance of its own class, FeedForwardBlock: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
torch.manual_seed(0)
class Config:
def __init__(self, d_model, d_ff, dropout):
self.d_model = d_model
self.d_ff = d_ff
self.dropout = dropout
config = Config(d_model=4, d_ff=8, dropout=0.1)
x = torch.randn(2, 3, 4)
ARGS = {
"config": config
}
- 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 FeedForwardBlock — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a FeedForwardBlock 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
|
| MultiHeadAttention |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("ef066f2fb629b698") How it ranRan 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 an instance of its own class, MultiHeadAttention: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
from copy import deepcopy as cp
import math
import torch.nn.functional as F
torch.manual_seed(0)
def attention(query, key, value, mask=None, dropout=None):
d_k = query.size(-1)
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k)
if mask is not None:
scores = scores.masked_fill(mask == 0, -1000000000.0)
attn = F.softmax(scores, dim=-1)
if dropout is not None:
attn = dropout(attn)
return (torch.matmul(attn, value), attn)
def clones(module, N):
return nn.ModuleList([cp(module) for _ in range(N)])
class MultiHeadAttention(nn.Module):
def __init__(self, config):
super(MultiHeadAttention, self).__init__()
self.d_model = config.d_model
self.n_head = config.n_head
self.d_k = config.d_model // config.n_head
self.linears = clones(nn.Linear(self.d_model, self.d_model), 4)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, query, key, value, mask=None):
if mask is not None:
mask = mask.unsqueeze(1)
batch_size = query.size(0)
query, key, value = [l(x).view(batch_size, -1, self.n_head, self.d_k).transpose(1, 2) for l, x in zip(self.linears, (query, key, value))]
x, attn = attention(query, key, value, mask=mask, dropout=self.dropout)
x = x.transpose(1, 2).contiguous().view(batch_size, -1, self.n_head * self.d_k)
return (self.linears[3](x), attn)
class Config:
def __init__(self, d_model, n_head, dropout):
self.d_model = d_model
self.n_head = n_head
self.dropout = dropout
config = Config(d_model=4, n_head=2, dropout=0.1)
ARGS = {
"config": config
}
- 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 MultiHeadAttention — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MultiHeadAttention 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
|
| PositionalEmbedding |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("21d20b888bdba6a4") How it ranRan 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 an instance of its own class, PositionalEmbedding: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
import math
torch.manual_seed(0)
class Config:
def __init__(self, max_len, d_model):
self.max_len = max_len
self.d_model = d_model
config = Config(max_len=8, d_model=4)
ARGS = {
"config": config
}
- 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 PositionalEmbedding — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PositionalEmbedding 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
|
| PositionwiseFeedForward |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("73d36f4b75757093") How it ranRan 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 an instance of its own class, PositionwiseFeedForward: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
torch.manual_seed(0)
class Config:
def __init__(self):
self.d_model = 4
self.d_ff = 8
self.dropout = 0.1
config = Config()
ARGS = {
"config": config
}
- 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 PositionwiseFeedForward — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PositionwiseFeedForward 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
|
| SelfAttentionBlock |
Ran ran on a synthesized input · constructed an object; no result was computed |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("52117ec9c56aa17a") How it ranRan 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 an instance of its own class, SelfAttentionBlock: the run constructed the object and did not call it, so no result was computed. 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.nn as nn
from copy import deepcopy as cp
import math
import torch.nn.functional as F
torch.manual_seed(0)
# Define helper functions needed by the module
def clones(module, N):
return nn.ModuleList([cp(module) for _ in range(N)])
def attention(query, key, value, mask=None, dropout=None):
d_k = query.size(-1)
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(d_k)
if mask is not None:
scores = scores.masked_fill(mask == 0, -1000000000.0)
attn = F.softmax(scores, dim=-1)
if dropout is not None:
attn = dropout(attn)
return (torch.matmul(attn, value), attn)
# Define MultiHeadAttention as required
class MultiHeadAttention(nn.Module):
def __init__(self, config):
super(MultiHeadAttention, self).__init__()
self.d_model = config.d_model
self.n_head = config.n_head
self.d_k = config.d_model // config.n_head
self.linears = clones(nn.Linear(self.d_model, self.d_model), 4)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, query, key, value, mask=None):
if mask is not None:
mask = mask.unsqueeze(1)
batch_size = query.size(0)
query, key, value = [l(x).view(batch_size, -1, self.n_head, self.d_k).transpose(1, 2) for l, x in zip(self.linears, (query, key, value))]
x, attn = attention(query, key, value, mask=mask, dropout=self.dropout)
x = x.transpose(1, 2).contiguous().view(batch_size, -1, self.n_head * self.d_k)
return (self.linears[3](x), attn)
# Define SelfAttentionBlock
class SelfAttentionBlock(nn.Module):
def __init__(self, config):
super(SelfAttentionBlock, self).__init__()
self.norm = nn.LayerNorm(config.d_model)
self.attn = MultiHeadAttention(config)
self.dropout = nn.Dropout(p=config.dropout)
def forward(self, x, mask):
x_ = self.norm(x)
x_, attn = self.attn(x_, x_, x_, mask)
return (self.dropout(x_) + x, attn)
# Create a config class with required attributes
class Config:
def __init__(self):
self.d_model = 4
self.n_head = 2
self.dropout = 0.1
# Create config instance
config = Config()
# Create input tensors
# batch_size=2, seq_len=3, d_model=4
x = torch.randn(2, 3, 4)
mask = torch.ones(2, 1, 3, 3)
ARGS = {
"config": config
}
- 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 SelfAttentionBlock — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a SelfAttentionBlock 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
|
| attention |
Ran ran; our contract draft was wrong, not the code |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("bbc7c22f9d8732dc") How it ranRan 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.nn as nn
torch.manual_seed(0)
# Construct tiny tensors for attention mechanism
# batch_size=2, seq_len=3, d_k=4
batch_size = 2
seq_len = 3
d_k = 4
query = torch.randn(batch_size, seq_len, d_k)
key = torch.randn(batch_size, seq_len, d_k)
value = torch.randn(batch_size, seq_len, d_k)
# Create a mask (optional parameter)
# mask should be broadcastable to scores shape (batch_size, seq_len, seq_len)
# Use 1s where we want to attend, 0s where we want to mask
mask = torch.ones(batch_size, seq_len, seq_len)
# Create a dropout layer (optional parameter)
dropout = nn.Dropout(p=0.1)
ARGS = {
"query": query,
"key": key,
"value": value,
"mask": mask,
"dropout": dropout,
}
- 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
|
| clones |
Ran ran; our contract draft was wrong, not the code |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("d013dfb22c365f67") How it ranRan 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 ModuleList. 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.nn as nn
from copy import deepcopy as cp
torch.manual_seed(0)
# The clones function takes:
# - module: an nn.Module to be cloned N times
# - N: an integer specifying how many clones to create
# Create a simple nn.Module for testing
class SimpleModule(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(4, 3)
def forward(self, x):
return self.linear(x)
module = SimpleModule()
N = 5
ARGS = {
"module": module,
"N": N,
}
- 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 ModuleList — a ModuleList output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ModuleList output the recorded ndim 1 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
|
| Transformer |
Not yet run unverified (harvested, no recorded run) |
MSU-MLSys-Lab/CATE/layers/transformer.py code served (permissive licence) · get_code("014afd02662c3b66") How it ran |