| CoAttentionTransformerEncoderLayer |
Ran ran on a synthesized input |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("fa672e2c394eb841") 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 (3, 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
import torch.nn as nn
import torch.nn.functional as F
from torch import Tensor
from typing import Optional
def _get_activation_fn(activation):
if activation == 'relu':
return F.relu
elif activation == 'gelu':
return F.gelu
raise ValueError('activation should be relu/gelu, not {}'.format(activation))
class CoAttentionTransformerEncoderLayer(nn.Module):
def __init__(self, d_model, nhead, dim_feedforward=2048, dropout=0.1, activation='relu'):
super(CoAttentionTransformerEncoderLayer, self).__init__()
self.self_attn = nn.MultiheadAttention(d_model, nhead, dropout=dropout)
self.linear1 = nn.Linear(d_model, dim_feedforward)
self.dropout = nn.Dropout(dropout)
self.linear2 = nn.Linear(dim_feedforward, d_model)
self.norm1 = nn.LayerNorm(d_model)
self.norm2 = nn.LayerNorm(d_model)
self.dropout1 = nn.Dropout(dropout)
self.dropout2 = nn.Dropout(dropout)
self.activation = _get_activation_fn(activation)
def __setstate__(self, state):
if 'activation' not in state:
state['activation'] = F.relu
super(CoAttentionTransformerEncoderLayer, self).__setstate__(state)
def forward(self, src: Tensor, src_: Tensor, src_mask: Optional[Tensor]=None, src_key_padding_mask: Optional[Tensor]=None) -> Tensor:
"""Pass the input through the encoder layer.
Args:
src: the sequence to the encoder layer (required).
src_: the sequence to the encoder layer (required).
src_mask: the mask for the src sequence (optional).
src_key_padding_mask: the mask for the src keys per batch (optional).
Shape:
see the docs in Transformer class.
"""
src2 = self.self_attn(src, src_, src_, attn_mask=src_mask, key_padding_mask=src_key_padding_mask)[0]
src = src + self.dropout1(src2)
src = self.norm1(src)
src2 = self.linear2(self.dropout(self.activation(self.linear1(src))))
src = src + self.dropout2(src2)
src = self.norm2(src)
return src
INIT_ARGS = {
'd_model': 4,
'nhead': 2,
'dim_feedforward': 8,
'dropout': 0.1,
'activation': 'relu'
}
ARGS = {
'src': torch.randn(3, 2, 4),
'src_': torch.randn(3, 2, 4),
'src_mask': None,
'src_key_padding_mask': None
}
if __name__ == '__main__':
model = CoAttentionTransformerEncoderLayer(**INIT_ARGS)
output = model(**ARGS)
print("Output shape:", output.shape)
print("Test passed!")
- 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 (3, 2, 4) — shape (3, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| MCCFormerEncoderS |
Ran ran on a synthesized input |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("182ed251c7d9568d") 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 math
import torch
import torch.nn as nn
from torch import Tensor
class PositionalEncoding(nn.Module):
"""
Learnable position embeddings
Args:
pe_type (str): type of position embeddings,
which is chosen from ['fully_learnable', 'sinusoidal']
d_model (int): embed dim (required).
max_len (int): max. length of the incoming sequence (default=5000).
Examples:
>>> pos_encoder = PositionalEncoding(d_model, max_len=100)
"""
def __init__(self, pe_type: str, d_model: int, max_len: int=5000):
super(PositionalEncoding, self).__init__()
if pe_type == 'fully_learnable':
self.pe = nn.parameter.Parameter(torch.randn(max_len, 1, d_model))
elif pe_type == 'sinusoidal':
pe = torch.zeros(max_len, d_model)
position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
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).transpose(0, 1)
self.register_buffer('pe', pe)
else:
raise RuntimeError('PE type should be fully_learnable/sinusoidal, not {}'.format(pe_type))
def forward(self, x: Tensor) -> Tensor:
"""
Args:
x (Tensor): the sequence fed to the positional encoder model [L, N, C]
Returns:
output (Tensor): position embeddings [L, N, C]
"""
return x + self.pe[:x.size(0)]
class MCCFormerEncoderS(nn.Module):
"""
Attributes:
linear (nn.Module): linear layer to create input feature from CNN feature
feature_extractor (Optional[nn.Module]): feature extractor
positional_encoding (nn.Module): positional encoder (default: 'learnable')
transformer (nn.Module): transformer encoder layer
"""
def __init__(self, feature_dim: int, encoder_dim: int, feature_extractor = None, image_size: int=14, nhead: int=4, transformer_layer_num: int=2):
super(MCCFormerEncoderS, self).__init__()
self.image_size = image_size
self.feature_extractor = feature_extractor
self.linear = nn.Conv2d(feature_dim, encoder_dim, kernel_size=1)
self.positional_encoding = PositionalEncoding('fully_learnable', encoder_dim, 2 * image_size ** 2)
encoder_layer = nn.TransformerEncoderLayer(d_model=encoder_dim, nhead=nhead, dim_feedforward=4 * encoder_dim, batch_first=False)
self.transformer = nn.TransformerEncoder(encoder_layer, num_layers=transformer_layer_num)
def forward(self, x1: Tensor, x2: Tensor) -> Tensor:
"""
Args:
x1 (Tensor): visual feature at t1 shape of [N, 3, H, W]
x2 (Tensor): visual feature at t2 shape of [N, 3, H, W]
Returns:
outputs (Tensor): output feature shape of [H'xW', N, 2C]
"""
N = len(x1)
features = torch.cat([x1, x2], dim=0)
if self.feature_extractor is not None:
features = self.feature_extractor(features)
features = self.linear(features).flatten(start_dim=2).permute(2, 0, 1)
features = torch.cat([features[:, :N], features[:, N:]], dim=0)
features = self.positional_encoding(features)
features = self.transformer(features)
before_features, after_features = (features[:self.image_size ** 2], features[self.image_size ** 2:])
return torch.cat([before_features, after_features], dim=2)
INIT_ARGS = {
'feature_dim': 4,
'encoder_dim': 8,
'feature_extractor': None,
'image_size': 3,
'nhead': 2,
'transformer_layer_num': 2,
}
ARGS = {
'x1': torch.randn(2, 4, 3, 3),
'x2': torch.randn(2, 4, 3, 3),
}
if __name__ == '__main__':
model = MCCFormerEncoderS(**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 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)
|
| MCCFormers_S |
Ran ran on a synthesized input · constructed an object; no result was computed |
cvpaperchallenge/Describing-and-Localizing-Multiple-Change-with-Transformers/code/models_trans.py pointer only (licence: NONE) · get_code("8e99499938b1efd9") How it ranThe body of this sample is withheld: GitHub detected no licence in this paper's repository, cvpaperchallenge/Describing-and-Localizing-Multiple-Change-with-Transformers when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded. |
| PositionalEncoding |
Ran ran on a synthesized input |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("58f682ef650d89c8") 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 (3, 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 math
import torch
import torch.nn as nn
from torch import Tensor
class PositionalEncoding(nn.Module):
"""
Learnable position embeddings
Args:
pe_type (str): type of position embeddings,
which is chosen from ['fully_learnable', 'sinusoidal']
d_model (int): embed dim (required).
max_len (int): max. length of the incoming sequence (default=5000).
Examples:
>>> pos_encoder = PositionalEncoding(d_model, max_len=100)
"""
def __init__(self, pe_type: str, d_model: int, max_len: int=5000):
super(PositionalEncoding, self).__init__()
if pe_type == 'fully_learnable':
self.pe = nn.parameter.Parameter(torch.randn(max_len, 1, d_model))
elif pe_type == 'sinusoidal':
pe = torch.zeros(max_len, d_model)
position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
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).transpose(0, 1)
self.register_buffer('pe', pe)
else:
raise RuntimeError('PE type should be fully_learnable/sinusoidal, not {}'.format(pe_type))
def forward(self, x: Tensor) -> Tensor:
"""
Args:
x (Tensor): the sequence fed to the positional encoder model [L, N, C]
Returns:
output (Tensor): position embeddings [L, N, C]
"""
return x + self.pe[:x.size(0)]
INIT_ARGS = {
'pe_type': 'sinusoidal',
'd_model': 4,
'max_len': 10
}
ARGS = {
'x': torch.randn(3, 2, 4)
}
if __name__ == '__main__':
model = PositionalEncoding(**INIT_ARGS)
output = model(**ARGS)
print("Output shape:", output.shape)
print("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 3, dtype family float, shape (3, 2, 4) — shape (3, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| SimpleEncoder |
Ran ran on a synthesized input |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("25103b8f0df4d9c2") 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 (25, 2, 6) 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 math
import torch
import torch.nn as nn
from torch import Tensor
class PositionalEncoding(nn.Module):
"""
Learnable position embeddings
Args:
pe_type (str): type of position embeddings,
which is chosen from ['fully_learnable', 'sinusoidal']
d_model (int): embed dim (required).
max_len (int): max. length of the incoming sequence (default=5000).
Examples:
>>> pos_encoder = PositionalEncoding(d_model, max_len=100)
"""
def __init__(self, pe_type: str, d_model: int, max_len: int=5000):
super(PositionalEncoding, self).__init__()
if pe_type == 'fully_learnable':
self.pe = nn.parameter.Parameter(torch.randn(max_len, 1, d_model))
elif pe_type == 'sinusoidal':
pe = torch.zeros(max_len, d_model)
position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
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).transpose(0, 1)
self.register_buffer('pe', pe)
else:
raise RuntimeError('PE type should be fully_learnable/sinusoidal, not {}'.format(pe_type))
def forward(self, x: Tensor) -> Tensor:
"""
Args:
x (Tensor): the sequence fed to the positional encoder model [L, N, C]
Returns:
output (Tensor): position embeddings [L, N, C]
"""
return x + self.pe[:x.size(0)]
class SimpleEncoder(nn.Module):
def __init__(self, feature_dim, encoder_dim, image_size=14):
super(SimpleEncoder, self).__init__()
self.linear = nn.Conv2d(feature_dim, encoder_dim, kernel_size=1)
self.positional_encoding = PositionalEncoding('fully_learnable', 2 * encoder_dim, image_size ** 2)
def forward(self, x1: Tensor, x2: Tensor) -> Tensor:
"""
Args:
x1 (Tensor): visual feature at t1 shape of [N, 3, H, W]
x2 (Tensor): visual feature at t2 shape of [N, 3, H, W]
Returns:
outputs (Tensor): output feature shape of [H'xW', N, 2C]
"""
return self.positional_encoding(torch.cat([self.linear(x1).flatten(start_dim=2).permute(2, 0, 1), self.linear(x2).flatten(start_dim=2).permute(2, 0, 1)], dim=2))
INIT_ARGS = {
'feature_dim': 4,
'encoder_dim': 3,
'image_size': 5,
}
ARGS = {
'x1': torch.randn(2, 4, 5, 5),
'x2': torch.randn(2, 4, 5, 5),
}
if __name__ == '__main__':
model = SimpleEncoder(**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 3, dtype family float, shape (25, 2, 6) — shape (25, 2, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| _get_activation_fn |
Ran ran; our contract draft was wrong, not the code |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("25f24e4d230ced80") 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 function. 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
torch.manual_seed(0)
ARGS = {
'activation': 'relu'
}
- 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 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
|
| CoAttentionTransformerEncoder |
Not yet run unverified (harvested, no recorded run) |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("a8899349acbad648") How it ran |
| MCCFormer |
Not yet run unverified (harvested, no recorded run) |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("986e31d80012b44f") How it ran |
| MCCFormerEncoderD |
Not yet run unverified (harvested, no recorded run) |
doiken23/mccformers.pytorch/models/model.py code served (permissive licence) · get_code("c3103140b48208b9") How it ran |