| AlphaBlender |
Ran ran on a synthesized input |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("ad950c2482098461") 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
# INIT_ARGS for AlphaBlender.__init__
INIT_ARGS = {
'alpha': 0.5,
'merge_strategy': 'learned_with_images',
'rearrange_pattern': 'b t -> (b t) 1 1'
}
# ARGS for AlphaBlender.forward
# For learned_with_images strategy, we need:
# - x_spatial and x_temporal: tensors to blend
# - image_only_indicator: tensor indicating which frames are image-only
#
# Let's use batch=2, time=3, height=4, width=5 for spatial tensors
batch_size = 2
time_steps = 3
height = 4
width = 5
x_spatial = torch.randn(batch_size * time_steps, height, width)
x_temporal = torch.randn(batch_size * time_steps, height, width)
# image_only_indicator should have shape (batch, time) before rearranging
# It indicates which frames are image-only (1.0) vs video frames (0.0)
image_only_indicator = torch.tensor([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]) # shape (2, 3)
ARGS = {
'x_spatial': x_spatial,
'x_temporal': x_temporal,
'image_only_indicator': image_only_indicator
}
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- einops, 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)
|
| Downsample |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("03cbae4dc00dbd28") 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, 4, 3) 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 Downsample(nn.Module):
"""
A downsampling layer with an optional convolution.
:param channels: channels in the inputs and outputs.
:param use_conv: a bool determining if a convolution is applied.
"""
def __init__(self, channels, use_conv):
super().__init__()
self.channels = channels
self.use_conv = use_conv
if use_conv:
self.op = nn.Conv2d(channels, channels, 3, stride=2, padding=1)
else:
self.op = nn.AvgPool2d(2)
def forward(self, x):
assert x.shape[1] == self.channels
return self.op(x)
INIT_ARGS = {
"channels": 4,
"use_conv": True,
}
ARGS = {
"x": torch.randn(2, 4, 8, 6),
}
if __name__ == "__main__":
model = Downsample(**INIT_ARGS)
output = model(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {output.shape}")
print("Success!")
- 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, 4, 3) — shape (2, 4, 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)
|
| Downsample |
Ran ran on a synthesized input |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("3ee1e71fc45df15b") 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, 8, 8, 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 torch as th
import torch.nn as nn
import logging
logging.basicConfig(level=logging.INFO)
def avg_pool_nd(dims, *args, **kwargs):
"""
Create a 1D, 2D, or 3D average pooling module.
"""
if dims == 1:
return nn.AvgPool1d(*args, **kwargs)
elif dims == 2:
return nn.AvgPool2d(*args, **kwargs)
elif dims == 3:
return nn.AvgPool3d(*args, **kwargs)
raise ValueError(f'unsupported dimensions: {dims}')
def conv_nd(dims, *args, **kwargs):
"""
Create a 1D, 2D, or 3D convolution module.
"""
if dims == 1:
return nn.Conv1d(*args, **kwargs)
elif dims == 2:
return nn.Conv2d(*args, **kwargs)
elif dims == 3:
return nn.Conv3d(*args, **kwargs)
raise ValueError(f'unsupported dimensions: {dims}')
logpy = logging.getLogger(__name__)
class Downsample(nn.Module):
"""
A downsampling layer with an optional convolution.
:param channels: channels in the inputs and outputs.
:param use_conv: a bool determining if a convolution is applied.
:param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then
downsampling occurs in the inner-two dimensions.
"""
def __init__(self, channels: int, use_conv: bool, dims: int=2, out_channels=None, padding: int=1, third_down: bool=False):
super().__init__()
self.channels = channels
self.out_channels = out_channels or channels
self.use_conv = use_conv
self.dims = dims
stride = 2 if dims != 3 else (1, 2, 2) if not third_down else (2, 2, 2)
if use_conv:
logpy.info(f'Building a Downsample layer with {dims} dims.')
logpy.info(f' --> settings are: \n in-chn: {self.channels}, out-chn: {self.out_channels}, kernel-size: 3, stride: {stride}, padding: {padding}')
if dims == 3:
logpy.info(f' --> Downsampling third axis (time): {third_down}')
self.op = conv_nd(dims, self.channels, self.out_channels, 3, stride=stride, padding=padding)
else:
assert self.channels == self.out_channels
self.op = avg_pool_nd(dims, kernel_size=stride, stride=stride)
def forward(self, x: th.Tensor) -> th.Tensor:
assert x.shape[1] == self.channels
return self.op(x)
INIT_ARGS = {
'channels': 4,
'use_conv': True,
'dims': 2,
'out_channels': 8,
'padding': 1,
'third_down': False,
}
ARGS = {
'x': th.randn(2, 4, 16, 12),
}
if __name__ == '__main__':
downsample = Downsample(**INIT_ARGS)
output = downsample(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {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 4, dtype family float, shape (2, 8, 8, 6) — shape (2, 8, 8, 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)
|
| LinearQKVAttention |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("5dc3f2495524ee28") 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, 5, 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 math
class LinearQKVAttention(nn.Module):
"""
A module which performs linear QKV attention.
(https://arxiv.org/abs/1812.01243)
"""
def __init__(self, l2_norm_v: bool=False):
super().__init__()
self.l2_norm_v = l2_norm_v
def forward(self, q: torch.Tensor, k: torch.Tensor, v: torch.Tensor):
"""
Args:
q, k, v: (n, ..., l, c) tensors of Queries, Keys, Values. The ...
can be any number of batch dimensions (e.g. heads).
Returns:
res: (n, ..., l, c) tensor after attention.
"""
ch = q.shape[-1]
scale = 1.0 / math.sqrt(ch)
q = q.softmax(dim=-1)
k = k.softmax(dim=-2)
q = q * scale
if self.l2_norm_v:
v = torch.nn.functional.normalize(v, dim=-1)
context = torch.einsum('...nd, ...ne -> ...de', k, v)
res = torch.einsum('...nd, ...de -> ...ne', q, context)
return res
INIT_ARGS = {
'l2_norm_v': False
}
ARGS = {
'q': torch.randn(2, 3, 5, 4),
'k': torch.randn(2, 3, 5, 4),
'v': torch.randn(2, 3, 5, 4)
}
if __name__ == '__main__':
module = LinearQKVAttention(**INIT_ARGS)
output = module(**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
- 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, 5, 4) — shape (2, 3, 5, 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)
|
| Pool2d |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("7340098015ec809d") 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, 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
class Pool2d(nn.Module):
def __init__(self, in_channels: int, out_channels: int, pool_factor: int=2):
super().__init__()
if pool_factor > 1 and pool_factor not in [2, 4, 8]:
raise ValueError(f'Only 1, 2, 4, and 8 are allowed as down-sampling factor, got {pool_factor}')
if pool_factor <= 1:
self.down_conv = nn.Identity()
else:
k = (pool_factor, pool_factor)
self.down_conv = nn.Conv2d(in_channels, out_channels, kernel_size=k, stride=k)
def forward(self, x: torch.Tensor):
return self.down_conv(x)
INIT_ARGS = {
'in_channels': 3,
'out_channels': 16,
'pool_factor': 2
}
ARGS = {
'x': torch.randn(2, 3, 8, 8)
}
if __name__ == '__main__':
model = Pool2d(**INIT_ARGS)
output = model(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {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 4, dtype family float, shape (2, 16, 4, 4) — shape (2, 16, 4, 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)
|
| QKVAttention |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("0bb33f06a6461c7a") 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, 4, 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
import math
INIT_ARGS = {
'efficient_attn': False,
'dropout': 0.1,
}
ARGS = {
'q': torch.randn(2, 3, 4, 8),
'k': torch.randn(2, 3, 4, 8),
'v': torch.randn(2, 3, 4, 8),
}
if __name__ == '__main__':
model = nn.Module()
class QKVAttention(nn.Module):
"""
A module which performs QKV attention.
"""
def __init__(self, efficient_attn: bool=True, dropout: float=0.0):
super().__init__()
self.dropout = dropout
self.efficient_attn = efficient_attn
if self.efficient_attn:
try:
_ = nn.functional.scaled_dot_product_attention
except AttributeError:
print('Please update PyTorch to 2.0 or higher to use efficient attention.')
self.efficient_attn = False
def forward(self, q: torch.Tensor, k: torch.Tensor, v: torch.Tensor):
"""
Args:
q, k, v: (n, ..., l, c) tensors of Queries, Keys, Values. The ...
can be any number of batch dimensions (e.g. heads).
Returns:
res: (n, ..., l, c) tensor after attention.
"""
if self.efficient_attn:
res = nn.functional.scaled_dot_product_attention(q, k, v, dropout_p=self.dropout)
else:
ch = q.shape[-1]
scale = 1.0 / math.sqrt(ch)
dot = torch.einsum('...td, ...kd -> ...tk', q, k) * scale
weight = torch.softmax(dot, dim=-1)
if self.dropout > 0.0:
weight = torch.dropout(weight, p=self.dropout, train=self.training)
res = torch.einsum('...dt, ...tv -> ...dv', weight, v)
return res
attn = QKVAttention(**INIT_ARGS)
output = attn(**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, 4, 8) — shape (2, 3, 4, 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)
|
| ResBlock |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("48e8939cab1b71e2") 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
from abc import abstractmethod
class TimestepBlock(nn.Module):
"""
Any module where forward() takes timestep embeddings as a second argument.
"""
@abstractmethod
def forward(self, x, emb):
"""
Apply the module to `x` given `emb` timestep embeddings.
"""
def zero_module(module):
"""
Zero out the parameters of a module and return it.
"""
for p in module.parameters():
p.detach().zero_()
return module
class ResBlock(TimestepBlock):
"""
A residual block that can optionally change the number of channels.
:param channels: the number of input channels.
:param emb_channels: the number of timestep embedding channels.
:param dropout: the rate of dropout.
:param out_channels: if specified, the number of out channels.
:param use_conv: if True and out_channels is specified, use a spatial
convolution instead of a smaller 1x1 convolution to change the
channels in the skip connection.
"""
def __init__(self, channels, emb_channels, dropout, out_channels=None, use_conv=False, use_scale_shift_norm=False):
super().__init__()
self.channels = channels
self.emb_channels = emb_channels
self.dropout = dropout
self.out_channels = out_channels or channels
self.use_conv = use_conv
self.use_scale_shift_norm = use_scale_shift_norm
self.in_layers = nn.Sequential(nn.GroupNorm(32, channels), nn.SiLU(), nn.Conv2d(channels, self.out_channels, 3, padding=1))
self.emb_layers = nn.Sequential(nn.SiLU(), nn.Linear(emb_channels, 2 * self.out_channels if use_scale_shift_norm else self.out_channels))
self.out_layers = nn.Sequential(nn.GroupNorm(32, self.out_channels), nn.SiLU(), nn.Dropout(p=dropout), zero_module(nn.Conv2d(self.out_channels, self.out_channels, 3, padding=1)))
if self.out_channels == channels:
self.skip_connection = nn.Identity()
elif use_conv:
self.skip_connection = nn.Conv2d(channels, self.out_channels, 3, padding=1)
else:
self.skip_connection = nn.Conv2d(channels, self.out_channels, 1)
def forward(self, x, emb):
"""
Apply the block to a Tensor, conditioned on a timestep embedding.
:param x: an [N x C x ...] Tensor of features.
:param emb: an [N x emb_channels] Tensor of timestep embeddings.
:return: an [N x C x ...] Tensor of outputs.
"""
h = self.in_layers(x)
emb_out = self.emb_layers(emb).type(h.dtype)
while len(emb_out.shape) < len(h.shape):
emb_out = emb_out[..., None]
if self.use_scale_shift_norm:
out_norm, out_rest = (self.out_layers[0], self.out_layers[1:])
scale, shift = torch.chunk(emb_out, 2, dim=1)
h = out_norm(h) * (1 + scale) + shift
h = out_rest(h)
else:
h = h + emb_out
h = self.out_layers(h)
return self.skip_connection(x) + h
INIT_ARGS = {
'channels': 64,
'emb_channels': 128,
'dropout': 0.1,
'out_channels': 96,
'use_conv': True,
'use_scale_shift_norm': False
}
ARGS = {
'x': torch.randn(2, 64, 8, 8),
'emb': torch.randn(2, 128)
}
- 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)
|
| Timestep |
Ran ran on a synthesized input |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("9eb2201b9e41a2d3") 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 (4, 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
import math
from einops import rearrange, repeat
def timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False):
"""
Create sinusoidal timestep embeddings.
:param timesteps: a 1-D Tensor of N indices, one per batch element.
These may be fractional.
:param dim: the dimension of the output.
:param max_period: controls the minimum frequency of the embeddings.
:return: an [N x dim] Tensor of positional embeddings.
"""
if not repeat_only:
half = dim // 2
freqs = torch.exp(-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half).to(device=timesteps.device)
args = timesteps[:, None].float() * freqs[None]
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
if dim % 2:
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
else:
embedding = repeat(timesteps, 'b -> b d', d=dim)
return embedding
class Timestep(nn.Module):
def __init__(self, dim: int):
super().__init__()
self.dim = dim
def forward(self, t: torch.Tensor) -> torch.Tensor:
return timestep_embedding(t, self.dim)
INIT_ARGS = {
'dim': 8
}
ARGS = {
't': torch.tensor([0, 1, 2, 3], dtype=torch.float32)
}
if __name__ == '__main__':
model = Timestep(**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 (4, 8) — shape (4, 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)
|
| UnPool2d |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("8e7f07ae79ee1de0") 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, 10, 12) 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 UnPool2d(nn.Module):
def __init__(self, in_channels: int, out_channels: int, pool_factor: int=2):
super().__init__()
if pool_factor > 1 and pool_factor not in [2, 4, 8]:
raise ValueError(f'Only 1, 2, 4, and 8 are allowed as down-sampling factor, got {pool_factor}')
self.ds_factor = pool_factor
if pool_factor <= 1:
self.up_conv = nn.Identity()
else:
k = (pool_factor, pool_factor)
self.up_conv = nn.ConvTranspose2d(in_channels, out_channels, kernel_size=k, stride=k)
def forward(self, x: torch.Tensor):
return self.up_conv(x)
INIT_ARGS = {
'in_channels': 3,
'out_channels': 4,
'pool_factor': 2
}
ARGS = {
'x': torch.randn(2, 3, 5, 6)
}
if __name__ == '__main__':
model = UnPool2d(**INIT_ARGS)
output = model(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {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 4, dtype family float, shape (2, 4, 10, 12) — shape (2, 4, 10, 12) 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)
|
| Upsample |
Ran ran on a synthesized input |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("63b3160a59e80ddb") 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, 6, 10) 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 Upsample(nn.Module):
"""
An upsampling layer with an optional convolution.
:param channels: channels in the inputs and outputs.
:param use_conv: a bool determining if a convolution is applied.
"""
def __init__(self, channels, use_conv):
super().__init__()
self.channels = channels
self.use_conv = use_conv
if use_conv:
self.conv = nn.Conv2d(channels, channels, 3, padding=1)
def forward(self, x):
assert x.shape[1] == self.channels
import torch.nn.functional as F
x = F.interpolate(x, scale_factor=2, mode='nearest')
if self.use_conv:
x = self.conv(x)
return x
INIT_ARGS = {
'channels': 4,
'use_conv': True,
}
ARGS = {
'x': torch.randn(2, 4, 3, 5),
}
if __name__ == '__main__':
model = Upsample(**INIT_ARGS)
output = model(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {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 4, dtype family float, shape (2, 4, 6, 10) — shape (2, 4, 6, 10) 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)
|
| Upsample |
Ran ran on a synthesized input |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("184b9747aa868755") 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, 8, 12, 10) 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 as th
import torch.nn as nn
import torch.nn.functional as F
def conv_nd(dims, *args, **kwargs):
"""
Create a 1D, 2D, or 3D convolution module.
"""
if dims == 1:
return nn.Conv1d(*args, **kwargs)
elif dims == 2:
return nn.Conv2d(*args, **kwargs)
elif dims == 3:
return nn.Conv3d(*args, **kwargs)
raise ValueError(f'unsupported dimensions: {dims}')
class Upsample(nn.Module):
"""
An upsampling layer with an optional convolution.
:param channels: channels in the inputs and outputs.
:param use_conv: a bool determining if a convolution is applied.
:param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then
upsampling occurs in the inner-two dimensions.
"""
def __init__(self, channels: int, use_conv: bool, dims: int=2, out_channels=None, padding: int=1, third_up: bool=False, kernel_size: int=3, scale_factor: int=2):
super().__init__()
self.channels = channels
self.out_channels = out_channels or channels
self.use_conv = use_conv
self.dims = dims
self.third_up = third_up
self.scale_factor = scale_factor
if use_conv:
self.conv = conv_nd(dims, self.channels, self.out_channels, kernel_size, padding=padding)
def forward(self, x: th.Tensor) -> th.Tensor:
assert x.shape[1] == self.channels
if self.dims == 3:
t_factor = 1 if not self.third_up else self.scale_factor
x = F.interpolate(x, (t_factor * x.shape[2], x.shape[3] * self.scale_factor, x.shape[4] * self.scale_factor), mode='nearest')
else:
x = F.interpolate(x, scale_factor=self.scale_factor, mode='nearest')
if self.use_conv:
x = self.conv(x)
return x
INIT_ARGS = {
'channels': 4,
'use_conv': True,
'dims': 2,
'out_channels': 8,
'padding': 1,
'third_up': False,
'kernel_size': 3,
'scale_factor': 2,
}
ARGS = {
'x': th.randn(2, 4, 6, 5),
}
if __name__ == '__main__':
upsample = Upsample(**INIT_ARGS)
output = upsample(**ARGS)
print(f"Input shape: {ARGS['x'].shape}")
print(f"Output shape: {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 4, dtype family float, shape (2, 8, 12, 10) — shape (2, 8, 12, 10) 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_dictionary |
Ran ran on a synthesized input |
yuchen413/text2image_safety/search_utils.py code served (permissive licence) · get_code("8b2e0a95b5d28430") 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 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 json
import tempfile
import os
import re
# Create temporary directory and mock data files
temp_dir = tempfile.mkdtemp()
data_dir = os.path.join(temp_dir, 'data')
os.makedirs(data_dir, exist_ok=True)
# Create mock vocab.json with some test subwords
vocab_data = {
"hello": 1,
"world": 2,
"test123": 3,
"a": 4,
"ab": 5,
"abc": 6,
"abcd": 7,
"hello_world": 8,
"test-word": 9,
"xyz": 10
}
vocab_path = os.path.join(data_dir, 'vocab.json')
with open(vocab_path, 'w') as f:
json.dump(vocab_data, f)
# Create mock words-google-10000-english-usa-no-swears.json
words_data = {
"the": 1,
"be": 2,
"to": 3,
"of": 4,
"and": 5,
"a": 6,
"in": 7,
"that": 8,
"have": 9,
"i": 10
}
words_path = os.path.join(data_dir, 'words-google-10000-english-usa-no-swears.json')
with open(words_path, 'w') as f:
json.dump(words_data, f)
# Change to temp directory so relative paths work
original_dir = os.getcwd()
os.chdir(temp_dir)
# Define arguments for get_dictionary function
ARGS = {
'len_subword': 5,
'en': False
}
- 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 tuple — a tuple output has no array shape of its own; none is stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| load_data |
Ran ran on a synthesized input |
yuchen413/text2image_safety/search_utils.py code served (permissive licence) · get_code("73a61f7a5d72f3e7") 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 list, ndim 2, 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 tempfile
import os
# Create a temporary file with some test data
temp_file = tempfile.NamedTemporaryFile(mode='w', encoding='utf-8-sig', delete=False, suffix='.txt')
temp_file.write("Hello world\n")
temp_file.write("This is a test\n")
temp_file.write("Another line\n")
temp_file.close()
# Define the arguments dictionary
ARGS = {
'path': temp_file.name
}
- 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 list, ndim 2, dtype family float — a list output has no array shape of its own; none is stated
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| load_nsfw_prompts |
Ran ran on a synthesized input |
yuchen413/text2image_safety/baseline/baseline.py code served (permissive licence) · get_code("b85c3309a7d80fdd") 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 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 tempfile
import os
# Create a temporary file with NSFW prompts
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("prompt1\nprompt2\nprompt3\n")
temp_file.close()
filepath = temp_file.name
ARGS = {
'filepath': filepath
}
- 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 tuple — a tuple output has no array shape of its own; none is stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| BasicTransformerBlock |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("40d8ba71b73d29d4") How it ran |
| CrossAttention |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("75e42984360b91c5") How it ran |
| EfficientUNet |
Not yet run unverified (harvested, no recorded run) |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("173b3ff1d8ad06a9") How it ran |
| MemoryEfficientCrossAttention |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("5cbc6286835eafa2") How it ran |
| ResBlock |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("77ab8d10090cbbae") How it ran |
| SpatialSelfAttention |
Not yet run unverified (harvested, no recorded run) |
compvis/fm-boosting/fmboost/models/unet/model.py code served (permissive licence) · get_code("ffc4ff1275bb5b7d") How it ran |
| SpatialTransformer |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("9778f92ec0ba682d") How it ran |
| SpatialVideoTransformer |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("d0977bbe6d3f1b49") How it ran |
| TimestepBlock |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("579d378f598c87ed") How it ran |
| TimestepEmbedSequential |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("0b73a46bc27e47c6") How it ran |
| UNetModel |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("5c5d69427c0df4ac") How it ran |
| VideoTransformerBlock |
Not yet run unverified (harvested, no recorded run) |
stability-ai/generative-models/sgm/modules/diffusionmodules/openaimodel.py code served (permissive licence) · get_code("54cb1b411b5423e1") How it ran |
| accuracy |
Not yet run unverified (harvested, no recorded run) |
yuchen413/text2image_safety/rl_utils.py code served (permissive licence) · get_code("0cdcae7b2ec00219") How it ran |