| EmbeddingNet |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("d32eca8fe0b18c43") 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 numpy as np
# INIT_ARGS for EmbeddingNet.__init__(node_dim, embedding_dim, seq_length)
INIT_ARGS = {
'node_dim': 5,
'embedding_dim': 8,
'seq_length': 6
}
# ARGS for EmbeddingNet.forward(x, solutions, visited_time=None)
batch_size = 2
seq_length = 6 # Must match INIT_ARGS['seq_length']
node_dim = 5 # Must match INIT_ARGS['node_dim']
# x: node features, shape (batch_size, seq_length, node_dim)
x = torch.randn(batch_size, seq_length, node_dim)
# solutions: permutation indices, shape (batch_size, seq_length)
# Each row should be a permutation of indices 0 to seq_length-1
solutions = torch.tensor([
[0, 1, 2, 3, 4, 5],
[2, 0, 4, 1, 5, 3]
], dtype=torch.long)
# visited_time: optional, can be None or shape (batch_size, seq_length)
visited_time = None
ARGS = {
'x': x,
'solutions': solutions,
'visited_time': visited_time
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, 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)
|
| FFandNormsubLayer |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("850da12d3368c65a") 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
from torch import nn
import math
class Normalization(nn.Module):
def __init__(self, embed_dim, normalization='batch'):
super(Normalization, self).__init__()
normalizer_class = {'batch': nn.BatchNorm1d, 'instance': nn.InstanceNorm1d}.get(normalization, None)
self.normalization = normalization
if not self.normalization == 'layer':
self.normalizer = normalizer_class(embed_dim, affine=True)
def init_parameters(self):
for name, param in self.named_parameters():
stdv = 1.0 / math.sqrt(param.size(-1))
param.data.uniform_(-stdv, stdv)
def forward(self, input):
if self.normalization == 'layer':
return (input - input.mean((1, 2)).view(-1, 1, 1)) / torch.sqrt(input.var((1, 2)).view(-1, 1, 1) + 1e-05)
if isinstance(self.normalizer, nn.BatchNorm1d):
return self.normalizer(input.view(-1, input.size(-1))).view(*input.size())
elif isinstance(self.normalizer, nn.InstanceNorm1d):
return self.normalizer(input.permute(0, 2, 1)).permute(0, 2, 1)
else:
assert self.normalizer is None, 'Unknown normalizer type'
return input
class FFandNormsubLayer(nn.Module):
def __init__(self, n_heads, embed_dim, feed_forward_hidden, normalization='layer'):
super(FFandNormsubLayer, self).__init__()
self.FF1 = nn.Sequential(nn.Linear(embed_dim, feed_forward_hidden), nn.ReLU(inplace=True), nn.Linear(feed_forward_hidden, embed_dim)) if feed_forward_hidden > 0 else nn.Linear(embed_dim, embed_dim)
self.FF2 = nn.Sequential(nn.Linear(embed_dim, feed_forward_hidden), nn.ReLU(inplace=True), nn.Linear(feed_forward_hidden, embed_dim)) if feed_forward_hidden > 0 else nn.Linear(embed_dim, embed_dim)
self.Norm = Normalization(embed_dim, normalization)
def forward(self, input1, input2):
out1 = self.FF1(input1)
out2 = self.FF2(input2)
return (self.Norm(out1 + input1), self.Norm(out2 + input2))
INIT_ARGS = {
'n_heads': 2,
'embed_dim': 4,
'feed_forward_hidden': 8,
'normalization': 'layer'
}
ARGS = {
'input1': torch.randn(2, 3, 4),
'input2': 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)
|
| MLP |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("355814dd5ff90a73") 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 1, dtype family float, shape (2,) 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
import math
class MLP(torch.nn.Module):
def __init__(self, input_dim=128, feed_forward_dim=64, embedding_dim=64, output_dim=1):
super(MLP, self).__init__()
self.fc1 = torch.nn.Linear(input_dim, feed_forward_dim)
self.fc2 = torch.nn.Linear(feed_forward_dim, embedding_dim)
self.fc3 = torch.nn.Linear(embedding_dim, output_dim)
self.dropout = torch.nn.Dropout(p=0.05)
self.ReLU = nn.ReLU(inplace=True)
self.init_parameters()
def init_parameters(self):
for param in self.parameters():
stdv = 1.0 / math.sqrt(param.size(-1))
param.data.uniform_(-stdv, stdv)
def forward(self, in_):
result = self.ReLU(self.fc1(in_))
result = self.dropout(result)
result = self.ReLU(self.fc2(result))
result = self.fc3(result).squeeze(-1)
return result
INIT_ARGS = {
'input_dim': 4,
'feed_forward_dim': 3,
'embedding_dim': 2,
'output_dim': 1
}
ARGS = {
'in_': torch.randn(2, 4)
}
if __name__ == '__main__':
model = MLP(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output: {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 1, dtype family float, shape (2,) — shape (2,) 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)
|
| MultiHeadAttention |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("fa54d99ecac04864") 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 numpy as np
INIT_ARGS = {
'n_heads': 2,
'input_dim': 4,
'embed_dim': 8,
}
# Create dummy inputs matching INIT_ARGS dimensions
batch_size = 2
graph_size = 3
# h_node_in: (batch_size, graph_size, input_dim)
h_node_in = torch.randn(batch_size, graph_size, INIT_ARGS['input_dim'])
# h_pos_in: (batch_size, graph_size, input_dim)
h_pos_in = torch.randn(batch_size, graph_size, INIT_ARGS['input_dim'])
ARGS = {
'h_node_in': h_node_in,
'h_pos_in': h_pos_in,
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, 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 |
yining043/TSP-improve/nets/attention_model.py code served (permissive licence) · get_code("3e9c7f43e77628ea") 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, 16) 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 torch import nn
import torch.nn.functional as F
import numpy as np
import math
class MultiHeadAttention(nn.Module):
def __init__(self, n_heads, input_dim, embed_dim=None, val_dim=None, key_dim=None):
super(MultiHeadAttention, self).__init__()
if val_dim is None:
assert embed_dim is not None, 'Provide either embed_dim or val_dim'
val_dim = embed_dim // n_heads
if key_dim is None:
key_dim = val_dim
self.n_heads = n_heads
self.input_dim = input_dim
self.embed_dim = embed_dim
self.val_dim = val_dim
self.key_dim = key_dim
self.norm_factor = 1 / math.sqrt(key_dim)
self.W_query = nn.Parameter(torch.Tensor(n_heads, input_dim, key_dim))
self.W_key = nn.Parameter(torch.Tensor(n_heads, input_dim, key_dim))
self.W_val = nn.Parameter(torch.Tensor(n_heads, input_dim, val_dim))
if embed_dim is not None:
self.W_out = nn.Parameter(torch.Tensor(n_heads, key_dim, embed_dim))
self.init_parameters()
def init_parameters(self):
for param in self.parameters():
stdv = 1.0 / math.sqrt(param.size(-1))
param.data.uniform_(-stdv, stdv)
def forward(self, q, h=None, mask=None):
"""
:param q: queries (batch_size, n_query, input_dim)
:param h: data (batch_size, graph_size, input_dim)
:param mask: mask (batch_size, n_query, graph_size) or viewable as that (i.e. can be 2 dim if n_query == 1)
Mask should contain 1 if attention is not possible (i.e. mask is negative adjacency)
:return:
"""
if h is None:
h = q
batch_size, graph_size, input_dim = h.size()
n_query = q.size(1)
assert q.size(0) == batch_size
assert q.size(2) == input_dim
assert input_dim == self.input_dim, 'Wrong embedding dimension of input'
hflat = h.contiguous().view(-1, input_dim)
qflat = q.contiguous().view(-1, input_dim)
shp = (self.n_heads, batch_size, graph_size, -1)
shp_q = (self.n_heads, batch_size, n_query, -1)
Q = torch.matmul(qflat, self.W_query).view(shp_q)
K = torch.matmul(hflat, self.W_key).view(shp)
V = torch.matmul(hflat, self.W_val).view(shp)
compatibility = self.norm_factor * torch.matmul(Q, K.transpose(2, 3))
if mask is not None:
mask = mask.view(1, batch_size, n_query, graph_size).expand_as(compatibility)
compatibility[mask] = -np.inf
attn = F.softmax(compatibility, dim=-1)
if mask is not None:
attnc = attn.clone()
attnc[mask] = 0
attn = attnc
heads = torch.matmul(attn, V)
out = torch.mm(heads.permute(1, 2, 0, 3).contiguous().view(-1, self.n_heads * self.val_dim), self.W_out.view(-1, self.embed_dim)).view(batch_size, n_query, self.embed_dim)
return out
INIT_ARGS = {
'n_heads': 2,
'input_dim': 8,
'embed_dim': 16,
'val_dim': None,
'key_dim': None,
}
ARGS = {
'q': torch.randn(2, 3, 8),
'h': torch.randn(2, 5, 8),
'mask': None,
}
if __name__ == '__main__':
model = MultiHeadAttention(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Expected shape: (2, 3, 16)")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, 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, 16) — shape (2, 3, 16) 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)
|
| MultiHeadCompat |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("211b65805e3d00f5") 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 4, dtype family float, shape (2, 2, 3, 5) 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 torch import nn
import math
class MultiHeadCompat(nn.Module):
def __init__(self, n_heads, input_dim, embed_dim=None, val_dim=None, key_dim=None):
super(MultiHeadCompat, self).__init__()
if val_dim is None:
val_dim = embed_dim // n_heads
if key_dim is None:
key_dim = val_dim
self.n_heads = n_heads
self.input_dim = input_dim
self.embed_dim = embed_dim
self.val_dim = val_dim
self.key_dim = key_dim
self.norm_factor = 1 / math.sqrt(1 * key_dim)
self.W_query = nn.Parameter(torch.Tensor(n_heads, input_dim, key_dim))
self.W_key = nn.Parameter(torch.Tensor(n_heads, input_dim, key_dim))
self.init_parameters()
def init_parameters(self):
for param in self.parameters():
stdv = 1.0 / math.sqrt(param.size(-1))
param.data.uniform_(-stdv, stdv)
def forward(self, q, h=None, mask=None):
if h is None:
h = q
batch_size, graph_size, input_dim = h.size()
n_query = q.size(1)
hflat = h.contiguous().view(-1, input_dim)
qflat = q.contiguous().view(-1, input_dim)
shp = (self.n_heads, batch_size, graph_size, -1)
shp_q = (self.n_heads, batch_size, n_query, -1)
Q = torch.matmul(qflat, self.W_query).view(shp_q)
K = torch.matmul(hflat, self.W_key).view(shp)
compatibility = torch.matmul(Q, K.transpose(2, 3))
return self.norm_factor * compatibility
INIT_ARGS = {
'n_heads': 2,
'input_dim': 4,
'embed_dim': 8,
'val_dim': 4,
'key_dim': 4,
}
ARGS = {
'q': torch.randn(2, 3, 4),
'h': torch.randn(2, 5, 4),
'mask': None,
}
if __name__ == '__main__':
model = MultiHeadCompat(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output: {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 4, dtype family float, shape (2, 2, 3, 5) — shape (2, 2, 3, 5) 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)
|
| MultiHeadDecoder |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("30b971afd000a522") 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. 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 numpy as np
from torch import nn
# INIT_ARGS for MultiHeadDecoder
INIT_ARGS = {
'n_heads': 2,
'input_dim': 4,
'embed_dim': 8,
'val_dim': None,
'key_dim': 4
}
# ARGS for MultiHeadDecoder.forward
batch_size = 2
graph_size = 3
dim = INIT_ARGS['embed_dim']
h_em = torch.randn(batch_size, graph_size, dim)
pos_em = torch.randn(batch_size, graph_size, dim)
solving_state_for_net = None # Not used in forward, so can be None
ARGS = {
'h_em': h_em,
'pos_em': pos_em,
'solving_state_for_net': solving_state_for_net
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, 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)
|
| MultiHeadDecoder |
Ran ran on a synthesized input |
yining043/TSP-improve/nets/attention_model.py code served (permissive licence) · get_code("5b8ea40ba7cb0c66") 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
from torch import nn
import torch.nn.functional as F
import numpy as np
import math
class MockProblem:
"""Mock problem class that provides get_swap_mask method"""
def __init__(self, graph_size):
self.graph_size = graph_size
def get_swap_mask(self, rec):
"""Return a mask for diagonal/invalid swaps"""
batch_size = rec.size(0)
mask = torch.zeros(batch_size, self.graph_size, self.graph_size)
for i in range(batch_size):
for j in range(self.graph_size):
mask[i, j, j] = 1.0
return mask
class MultiHeadDecoder(nn.Module):
def __init__(self, problem, input_dim, embed_dim=None, val_dim=None, key_dim=None):
super(MultiHeadDecoder, self).__init__()
self.problem = problem
self.n_heads = 1
if val_dim is None:
assert embed_dim is not None, 'Provide either embed_dim or val_dim'
val_dim = embed_dim // self.n_heads
if key_dim is None:
key_dim = val_dim
self.input_dim = input_dim
self.embed_dim = embed_dim
self.val_dim = val_dim
self.key_dim = key_dim
self.norm_factor = 1 / math.sqrt(key_dim)
self.W_query = nn.Parameter(torch.Tensor(self.n_heads, input_dim, key_dim))
self.W_key = nn.Parameter(torch.Tensor(self.n_heads, input_dim, key_dim))
self.init_parameters()
def init_parameters(self):
for param in self.parameters():
stdv = 1.0 / math.sqrt(param.size(-1))
param.data.uniform_(-stdv, stdv)
def forward(self, q, exchange, rec):
"""
:param q: queries (batch_size, n_query, input_dim)
:param exchange: (batch_size, 2)
:return:
"""
h = q
batch_size, graph_size, input_dim = h.size()
n_query = q.size(1)
assert q.size(0) == batch_size
assert q.size(2) == input_dim
assert input_dim == self.input_dim, 'Wrong embedding dimension of input'
hflat = h.contiguous().view(-1, input_dim)
qflat = q.contiguous().view(-1, input_dim)
shp = (self.n_heads, batch_size, graph_size, -1)
shp_q = (self.n_heads, batch_size, n_query, -1)
Q = torch.matmul(qflat, self.W_query).view(shp_q)
K = torch.matmul(hflat, self.W_key).view(shp)
compatibility_raw = self.norm_factor * torch.matmul(Q, K.transpose(2, 3))
compatibility = torch.tanh(compatibility_raw[0]) * 10.0
mask_dia = self.problem.get_swap_mask(rec).expand_as(compatibility)
compatibility[mask_dia.bool()] = -np.inf
if exchange is not None:
compatibility[torch.arange(batch_size), exchange[:, 0], exchange[:, 1]] = -np.inf
compatibility[torch.arange(batch_size), exchange[:, 1], exchange[:, 0]] = -np.inf
im = compatibility.view(batch_size, -1)
im_log_soft = F.log_softmax(im, dim=-1)
im_soft = F.softmax(im, dim=-1)
return (im_log_soft, im_soft)
# Setup configuration
input_dim = 4
embed_dim = 8
graph_size = 3
batch_size = 2
problem = MockProblem(graph_size)
INIT_ARGS = {
'problem': problem,
'input_dim': input_dim,
'embed_dim': embed_dim,
'val_dim': None,
'key_dim': None,
}
ARGS = {
'q': torch.randn(batch_size, graph_size, input_dim),
'exchange': torch.tensor([[0, 1], [1, 2]]),
'rec': torch.zeros(batch_size, graph_size),
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, 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)
|
| Normalization |
Ran ran on a synthesized input |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("08bc67177889a2b3") 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
from torch import nn
import math
class Normalization(nn.Module):
def __init__(self, embed_dim, normalization='batch'):
super(Normalization, self).__init__()
normalizer_class = {'batch': nn.BatchNorm1d, 'instance': nn.InstanceNorm1d}.get(normalization, None)
self.normalization = normalization
if not self.normalization == 'layer':
self.normalizer = normalizer_class(embed_dim, affine=True)
def init_parameters(self):
for name, param in self.named_parameters():
stdv = 1.0 / math.sqrt(param.size(-1))
param.data.uniform_(-stdv, stdv)
def forward(self, input):
if self.normalization == 'layer':
return (input - input.mean((1, 2)).view(-1, 1, 1)) / torch.sqrt(input.var((1, 2)).view(-1, 1, 1) + 1e-05)
if isinstance(self.normalizer, nn.BatchNorm1d):
return self.normalizer(input.view(-1, input.size(-1))).view(*input.size())
elif isinstance(self.normalizer, nn.InstanceNorm1d):
return self.normalizer(input.permute(0, 2, 1)).permute(0, 2, 1)
else:
assert self.normalizer is None, 'Unknown normalizer type'
return input
INIT_ARGS = {
'embed_dim': 4,
'normalization': 'batch'
}
ARGS = {
'input': torch.randn(2, 3, 4)
}
if __name__ == '__main__':
model = Normalization(**INIT_ARGS)
output = model(**ARGS)
print(output.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 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)
|
| Actor |
Not yet run unverified (harvested, no recorded run) |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("c62ea025f6578059") How it ran |
| AttentionModel |
Not yet run unverified (harvested, no recorded run) |
yining043/TSP-improve/nets/attention_model.py code served (permissive licence) · get_code("afcbe0b62b04095b") How it ran |
| EmbeddingNet |
Not yet run unverified (harvested, no recorded run) |
yining043/TSP-improve/nets/attention_model.py code served (permissive licence) · get_code("5a3c7c6596133237") How it ran |
| MultiHeadAttentionLayer |
Not yet run unverified (harvested, no recorded run) |
yining043/TSP-improve/nets/attention_model.py code served (permissive licence) · get_code("1905f5c7465accec") How it ran |
| MultiHeadAttentionsubLayer |
Not yet run unverified (harvested, no recorded run) |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("500395d982e1b1bb") How it ran |
| MultiHeadEncoder |
Not yet run unverified (harvested, no recorded run) |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("8147e91b3d0fe9f1") How it ran |
| mySequential |
Not yet run unverified (harvested, no recorded run) |
yining043/VRP-DACT/nets/actor_network.py code served (permissive licence) · get_code("b48a3565db4b5491") How it ran |