| CosinePositionalEmbedding |
Ran ran on a synthesized input · constructed an object; no result was computed |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("1af228fc6281d8b8") 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, CosinePositionalEmbedding: 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
from enum import IntEnum
torch.manual_seed(0)
class Dim(IntEnum):
batch = 0
seq = 1
feature = 2
class CosinePositionalEmbedding(nn.Module):
def __init__(self, d_model, max_len=512):
super().__init__()
pe = 0.1 * torch.randn(max_len, d_model)
position = torch.arange(0, max_len).unsqueeze(1).float()
div_term = torch.exp(torch.arange(0, d_model, 2).float() * -(math.log(10000.0) / d_model))
pe[:, 0::2] = torch.sin(position * div_term)
pe[:, 1::2] = torch.cos(position * div_term)
pe = pe.unsqueeze(0)
self.weight = nn.Parameter(pe, requires_grad=False)
def forward(self, x):
return self.weight[:, :x.size(Dim.seq), :]
ARGS = {
"d_model": 4,
"max_len": 512
}
- 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 CosinePositionalEmbedding — 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 CosinePositionalEmbedding 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
|
| GCNLayer |
Ran ran on a synthesized input · constructed an object; no result was computed |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("468b69dcd19612b7") 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, GCNLayer: 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 torch.nn.functional as F
import numpy as np
import math
from torch.nn import Module, Parameter
torch.manual_seed(0)
# Define the necessary classes (copied from function signature)
class GraphConvolution(Module):
def __init__(self, in_features, out_features, bias=True):
super(GraphConvolution, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.weight = nn.Parameter(torch.FloatTensor(in_features, out_features))
if bias:
self.bias = nn.Parameter(torch.FloatTensor(out_features))
else:
self.register_parameter('bias', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1.0 / math.sqrt(self.weight.size(1))
self.weight.data.uniform_(-stdv, stdv)
if self.bias is not None:
self.bias.data.uniform_(-stdv, stdv)
def glorot_init(self, input_dim, output_dim):
init_range = np.sqrt(6.0 / (input_dim + output_dim))
initial = torch.rand(input_dim, output_dim) * 2 * init_range - init_range
return nn.Parameter(initial / 2)
def forward(self, input, adj):
support = input
output = torch.spmm(adj, support)
if self.bias is not None:
return output + self.bias
else:
return output
def __repr__(self):
return self.__class__.__name__ + ' (' + str(self.in_features) + ' -> ' + str(self.out_features) + ')'
class GNN(nn.Module):
def __init__(self, nfeat, nhid, dropout, alpha):
super(GNN, self).__init__()
self.gc1 = GraphConvolution(nfeat, nhid)
self.dropout = dropout
self.leakyrelu = nn.LeakyReLU(alpha)
def forward(self, x, adj):
x = self.gc1(x, adj)
return x
class GCNLayer(nn.Module):
"""
GCN Module layer
"""
def __init__(self, opt):
super(GCNLayer, self).__init__()
self.opt = opt
self.dropout = opt['dropout']
self.layer_number = opt['GNNL']
self.encoder = []
for i in range(self.layer_number):
self.encoder.append(GNN(nfeat=opt['hidden_units'], nhid=opt['hidden_units'], dropout=opt['dropout'], alpha=opt['leakey']))
self.encoder = nn.ModuleList(self.encoder)
def forward(self, fea, adj):
learn_fea = fea
tmp_fea = fea
for layer in self.encoder:
learn_fea = F.dropout(learn_fea, self.dropout, training=self.training)
learn_fea = layer(learn_fea, adj)
tmp_fea = tmp_fea + learn_fea
return tmp_fea / (self.layer_number + 1)
# Create small feature matrix (2 nodes, 4 features)
fea = torch.randn(2, 4)
# Create sparse adjacency matrix (2x2)
indices = torch.LongTensor([[0, 1], [1, 0]])
values = torch.FloatTensor([1.0, 1.0])
adj = torch.sparse.FloatTensor(indices.t(), values, torch.Size([2, 2]))
# Create opt dictionary with all required keys
ARGS = {
'opt': {
'dropout': 0.1,
'GNNL': 2,
'hidden_units': 4,
'leakey': 0.2
}
}
- 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 GCNLayer — 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 GCNLayer 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
|
| GNN |
Ran ran on a synthesized input · constructed an object; no result was computed |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("1fdbae2fa6548e67") 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, GNN: 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 numpy as np
import math
torch.manual_seed(0)
# Build tiny tensors for input features and adjacency matrix
nfeat = 4 # input feature dimension
nhid = 3 # hidden dimension
dropout = 0.5
alpha = 0.2
# Create a small input tensor (2 nodes, 4 features each)
x = torch.randn(2, nfeat)
# Create a small sparse adjacency matrix (2x2)
# Using a simple dense matrix converted to sparse for spmm compatibility
adj_dense = torch.tensor([[1.0, 1.0], [1.0, 1.0]])
adj = adj_dense.to_sparse()
ARGS = {
'nfeat': nfeat,
'nhid': nhid,
'dropout': dropout,
'alpha': alpha
}
- 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 GNN — 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 GNN 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
|
| GraphConvolution |
Ran ran on a synthesized input · constructed an object; no result was computed |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("a600593f88af2876") 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, GraphConvolution: 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 numpy as np
import math
torch.manual_seed(0)
# Create a small sparse adjacency matrix (2x2 for simplicity)
# We'll use a COO sparse tensor format
indices = torch.LongTensor([[0, 1], [1, 0]])
values = torch.FloatTensor([1.0, 1.0])
adj = torch.sparse_coo_tensor(indices.t(), values, (2, 2))
# Create input tensor with shape (2, 4) - 2 nodes, 4 features
input_tensor = torch.randn(2, 4)
# Define ARGS dict mapping all GraphConvolution.__init__ parameters
ARGS = {
'in_features': 4,
'out_features': 3,
'bias': True
}
- 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 GraphConvolution — 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 GraphConvolution 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 |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("7f49a12274975f04") 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; no output shape is stated. 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 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
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.init import xavier_uniform_
from torch.nn.init import constant_
import math
def attention(q, k, v, d_k, mask, dropout, zero_pad):
"""
This is called by Multi-head atention object to find the values.
"""
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(d_k)
bs, head, seqlen = (scores.size(0), scores.size(1), scores.size(2))
scores.masked_fill_(mask == 0, -1e+32)
scores = F.softmax(scores, dim=-1)
if zero_pad:
pad_zero = torch.zeros(bs, head, 1, seqlen)
scores = torch.cat([pad_zero, scores[:, :, 1:, :]], dim=2)
scores = dropout(scores)
output = torch.matmul(scores, v)
return output
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, d_feature, n_heads, dropout, kq_same, bias=True):
super().__init__()
self.d_model = d_model
self.d_k = d_feature
self.h = n_heads
self.kq_same = kq_same
self.v_linear = nn.Linear(d_model, d_model, bias=bias)
self.k_linear = nn.Linear(d_model, d_model, bias=bias)
if kq_same is False:
self.q_linear = nn.Linear(d_model, d_model, bias=bias)
self.dropout = nn.Dropout(dropout)
self.proj_bias = bias
self.out_proj = nn.Linear(d_model, d_model, bias=bias)
self._reset_parameters()
def _reset_parameters(self):
xavier_uniform_(self.k_linear.weight)
xavier_uniform_(self.v_linear.weight)
if self.kq_same is False:
xavier_uniform_(self.q_linear.weight)
if self.proj_bias:
constant_(self.k_linear.bias, 0.0)
constant_(self.v_linear.bias, 0.0)
if self.kq_same is False:
constant_(self.q_linear.bias, 0.0)
constant_(self.out_proj.bias, 0.0)
def forward(self, q, k, v, mask, zero_pad):
bs = q.size(0)
k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
if self.kq_same is False:
q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
else:
q = self.k_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)
scores = attention(q, k, v, self.d_k, mask, self.dropout, zero_pad)
concat = scores.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
output = self.out_proj(concat)
return output
INIT_ARGS = {
'd_model': 8,
'd_feature': 4,
'n_heads': 2,
'dropout': 0.1,
'kq_same': True,
'bias': True
}
ARGS = {
'q': torch.randn(2, 3, 8),
'k': torch.randn(2, 3, 8),
'v': torch.randn(2, 3, 8),
'mask': torch.ones(2, 2, 3, 3),
'zero_pad': False
}
model = MultiHeadAttention(**INIT_ARGS)
output = model(**ARGS)
print("Output shape:", output.shape)
print("Expected shape: (2, 3, 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 Tensor, ndim 3, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
- 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)
|
| TransformerLayer |
Ran ran on a synthesized input · constructed an object; no result was computed |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("4b1352ba81722cb9") 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, TransformerLayer: the run constructed the object and did not call it, so no result was computed. 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 numpy as np
import math
torch.manual_seed(0)
# Define the required classes and functions that are used in TransformerLayer
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, d_feature, n_heads, dropout, kq_same, bias=True):
super().__init__()
self.d_model = d_model
self.d_k = d_feature
self.h = n_heads
self.kq_same = kq_same
self.v_linear = nn.Linear(d_model, d_model, bias=bias)
self.k_linear = nn.Linear(d_model, d_model, bias=bias)
if kq_same is False:
self.q_linear = nn.Linear(d_model, d_model, bias=bias)
self.dropout = nn.Dropout(dropout)
self.proj_bias = bias
self.out_proj = nn.Linear(d_model, d_model, bias=bias)
def forward(self, q, k, v, mask, zero_pad):
bs = q.size(0)
k = self.k_linear(k).view(bs, -1, self.h, self.d_k)
if self.kq_same is False:
q = self.q_linear(q).view(bs, -1, self.h, self.d_k)
else:
q = self.k_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)
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(self.d_k)
scores.masked_fill_(mask == 0, -1e+32)
scores = torch.nn.functional.softmax(scores, dim=-1)
scores = self.dropout(scores)
output = torch.matmul(scores, v)
return output.transpose(1, 2).contiguous().view(bs, -1, self.d_model)
class TransformerLayer(nn.Module):
def __init__(self, d_model, d_feature, d_ff, n_heads, dropout, kq_same):
super().__init__()
kq_same = kq_same == 1
self.masked_attn_head = MultiHeadAttention(d_model, d_feature, n_heads, dropout, kq_same=kq_same)
self.layer_norm1 = nn.LayerNorm(d_model)
self.dropout1 = nn.Dropout(dropout)
self.linear1 = nn.Linear(d_model, d_ff)
self.activation = nn.ReLU()
self.dropout = nn.Dropout(dropout)
self.linear2 = nn.Linear(d_ff, d_model)
self.layer_norm2 = nn.LayerNorm(d_model)
self.dropout2 = nn.Dropout(dropout)
def forward(self, mask, query, key, values, apply_pos=True):
seqlen, batch_size = (query.size(1), query.size(0))
nopeek_mask = np.triu(np.ones((1, 1, seqlen, seqlen)), k=mask).astype('uint8')
src_mask = (torch.from_numpy(nopeek_mask) == 0)
if mask == 0:
query2 = self.masked_attn_head(query, key, values, mask=src_mask, zero_pad=True)
else:
query2 = self.masked_attn_head(query, key, values, mask=src_mask, zero_pad=False)
query = query + self.dropout1(query2)
query = self.layer_norm1(query)
if apply_pos:
query2 = self.linear2(self.dropout(self.activation(self.linear1(query))))
return query
# Create test data
d_model = 4
d_feature = 2
d_ff = 8
n_heads = 2
dropout = 0.1
kq_same = 1
batch_size = 2
seq_len = 3
mask = torch.ones(batch_size, 1, seq_len, seq_len)
query = torch.randn(batch_size, seq_len, d_model)
key = torch.randn(batch_size, seq_len, d_model)
values = torch.randn(batch_size, seq_len, d_model)
ARGS = {
'd_model': d_model,
'd_feature': d_feature,
'd_ff': d_ff,
'n_heads': n_heads,
'dropout': dropout,
'kq_same': kq_same,
}
- 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 TransformerLayer — 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 TransformerLayer 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 |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("134e95d193454d9c") 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 Tensor, ndim 4, dtype family float, shape (2, 3, 4, 6) as a later run recorded it. 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, 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
import math
torch.manual_seed(0)
# Set device to CPU only
device = torch.device('cpu')
# Parameters
batch_size = 2
num_heads = 3
seq_len = 4
d_k = 5
d_v = 6
# q: (batch_size, num_heads, seq_len, d_k)
q = torch.randn(batch_size, num_heads, seq_len, d_k)
# k: (batch_size, num_heads, seq_len, d_k)
k = torch.randn(batch_size, num_heads, seq_len, d_k)
# v: (batch_size, num_heads, seq_len, d_v)
v = torch.randn(batch_size, num_heads, seq_len, d_v)
# d_k: dimension of key
d_k_param = d_k
# mask: (batch_size, num_heads, seq_len, seq_len) with 0s and 1s
# The function uses mask == 0 to identify positions to mask
mask = torch.ones(batch_size, num_heads, seq_len, seq_len)
mask[:, :, 0, 1:] = 0 # mask some positions
# dropout: a callable that applies dropout
dropout = nn.Dropout(p=0.1)
# zero_pad: boolean flag
zero_pad = True
ARGS = {
'q': q,
'k': k,
'v': v,
'd_k': d_k_param,
'mask': mask,
'dropout': dropout,
'zero_pad': zero_pad
}
- 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 4, dtype family float, shape (2, 3, 4, 6) — shape (2, 3, 4, 6) 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
|
| SimpleKT_Encoder |
Not yet run unverified (harvested, no recorded run) |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("113e4ce51a2d138f") How it ran |
| TransKT |
Not yet run unverified (harvested, no recorded run) |
DQYZHWK/TransKT/model/TransKT.py code served (permissive licence) · get_code("60752970ece072d1") How it ran |