| Attend |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("360e36fe7ea92c19") 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; 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 collections import namedtuple
from torch import einsum
from functools import wraps
from packaging import version
AttentionConfig = namedtuple('AttentionConfig', ['enable_flash', 'enable_math', 'enable_mem_efficient'])
def once(fn):
called = False
@wraps(fn)
def inner(x):
nonlocal called
if called:
return
called = True
return fn(x)
return inner
print_once = once(print)
class Attend(nn.Module):
def __init__(self, dropout=0.0, flash=False):
super().__init__()
self.dropout = dropout
self.attn_dropout = nn.Dropout(dropout)
self.flash = flash
assert not (flash and version.parse(torch.__version__) < version.parse('2.0.0')), 'in order to use flash attention, you must be using pytorch 2.0 or above'
self.cpu_config = AttentionConfig(True, True, True)
self.cuda_config = None
if not torch.cuda.is_available() or not flash:
return
device_properties = torch.cuda.get_device_properties(torch.device('cuda'))
if device_properties.major == 8 and device_properties.minor == 0:
print_once('A100 GPU detected, using flash attention if input tensor is on cuda')
self.cuda_config = AttentionConfig(True, False, False)
else:
print_once('Non-A100 GPU detected, using math or mem efficient attention if input tensor is on cuda')
self.cuda_config = AttentionConfig(False, True, True)
def flash_attn(self, q, k, v):
_, heads, q_len, _, k_len, is_cuda, device = (*q.shape, k.shape[-2], q.is_cuda, q.device)
q, k, v = map(lambda t: t.contiguous(), (q, k, v))
config = self.cuda_config if is_cuda else self.cpu_config
with torch.backends.cuda.sdp_kernel(**config._asdict()):
out = F.scaled_dot_product_attention(q, k, v, dropout_p=self.dropout if self.training else 0.0)
return out
def forward(self, q, k, v):
"""
einstein notation
b - batch
h - heads
n, i, j - sequence length (base sequence length, source, target)
d - feature dimension
"""
q_len, k_len, device = (q.shape[-2], k.shape[-2], q.device)
if self.flash:
return self.flash_attn(q, k, v)
scale = q.shape[-1] ** (-0.5)
sim = einsum(f'b h i d, b h j d -> b h i j', q, k) * scale
attn = sim.softmax(dim=-1)
attn = self.attn_dropout(attn)
out = einsum(f'b h i j, b h j d -> b h i d', attn, v)
return out
INIT_ARGS = {
'dropout': 0.1,
'flash': False,
}
ARGS = {
'q': torch.randn(2, 3, 4, 5),
'k': torch.randn(2, 3, 6, 5),
'v': torch.randn(2, 3, 6, 5),
}
if __name__ == '__main__':
model = Attend(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Expected shape: (2, 3, 4, 5)")
assert output.shape == (2, 3, 4, 5), f"Shape mismatch: {output.shape}"
print("Test passed!")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- packaging, 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 — 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)
|
| Attention |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("dfac04afda97fe38") 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, 16, 4, 3) 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 torch.nn.functional as F
from collections import namedtuple
from einops import rearrange, reduce, repeat
from torch import nn, einsum
from functools import wraps
from packaging import version
class Attend(nn.Module):
def __init__(self, dropout=0.0, flash=False):
super().__init__()
self.dropout = dropout
self.attn_dropout = nn.Dropout(dropout)
self.flash = flash
assert not (flash and version.parse(torch.__version__) < version.parse('2.0.0')), 'in order to use flash attention, you must be using pytorch 2.0 or above'
self.cpu_config = AttentionConfig(True, True, True)
self.cuda_config = None
if not torch.cuda.is_available() or not flash:
return
device_properties = torch.cuda.get_device_properties(torch.device('cuda'))
if device_properties.major == 8 and device_properties.minor == 0:
print_once('A100 GPU detected, using flash attention if input tensor is on cuda')
self.cuda_config = AttentionConfig(True, False, False)
else:
print_once('Non-A100 GPU detected, using math or mem efficient attention if input tensor is on cuda')
self.cuda_config = AttentionConfig(False, True, True)
def flash_attn(self, q, k, v):
_, heads, q_len, _, k_len, is_cuda, device = (*q.shape, k.shape[-2], q.is_cuda, q.device)
q, k, v = map(lambda t: t.contiguous(), (q, k, v))
config = self.cuda_config if is_cuda else self.cpu_config
with torch.backends.cuda.sdp_kernel(**config._asdict()):
out = F.scaled_dot_product_attention(q, k, v, dropout_p=self.dropout if self.training else 0.0)
return out
def forward(self, q, k, v):
"""
einstein notation
b - batch
h - heads
n, i, j - sequence length (base sequence length, source, target)
d - feature dimension
"""
q_len, k_len, device = (q.shape[-2], k.shape[-2], q.device)
if self.flash:
return self.flash_attn(q, k, v)
scale = q.shape[-1] ** (-0.5)
sim = einsum(f'b h i d, b h j d -> b h i j', q, k) * scale
attn = sim.softmax(dim=-1)
attn = self.attn_dropout(attn)
out = einsum(f'b h i j, b h j d -> b h i d', attn, v)
return out
AttentionConfig = namedtuple('AttentionConfig', ['enable_flash', 'enable_math', 'enable_mem_efficient'])
class RMSNorm(nn.Module):
def __init__(self, dim):
super().__init__()
self.g = nn.Parameter(torch.ones(1, dim, 1, 1))
def forward(self, x):
return F.normalize(x, dim=1) * self.g * x.shape[1] ** 0.5
def once(fn):
called = False
@wraps(fn)
def inner(x):
nonlocal called
if called:
return
called = True
return fn(x)
return inner
print_once = once(print)
class Attention(nn.Module):
def __init__(self, dim, heads=4, dim_head=32, flash=False):
super().__init__()
self.heads = heads
hidden_dim = dim_head * heads
self.norm = RMSNorm(dim)
self.attend = Attend(flash=flash)
self.to_qkv = nn.Conv2d(dim, hidden_dim * 3, 1, bias=False)
self.to_out = nn.Conv2d(hidden_dim, dim, 1)
def forward(self, x):
b, c, h, w = x.shape
x = self.norm(x)
qkv = self.to_qkv(x).chunk(3, dim=1)
q, k, v = map(lambda t: rearrange(t, 'b (h c) x y -> b h (x y) c', h=self.heads), qkv)
out = self.attend(q, k, v)
out = rearrange(out, 'b h (x y) d -> b (h d) x y', x=h, y=w)
return self.to_out(out)
INIT_ARGS = {
'dim': 16,
'heads': 2,
'dim_head': 8,
'flash': False
}
ARGS = {
'x': torch.randn(2, 16, 4, 3)
}
if __name__ == '__main__':
model = Attention(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Expected shape: (2, 16, 4, 3)")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- einops, packaging, 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, 16, 4, 3) — shape (2, 16, 4, 3) 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)
|
| Bottleneck |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("f7f588495112f1d3") 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; 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 torch.nn as nn
BatchNorm = nn.BatchNorm2d
class Bottleneck(nn.Module):
expansion = 2
def __init__(self, inplanes, planes, stride=1, dilation=1):
super(Bottleneck, self).__init__()
expansion = Bottleneck.expansion
bottle_planes = planes // expansion
self.conv1 = nn.Conv2d(inplanes, bottle_planes, kernel_size=1, bias=False)
self.bn1 = BatchNorm(bottle_planes)
self.conv2 = nn.Conv2d(bottle_planes, bottle_planes, kernel_size=3, stride=stride, padding=dilation, bias=False, dilation=dilation)
self.bn2 = BatchNorm(bottle_planes)
self.conv3 = nn.Conv2d(bottle_planes, planes, kernel_size=1, bias=False)
self.bn3 = BatchNorm(planes)
self.relu = nn.ReLU(inplace=True)
self.stride = stride
def forward(self, x, residual=None):
if residual is None:
residual = x
out = self.conv1(x)
out = self.bn1(out)
out = self.relu(out)
out = self.conv2(out)
out = self.bn2(out)
out = self.relu(out)
out = self.conv3(out)
out = self.bn3(out)
out += residual
out = self.relu(out)
return out
INIT_ARGS = {
'inplanes': 8,
'planes': 8,
'stride': 1,
'dilation': 1
}
ARGS = {
'x': torch.randn(2, 8, 7, 7)
}
- 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 — 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)
|
| Conv2d |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("9f54fd544c431a89") 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, 4, 8, 8) 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
class Conv2d(nn.Module):
def __init__(self, in_planes, out_planes, kernal_szie=3, stride=1, bias=True):
super(Conv2d, self).__init__()
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=kernal_szie, stride=stride, padding=kernal_szie // 2, bias=bias)
self.bn = nn.BatchNorm2d(out_planes)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x = self.relu(x)
return x
INIT_ARGS = {
'in_planes': 3,
'out_planes': 4,
'kernal_szie': 3,
'stride': 1,
'bias': True,
}
ARGS = {
'x': torch.randn(2, 3, 8, 8),
}
if __name__ == '__main__':
model = Conv2d(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Expected shape: torch.Size([2, 4, 8, 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 4, dtype family float, shape (2, 4, 8, 8) — shape (2, 4, 8, 8) 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)
|
| DLAUp |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("c3a2aeb5e289231e") 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; 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 torch.nn as nn
import math
import numpy as np
class Conv2d(nn.Module):
def __init__(self, in_planes, out_planes, kernal_szie=3, stride=1, bias=True):
super(Conv2d, self).__init__()
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=kernal_szie, stride=stride, padding=kernal_szie // 2, bias=bias)
self.bn = nn.BatchNorm2d(out_planes)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x = self.relu(x)
return x
class IDAUp(nn.Module):
"""
input: features map of different layers
output: up-sampled features
"""
def __init__(self, in_channels_list, up_factors_list, out_channels):
super(IDAUp, self).__init__()
self.in_channels_list = in_channels_list
self.out_channels = out_channels
for i in range(1, len(in_channels_list)):
in_channels = in_channels_list[i]
up_factors = int(up_factors_list[i])
proj = Conv2d(in_channels, out_channels, kernal_szie=3, stride=1, bias=False)
node = Conv2d(out_channels * 2, out_channels, kernal_szie=3, stride=1, bias=False)
up = nn.ConvTranspose2d(in_channels=out_channels, out_channels=out_channels, kernel_size=up_factors * 2, stride=up_factors, padding=up_factors // 2, output_padding=0, groups=out_channels, bias=False)
fill_up_weights(up)
setattr(self, 'proj_' + str(i), proj)
setattr(self, 'up_' + str(i), up)
setattr(self, 'node_' + str(i), node)
for m in self.modules():
if isinstance(m, nn.Conv2d):
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
m.weight.data.normal_(0, math.sqrt(2.0 / n))
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def forward(self, layers):
assert len(self.in_channels_list) == len(layers), '{} vs {} layers'.format(len(self.in_channels_list), len(layers))
for i in range(1, len(layers)):
upsample = getattr(self, 'up_' + str(i))
project = getattr(self, 'proj_' + str(i))
node = getattr(self, 'node_' + str(i))
layers[i] = upsample(project(layers[i]))
layers[i] = node(torch.cat([layers[i - 1], layers[i]], 1))
return layers
def fill_up_weights(up):
w = up.weight.data
f = math.ceil(w.size(2) / 2)
c = (2 * f - 1 - f % 2) / (2.0 * f)
for i in range(w.size(2)):
for j in range(w.size(3)):
w[0, 0, i, j] = (1 - math.fabs(i / f - c)) * (1 - math.fabs(j / f - c))
for c in range(1, w.size(0)):
w[c, 0, :, :] = w[0, 0, :, :]
class DLAUp(nn.Module):
def __init__(self, in_channels_list, scales_list=(1, 2, 4, 8, 16)):
super(DLAUp, self).__init__()
scales_list = np.array(scales_list, dtype=int)
for i in range(len(in_channels_list) - 1):
j = -i - 2
setattr(self, 'ida_{}'.format(i), IDAUp(in_channels_list=in_channels_list[j:], up_factors_list=scales_list[j:] // scales_list[j], out_channels=in_channels_list[j]))
scales_list[j + 1:] = scales_list[j]
in_channels_list[j + 1:] = [in_channels_list[j] for _ in in_channels_list[j + 1:]]
def forward(self, layers):
layers = list(layers)
assert len(layers) > 1
for i in range(len(layers) - 1):
ida = getattr(self, 'ida_{}'.format(i))
layers[-i - 2:] = ida(layers[-i - 2:])
return layers[-1]
INIT_ARGS = {
'in_channels_list': [4, 8, 16],
'scales_list': (1, 2, 4)
}
ARGS = {
'layers': [
torch.randn(2, 4, 8, 8),
torch.randn(2, 8, 4, 4),
torch.randn(2, 16, 2, 2)
]
}
if __name__ == '__main__':
model = DLAUp(**INIT_ARGS)
model.eval()
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
- 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 4, 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)
|
| DepthAwareFE |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("4660642fa4ba3464") 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 numpy as np
# INIT_ARGS for DepthAwareFE.__init__
INIT_ARGS = {
'output_channel_num': 256
}
# ARGS for DepthAwareFE.forward
# The forward method expects x with shape (N, output_channel_num, H, W)
# Based on the code:
# - x has shape (N, 256, H, W) since output_channel_num=256
# - depth_output upsamples by 2x, so if x is (N, 256, H, W), depth becomes (N, 96, 2*H, 2*W)
# - depth_guide is interpolated back to x.size()[2:], so (N, 96, H, W)
# - depth_down reduces 96 channels to 12 channels
# - acf takes (x, depth_guide) where x is (N, 256, H, W) and depth_guide is (N, 12, H, W)
ARGS = {
'x': torch.randn(2, 256, 8, 6) # batch=2, channels=256, height=8, width=6
}
- 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)
|
| IDAUp |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("f6dbf7aa2006b4ba") 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 list. 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
class Conv2d(nn.Module):
def __init__(self, in_planes, out_planes, kernal_szie=3, stride=1, bias=True):
super(Conv2d, self).__init__()
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=kernal_szie, stride=stride, padding=kernal_szie // 2, bias=bias)
self.bn = nn.BatchNorm2d(out_planes)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x = self.relu(x)
return x
def fill_up_weights(up):
w = up.weight.data
f = math.ceil(w.size(2) / 2)
c = (2 * f - 1 - f % 2) / (2.0 * f)
for i in range(w.size(2)):
for j in range(w.size(3)):
w[0, 0, i, j] = (1 - math.fabs(i / f - c)) * (1 - math.fabs(j / f - c))
for c in range(1, w.size(0)):
w[c, 0, :, :] = w[0, 0, :, :]
class IDAUp(nn.Module):
"""
input: features map of different layers
output: up-sampled features
"""
def __init__(self, in_channels_list, up_factors_list, out_channels):
super(IDAUp, self).__init__()
self.in_channels_list = in_channels_list
self.out_channels = out_channels
for i in range(1, len(in_channels_list)):
in_channels = in_channels_list[i]
up_factors = int(up_factors_list[i])
proj = Conv2d(in_channels, out_channels, kernal_szie=3, stride=1, bias=False)
node = Conv2d(out_channels * 2, out_channels, kernal_szie=3, stride=1, bias=False)
up = nn.ConvTranspose2d(in_channels=out_channels, out_channels=out_channels, kernel_size=up_factors * 2, stride=up_factors, padding=up_factors // 2, output_padding=0, groups=out_channels, bias=False)
fill_up_weights(up)
setattr(self, 'proj_' + str(i), proj)
setattr(self, 'up_' + str(i), up)
setattr(self, 'node_' + str(i), node)
for m in self.modules():
if isinstance(m, nn.Conv2d):
n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
m.weight.data.normal_(0, math.sqrt(2.0 / n))
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def forward(self, layers):
assert len(self.in_channels_list) == len(layers), '{} vs {} layers'.format(len(self.in_channels_list), len(layers))
for i in range(1, len(layers)):
upsample = getattr(self, 'up_' + str(i))
project = getattr(self, 'proj_' + str(i))
node = getattr(self, 'node_' + str(i))
layers[i] = upsample(project(layers[i]))
layers[i] = node(torch.cat([layers[i - 1], layers[i]], 1))
return layers
INIT_ARGS = {
'in_channels_list': [8, 16],
'up_factors_list': [2, 2],
'out_channels': 8
}
ARGS = {
'layers': [
torch.randn(2, 8, 4, 4),
torch.randn(2, 16, 2, 2)
]
}
- 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 list — a list 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)
|
| LinearAttention |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("e483acb4ed97bccf") 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, 3, 2, 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.nn import Module, Dropout
def elu_feature_map(x):
return torch.nn.functional.elu(x) + 1
class LinearAttention(Module):
def __init__(self, eps=1e-06):
super().__init__()
self.feature_map = elu_feature_map
self.eps = eps
def forward(self, queries, keys, values):
""" Multi-Head linear attention proposed in "Transformers are RNNs"
Args:
queries: [N, L, H, D]
keys: [N, L, H, D]
values: [N, L, H, D]
Returns:
queried_values: (N, L, H, D)
"""
Q = self.feature_map(queries)
K = self.feature_map(keys)
v_length = values.size(1)
values = values / v_length
KV = torch.einsum('nshd,nshv->nhdv', K, values)
Z = 1 / (torch.einsum('nlhd,nhd->nlh', Q, K.sum(dim=1)) + self.eps)
queried_values = torch.einsum('nlhd,nhdv,nlh->nlhv', Q, KV, Z) * v_length
return queried_values.contiguous()
INIT_ARGS = {
'eps': 1e-06
}
ARGS = {
'queries': torch.randn(2, 3, 2, 4),
'keys': torch.randn(2, 3, 2, 4),
'values': torch.randn(2, 3, 2, 5)
}
if __name__ == '__main__':
model = LinearAttention(**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, 3, 2, 5) — shape (2, 3, 2, 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)
|
| RMSNorm |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("234fd6dd12768c7d") 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, 4, 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
import torch.nn as nn
import torch.nn.functional as F
class RMSNorm(nn.Module):
def __init__(self, dim):
super().__init__()
self.g = nn.Parameter(torch.ones(1, dim, 1, 1))
def forward(self, x):
return F.normalize(x, dim=1) * self.g * x.shape[1] ** 0.5
INIT_ARGS = {
'dim': 4
}
ARGS = {
'x': torch.randn(2, 4, 3, 5)
}
if __name__ == '__main__':
model = RMSNorm(**INIT_ARGS)
output = model(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {output.shape}")
print(f"Output:\n{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, 4, 3, 5) — shape (2, 4, 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)
|
| RandomOrLearnedSinusoidalPosEmb |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("49db9b9ea5686382") 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 2, dtype family float, shape (2, 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
import torch.nn as nn
import math
from einops import rearrange, repeat
def divisible_by(numer, denom):
return numer % denom == 0
class RandomOrLearnedSinusoidalPosEmb(nn.Module):
""" following @crowsonkb 's lead with random (learned optional) sinusoidal pos emb """
' https://github.com/crowsonkb/v-diffusion-jax/blob/master/diffusion/models/danbooru_128.py#L8 '
def __init__(self, dim, is_random=False):
super().__init__()
assert divisible_by(dim, 2)
half_dim = dim // 2
self.weights = nn.Parameter(torch.randn(half_dim), requires_grad=not is_random)
def forward(self, x):
x = rearrange(x, 'b -> b 1')
freqs = x * rearrange(self.weights, 'd -> 1 d') * 2 * math.pi
fouriered = torch.cat((freqs.sin(), freqs.cos()), dim=-1)
fouriered = torch.cat((x, fouriered), dim=-1)
return fouriered
INIT_ARGS = {
'dim': 4,
'is_random': False,
}
ARGS = {
'x': torch.randn(2),
}
if __name__ == '__main__':
model = RandomOrLearnedSinusoidalPosEmb(**INIT_ARGS)
output = model(**ARGS)
print(f"Output shape: {output.shape}")
print(f"Output:\n{output}")
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 2, dtype family float, shape (2, 5) — shape (2, 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)
|
| TransDecoderLayer |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("68df791593973dbe") 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 torch.nn as nn
# INIT_ARGS for TransDecoderLayer.__init__
INIT_ARGS = {
'd_model': 8,
'nhead': 2,
'attention': 'linear'
}
# ARGS for TransDecoderLayer.forward
# x: [N, L, C] where C = d_model
# source: [N, L, C] where C = d_model
ARGS = {
'x': torch.randn(2, 5, 8), # batch=2, seq_len=5, d_model=8
'source': torch.randn(2, 7, 8) # batch=2, seq_len=7, d_model=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)
|
| TransEncoderLayer |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("721c301e49b3f514") 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 torch.nn as nn
import numpy as np
def elu_feature_map(x):
return torch.nn.functional.elu(x) + 1
class LinearAttention(nn.Module):
def __init__(self, eps=1e-06):
super().__init__()
self.feature_map = elu_feature_map
self.eps = eps
def forward(self, queries, keys, values):
Q = self.feature_map(queries)
K = self.feature_map(keys)
v_length = values.size(1)
values = values / v_length
KV = torch.einsum('nshd,nshv->nhdv', K, values)
Z = 1 / (torch.einsum('nlhd,nhd->nlh', Q, K.sum(dim=1)) + self.eps)
queried_values = torch.einsum('nlhd,nhdv,nlh->nlhv', Q, KV, Z) * v_length
return queried_values.contiguous()
class TransEncoderLayer(nn.Module):
def __init__(self, d_model=2048, nhead=8, attention='linear'):
super(TransEncoderLayer, self).__init__()
self.dim = d_model // nhead
self.nhead = nhead
self.q_proj = nn.Linear(d_model, d_model, bias=False)
self.k_proj = nn.Linear(d_model, d_model, bias=False)
self.v_proj = nn.Linear(d_model, d_model, bias=False)
self.attention = LinearAttention()
self.merge = nn.Linear(d_model, d_model, bias=False)
self.mlp = nn.Sequential(nn.Linear(d_model, d_model * 2, bias=False), nn.ReLU(True), nn.Linear(d_model * 2, d_model, bias=False))
self.norm1 = nn.LayerNorm(d_model)
self.norm2 = nn.LayerNorm(d_model)
self.drop_path = nn.Identity()
def forward(self, x):
bs = x.size(0)
query, key, value = (x, x, x)
query = self.q_proj(query).view(bs, -1, self.nhead, self.dim)
key = self.k_proj(key).view(bs, -1, self.nhead, self.dim)
value = self.v_proj(value).view(bs, -1, self.nhead, self.dim)
message = self.attention(query, key, value)
message = self.merge(message.view(bs, -1, self.nhead * self.dim))
x = x + self.drop_path(self.norm1(message))
x = x + self.drop_path(self.norm2(self.mlp(x)))
return x
INIT_ARGS = {
'd_model': 16,
'nhead': 4,
'attention': 'linear'
}
ARGS = {
'x': torch.randn(2, 5, 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 — 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)
|
| Tree |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("8862f92d2180b857") 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; 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 torch.nn as nn
# Define a simple block for the Tree
class SimpleBlock(nn.Module):
def __init__(self, in_channels, out_channels, stride=1, dilation=1):
super(SimpleBlock, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=3,
stride=stride, padding=dilation, dilation=dilation, bias=False)
self.bn = nn.BatchNorm2d(out_channels)
self.relu = nn.ReLU(inplace=True)
def forward(self, x, residual=None):
out = self.conv(x)
out = self.bn(out)
if residual is not None:
out += residual
out = self.relu(out)
return out
INIT_ARGS = {
'levels': 2,
'block': SimpleBlock,
'in_channels': 8,
'out_channels': 16,
'stride': 1,
'level_root': False,
'root_dim': 0,
'root_kernel_size': 1,
'dilation': 1,
'root_residual': False
}
ARGS = {
'x': torch.randn(2, 8, 12, 12),
'residual': None,
'children': None
}
- 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 — 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)
|
| WeatherCodebook |
Ran ran on a synthesized input |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("a26331af1d2a725c") 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 numpy as np
# INIT_ARGS for WeatherCodebook.__init__(codebook_dim, feature_dim, channel)
INIT_ARGS = {
'codebook_dim': 8,
'feature_dim': 12,
'channel': 12
}
# ARGS for forward method
# The forward method expects input and optional second_input
# input shape: (batch, channel, height, width)
# When second_input is provided (training mode), both should have same shape
batch_size = 2
height = 4
width = 6
# Test with both training and inference modes
# For training mode (with second_input)
clear_input = torch.randn(batch_size, INIT_ARGS['channel'], height, width)
adverse_input = torch.randn(batch_size, INIT_ARGS['channel'], height, width)
ARGS = {
'input': clear_input,
'second_input': adverse_input
}
- 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)
|
| get_model_url |
Ran ran; our contract draft was wrong, not the code |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("3c9867a84d7c18d9") 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 str. 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 os
ARGS = {
'data': 'imagenet',
'name': 'dla34',
'hash': 'ba72cf86'
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
|
| BasicBlock |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("822bbc27c98772b9") How it ran |
| CrossAttention |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("056357c296407ea2") How it ran |
| DLA |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("66e5d28ac311f7fe") How it ran |
| DepthAwarePosEnc |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("2f1466316451a519") How it ran |
| DepthAwareTransformer |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("1440222618f4b897") How it ran |
| GaussianDiffusion |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("c41056f8a4f34abd") How it ran |
| MonoWAD |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("64099da24b02e2be") How it ran |
| Root |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("0aff889aa4679890") How it ran |
| Unet |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("e275d60eaaba6a01") How it ran |
| dfe_module |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("e28ea7c71f77af75") How it ran |
| dla102 |
Not yet run unverified (harvested, no recorded run) |
VisualAIKHU/MonoWAD/visualDet3D/networks/detectors/MonoWAD.py code served (permissive licence) · get_code("f6223e37e1c97520") How it ran |