| EncoderLayer |
Ran ran on a synthesized input |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("7d0a47fc145a9d6c") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
# Import the classes from the provided code
import math
import torch.nn.functional as F
class FeedForward(nn.Module):
def __init__(self, d_model, d_ff=2048, dropout=0.2):
super().__init__()
self.linear_1 = nn.Linear(d_model, d_ff)
self.dropout_1 = nn.Dropout(dropout)
self.linear_2 = nn.Linear(d_ff, d_model)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
x = self.dropout_1(F.relu(self.linear_1(x)))
x = self.dropout_2(self.linear_2(x))
return x
class MultiHeadAttention(nn.Module):
def __init__(self, heads, d_model, dropout=0.1):
super().__init__()
self.d_model = d_model
self.d_k = d_model // heads
self.h = heads
self.q_linear = nn.Linear(d_model, d_model)
self.v_linear = nn.Linear(d_model, d_model)
self.k_linear = nn.Linear(d_model, d_model)
self.dropout = nn.Dropout(dropout)
self.out = nn.Linear(d_model, d_model)
def forward(self, q, k, v):
bs = q.size(0)
k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
v = self.v_linear(v).view(bs, -1, self.h, self.d_k)
k = k.transpose(1, 2)
q = q.transpose(1, 2)
v = v.transpose(1, 2)
output_scores, scores = attention(q, k, v, self.d_k, self.dropout)
concat = output_scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
output = self.out(concat)
return (output, scores)
class Norm(nn.Module):
def __init__(self, d_model, eps=1e-06):
super().__init__()
self.size = d_model
self.alpha = nn.Parameter(torch.ones(self.size))
self.bias = nn.Parameter(torch.zeros(self.size))
self.eps = eps
def forward(self, x):
norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim=-1, keepdim=True) + self.eps) + self.bias
return norm
def attention(q, k, v, d_k, dropout=None):
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
scores = F.softmax(scores, dim=-1)
if dropout is not None:
scores = dropout(scores)
output = torch.matmul(scores, v)
return (output, scores)
class EncoderLayer(nn.Module):
def __init__(self, d_model, heads, dropout=0.1):
super().__init__()
self.norm_1 = Norm(d_model)
self.norm_2 = Norm(d_model)
self.attn = MultiHeadAttention(heads, d_model, dropout=dropout)
self.ff = FeedForward(d_model, dropout=dropout)
self.dropout_1 = nn.Dropout(dropout)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
x2 = self.norm_1(x)
output, scores = self.attn(x2, x2, x2)
x = x + self.dropout_1(output)
x2 = self.norm_2(x)
x = x + self.dropout_2(self.ff(x2))
return (x, scores)
INIT_ARGS = {
'd_model': 4,
'heads': 2,
'dropout': 0.1
}
ARGS = {
'x': torch.randn(2, 3, 4)
}
if __name__ == '__main__':
encoder_layer = EncoderLayer(**INIT_ARGS)
output, scores = encoder_layer(**ARGS)
print("Output shape:", output.shape)
print("Scores shape:", scores.shape)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| MultiHeadAttention |
Ran ran on a synthesized input |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("0184227dae2b2a3a") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
import math
import torch.nn.functional as F
def attention(q, k, v, d_k, dropout=None):
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
scores = F.softmax(scores, dim=-1)
if dropout is not None:
scores = dropout(scores)
output = torch.matmul(scores, v)
return (output, scores)
class MultiHeadAttention(nn.Module):
def __init__(self, heads, d_model, dropout=0.1):
super().__init__()
self.d_model = d_model
self.d_k = d_model // heads
self.h = heads
self.q_linear = nn.Linear(d_model, d_model)
self.v_linear = nn.Linear(d_model, d_model)
self.k_linear = nn.Linear(d_model, d_model)
self.dropout = nn.Dropout(dropout)
self.out = nn.Linear(d_model, d_model)
def forward(self, q, k, v):
bs = q.size(0)
k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
v = self.v_linear(v).view(bs, -1, self.h, self.d_k)
k = k.transpose(1, 2)
q = q.transpose(1, 2)
v = v.transpose(1, 2)
output_scores, scores = attention(q, k, v, self.d_k, self.dropout)
concat = output_scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
output = self.out(concat)
return (output, scores)
INIT_ARGS = {
'heads': 2,
'd_model': 8,
'dropout': 0.1
}
ARGS = {
'q': torch.randn(2, 5, 8),
'k': torch.randn(2, 5, 8),
'v': torch.randn(2, 5, 8)
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| Norm |
Ran ran on a synthesized input |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("a87c34abb9f3bffe") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 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
import torch.nn as nn
INIT_ARGS = {
"d_model": 4,
"eps": 1e-06,
}
ARGS = {
"x": torch.randn(2, 3, 4),
}
if __name__ == "__main__":
norm = nn.Module()
norm.__class__ = type('Norm', (nn.Module,), {
'__init__': lambda self, d_model, eps=1e-06: (
nn.Module.__init__(self),
setattr(self, 'size', d_model),
setattr(self, 'alpha', nn.Parameter(torch.ones(d_model))),
setattr(self, 'bias', nn.Parameter(torch.zeros(d_model))),
setattr(self, 'eps', eps),
),
'forward': lambda self, x: (
self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim=-1, keepdim=True) + self.eps) + self.bias
),
})
norm_instance = norm.__class__(**INIT_ARGS)
output = norm_instance(**ARGS)
print(output.shape)
print(output)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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, 3, 4) — shape (2, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| T_Encoders |
Ran ran on a synthesized input |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("0bb4e4af64b8087b") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
import torch.nn.functional as F
import copy
import math
class Norm(nn.Module):
def __init__(self, d_model, eps=1e-06):
super().__init__()
self.size = d_model
self.alpha = nn.Parameter(torch.ones(self.size))
self.bias = nn.Parameter(torch.zeros(self.size))
self.eps = eps
def forward(self, x):
norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim=-1, keepdim=True) + self.eps) + self.bias
return norm
def attention(q, k, v, d_k, dropout=None):
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
scores = F.softmax(scores, dim=-1)
if dropout is not None:
scores = dropout(scores)
output = torch.matmul(scores, v)
return (output, scores)
class MultiHeadAttention(nn.Module):
def __init__(self, heads, d_model, dropout=0.1):
super().__init__()
self.d_model = d_model
self.d_k = d_model // heads
self.h = heads
self.q_linear = nn.Linear(d_model, d_model)
self.v_linear = nn.Linear(d_model, d_model)
self.k_linear = nn.Linear(d_model, d_model)
self.dropout = nn.Dropout(dropout)
self.out = nn.Linear(d_model, d_model)
def forward(self, q, k, v):
bs = q.size(0)
k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
v = self.v_linear(v).view(bs, -1, self.h, self.d_k)
k = k.transpose(1, 2)
q = q.transpose(1, 2)
v = v.transpose(1, 2)
output_scores, scores = attention(q, k, v, self.d_k, self.dropout)
concat = output_scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
output = self.out(concat)
return (output, scores)
class FeedForward(nn.Module):
def __init__(self, d_model, d_ff=2048, dropout=0.2):
super().__init__()
self.linear_1 = nn.Linear(d_model, d_ff)
self.dropout_1 = nn.Dropout(dropout)
self.linear_2 = nn.Linear(d_ff, d_model)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
x = self.dropout_1(F.relu(self.linear_1(x)))
x = self.dropout_2(self.linear_2(x))
return x
class EncoderLayer(nn.Module):
def __init__(self, d_model, heads, dropout=0.1):
super().__init__()
self.norm_1 = Norm(d_model)
self.norm_2 = Norm(d_model)
self.attn = MultiHeadAttention(heads, d_model, dropout=dropout)
self.ff = FeedForward(d_model, dropout=dropout)
self.dropout_1 = nn.Dropout(dropout)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
x2 = self.norm_1(x)
output, scores = self.attn(x2, x2, x2)
x = x + self.dropout_1(output)
x2 = self.norm_2(x)
x = x + self.dropout_2(self.ff(x2))
return (x, scores)
def get_clones(module, N):
return nn.ModuleList([copy.deepcopy(module) for i in range(N)])
class T_Encoders(nn.Module):
def __init__(self, d_model, N, heads, dropout):
super().__init__()
self.N = N
self.layers = get_clones(EncoderLayer(d_model, heads, dropout), N)
self.norm = Norm(d_model)
def forward(self, src):
x = src
for i in range(self.N):
x, scores = self.layers[i](x)
return (self.norm(x), scores)
INIT_ARGS = {
'd_model': 4,
'N': 2,
'heads': 2,
'dropout': 0.1
}
ARGS = {
'src': torch.randn(2, 3, 4)
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| TransformerEncoder |
Ran ran on a synthesized input |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("385daea0f2dbd0b0") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
import copy
import math
import torch.nn.functional as F
class Norm(nn.Module):
def __init__(self, d_model, eps=1e-06):
super().__init__()
self.size = d_model
self.alpha = nn.Parameter(torch.ones(self.size))
self.bias = nn.Parameter(torch.zeros(self.size))
self.eps = eps
def forward(self, x):
norm = self.alpha * (x - x.mean(dim=-1, keepdim=True)) / (x.std(dim=-1, keepdim=True) + self.eps) + self.bias
return norm
def attention(q, k, v, d_k, dropout=None):
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
scores = F.softmax(scores, dim=-1)
if dropout is not None:
scores = dropout(scores)
output = torch.matmul(scores, v)
return (output, scores)
class MultiHeadAttention(nn.Module):
def __init__(self, heads, d_model, dropout=0.1):
super().__init__()
self.d_model = d_model
self.d_k = d_model // heads
self.h = heads
self.q_linear = nn.Linear(d_model, d_model)
self.v_linear = nn.Linear(d_model, d_model)
self.k_linear = nn.Linear(d_model, d_model)
self.dropout = nn.Dropout(dropout)
self.out = nn.Linear(d_model, d_model)
def forward(self, q, k, v):
bs = q.size(0)
k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
v = self.v_linear(v).view(bs, -1, self.h, self.d_k)
k = k.transpose(1, 2)
q = q.transpose(1, 2)
v = v.transpose(1, 2)
output_scores, scores = attention(q, k, v, self.d_k, self.dropout)
concat = output_scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
output = self.out(concat)
return (output, scores)
class FeedForward(nn.Module):
def __init__(self, d_model, d_ff=2048, dropout=0.2):
super().__init__()
self.linear_1 = nn.Linear(d_model, d_ff)
self.dropout_1 = nn.Dropout(dropout)
self.linear_2 = nn.Linear(d_ff, d_model)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
x = self.dropout_1(F.relu(self.linear_1(x)))
x = self.dropout_2(self.linear_2(x))
return x
class EncoderLayer(nn.Module):
def __init__(self, d_model, heads, dropout=0.1):
super().__init__()
self.norm_1 = Norm(d_model)
self.norm_2 = Norm(d_model)
self.attn = MultiHeadAttention(heads, d_model, dropout=dropout)
self.ff = FeedForward(d_model, dropout=dropout)
self.dropout_1 = nn.Dropout(dropout)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
x2 = self.norm_1(x)
output, scores = self.attn(x2, x2, x2)
x = x + self.dropout_1(output)
x2 = self.norm_2(x)
x = x + self.dropout_2(self.ff(x2))
return (x, scores)
def get_clones(module, N):
return nn.ModuleList([copy.deepcopy(module) for i in range(N)])
class T_Encoders(nn.Module):
def __init__(self, d_model, N, heads, dropout):
super().__init__()
self.N = N
self.layers = get_clones(EncoderLayer(d_model, heads, dropout), N)
self.norm = Norm(d_model)
def forward(self, src):
x = src
for i in range(self.N):
x, scores = self.layers[i](x)
return (self.norm(x), scores)
class TransformerEncoder(nn.Module):
def __init__(self, d_model, N, heads, dropout):
super().__init__()
self.encoders = T_Encoders(d_model, N, heads, dropout)
def forward(self, src):
e_outputs, scores = self.encoders(src)
return (e_outputs, scores)
INIT_ARGS = {
'd_model': 4,
'N': 2,
'heads': 2,
'dropout': 0.1
}
ARGS = {
'src': torch.randn(2, 3, 4)
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| attention |
Ran ran; our contract draft was wrong, not the code |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("62a5ef486fa1cb33") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) 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
import math
torch.manual_seed(0)
# Create small tensors for q, k, v
# q: (batch=2, seq_len=3, d_k=4)
# k: (batch=2, seq_len=3, d_k=4)
# v: (batch=2, seq_len=3, d_v=5)
q = torch.randn(2, 3, 4)
k = torch.randn(2, 3, 4)
v = torch.randn(2, 3, 5)
# d_k is the dimension of the key (used for scaling)
d_k = 4
# dropout is optional - create a dropout layer
dropout = nn.Dropout(p=0.1)
ARGS = {
"q": q,
"k": k,
"v": v,
"d_k": d_k,
"dropout": dropout
}
- 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 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
|
| Network |
Not yet run unverified (harvested, no recorded run) |
SubmissionsIn/RML/RML+NRCH/RML_network.py code served (permissive licence) · get_code("ad129ddc55a8a426") How it ran |