| BN2DND |
Ran ran on a synthesized input |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("706813ea88c4046c") 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 BatchNorm2d. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
from torch import nn
class NDModule:
@property
def n(self):
raise NotImplementedError
def check_compat(self, m: nn.Module) -> bool:
raise NotImplementedError
def mirror_nth_member(self, idx: int, other):
raise NotImplementedError
def get_nth_member(self, idx: int) -> nn.Module:
raise NotImplementedError
def set_nth_member(self, idx: int, member: nn.Module):
raise NotImplementedError
def unbatch(self):
return [self.get_nth_member(i) for i in range(self.n)]
class BN2DND(nn.BatchNorm2d, NDModule):
def __init__(self, bn2d: nn.BatchNorm2d, n_groups: int):
device = next(bn2d.parameters()).device
dtype = next(bn2d.parameters()).dtype
self.multiplicity = n_groups
super().__init__(bn2d.num_features * n_groups, eps=bn2d.eps, momentum=bn2d.momentum, affine=bn2d.affine, track_running_stats=bn2d.track_running_stats, device=device, dtype=dtype)
nuweights = bn2d.weight.data.repeat(n_groups)
assert nuweights.shape == self.weight.data.shape, 'Something is up with repeating the weights!'
self.weight.data = nuweights
nubias = bn2d.bias.data.repeat(n_groups)
assert nubias.shape == self.bias.data.shape, 'Something is up with repeating the biases!'
self.bias.data = nubias
if bn2d.track_running_stats:
self.running_mean.data = bn2d.running_mean.data.repeat(n_groups)
self.running_var.data = bn2d.running_var.data.repeat(n_groups)
@property
def n(self):
return self.multiplicity
@torch.no_grad()
def check_compat(self, m: nn.Module) -> bool:
if isinstance(m, nn.BatchNorm2d):
return True
else:
return False
@torch.no_grad()
def mirror_nth_member(self, idx: int, other):
n_in = self.num_features // self.n
self.weight.data[n_in * idx:n_in * (idx + 1)] = other.weight.data[n_in * idx:n_in * (idx + 1)]
self.bias.data[n_in * idx:n_in * (idx + 1)] = other.bias.data[n_in * idx:n_in * (idx + 1)]
if self.track_running_stats:
self.running_mean.data[n_in * idx:n_in * (idx + 1)] = other.running_mean.data[n_in * idx:n_in * (idx + 1)]
self.running_var.data[n_in * idx:n_in * (idx + 1)] = other.running_var.data[n_in * idx:n_in * (idx + 1)]
@torch.no_grad()
def get_nth_member(self, idx: int) -> nn.Module:
n_in = self.num_features // self.n
retval = nn.BatchNorm2d(n_in, eps=self.eps, momentum=self.momentum, affine=self.affine, track_running_stats=self.track_running_stats, device=self.weight.data.device, dtype=self.weight.data.dtype)
retval.weight.data = self.weight.data[n_in * idx:n_in * (idx + 1)].clone()
retval.bias.data = self.bias.data[n_in * idx:n_in * (idx + 1)].clone()
if self.track_running_stats:
retval.running_mean.data = self.running_mean.data[n_in * idx:n_in * (idx + 1)].clone()
retval.running_var.data = self.running_var.data[n_in * idx:n_in * (idx + 1)].clone()
return retval
@torch.no_grad()
def set_nth_member(self, idx: int, member: nn.Module):
n_in = self.num_features // self.n
self.weight.data[n_in * idx:n_in * (idx + 1)] = member.weight.data
self.bias.data[n_in * idx:n_in * (idx + 1)] = member.bias.data
if self.track_running_stats:
self.running_mean.data[n_in * idx:n_in * (idx + 1)] = member.running_mean.data
self.running_var.data[n_in * idx:n_in * (idx + 1)] = member.running_var.data
base_bn = nn.BatchNorm2d(4, eps=1e-5, momentum=0.1, affine=True, track_running_stats=True)
INIT_ARGS = {
'bn2d': base_bn,
'n_groups': 3
}
ARGS = {
'idx': 1
}
METHOD = 'get_nth_member'
bn2d_nd = BN2DND(**INIT_ARGS)
result = getattr(bn2d_nd, METHOD)(**ARGS)
print(f"Result type: {type(result)}")
print(f"Result num_features: {result.num_features}")
print(f"BN2DND n property: {bn2d_nd.n}")
- 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 BatchNorm2d — a BatchNorm2d output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a BatchNorm2d 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| Conv2DND |
Ran ran on a synthesized input |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("08a64a462fa9a870") 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 Conv2d. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
from torch import nn
# Define a base Conv2d to wrap
base_conv = nn.Conv2d(
in_channels=4,
out_channels=3,
kernel_size=3,
bias=True,
stride=1,
padding=1,
dilation=1
)
INIT_ARGS = {
'conv': base_conv,
'n_groups': 2
}
# For get_nth_member, we call it with idx=0
ARGS = {
'idx': 0
}
METHOD = 'get_nth_member'
# Construct and call
from torch import nn
from typing import Callable, List, Dict, Union
from abc import ABC, abstractmethod, abstractproperty
class NDModule(ABC):
@property
@abstractmethod
def n(self):
pass
@abstractmethod
def check_compat(self, m: nn.Module) -> bool:
pass
@abstractmethod
def mirror_nth_member(self, idx: int, other):
pass
@abstractmethod
def get_nth_member(self, idx: int) -> nn.Module:
pass
@abstractmethod
def set_nth_member(self, idx: int, member: nn.Module):
pass
def unbatch(self) -> List[nn.Module]:
return [self.get_nth_member_as_linear(i) for i in range(self.n)]
class Conv2DND(nn.Conv2d, NDModule):
def __init__(self, conv: nn.Conv2d, n_groups: int):
device = next(conv.parameters()).device
dtype = next(conv.parameters()).dtype
has_bias = hasattr(conv, 'bias') and conv.bias is not None
self.multiplicity = n_groups
super().__init__(conv.in_channels * n_groups, conv.out_channels * n_groups, conv.kernel_size, bias=has_bias, stride=conv.stride, padding=conv.padding, dilation=conv.dilation, device=device, dtype=dtype, groups=n_groups)
nuweights = conv.weight.data.repeat(n_groups, 1, 1, 1)
assert nuweights.shape == self.weight.data.shape, 'Something is up with repeating the weights!'
self.weight.data = nuweights
if has_bias:
nubias = conv.bias.data.repeat(n_groups)
assert nubias.shape == self.bias.data.shape, 'Something is up with repeating the weights the biases!'
self.bias.data = nubias
@property
def n(self):
return self.multiplicity
def check_compat(self, m: nn.Module) -> bool:
if isinstance(m, nn.Conv2d):
return True
else:
return False
@torch.no_grad()
def mirror_nth_member(self, idx: int, other):
n_in = self.in_channels // self.n
n_out = self.out_channels // self.n
self.weight.data[n_out * idx:n_out * (idx + 1), :, :, :] = other.weight.data[n_out * idx:n_out * (idx + 1), :, :, :]
if hasattr(self, 'bias') and self.bias is not None:
self.bias.data[n_out * idx:n_out * (idx + 1)] = other.bias.data[n_out * idx:n_out * (idx + 1)]
@torch.no_grad()
def get_nth_member(self, idx: int) -> nn.Module:
n_in = self.in_channels // self.n
n_out = self.out_channels // self.n
retval = nn.Conv2d(self.in_channels // self.n, self.out_channels // self.n, self.kernel_size, bias=hasattr(self, 'bias'), stride=self.stride, padding=self.padding, dilation=self.dilation, device=self.weight.data.device, dtype=self.weight.data.dtype)
retval.weight.data = self.weight.data[n_out * idx:n_out * (idx + 1)]
if hasattr(self, 'bias') and self.bias is not None:
retval.bias.data = self.bias.data[n_out * idx:n_out * (idx + 1)]
return retval
@torch.no_grad()
def set_nth_member(self, idx: int, member: nn.Conv2d):
n_in = self.in_channels // self.n
n_out = self.out_channels // self.n
self.weight.data[n_out * idx:n_out * (idx + 1)] = member.weight.data
if hasattr(self, 'bias') and self.bias is not None:
self.bias.data[n_out * idx:n_out * (idx + 1)] = member.bias.data
instance = Conv2DND(**INIT_ARGS)
result = instance.get_nth_member(**ARGS)
- 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 Conv2d — a Conv2d output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Conv2d 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| LinearND |
Ran ran on a synthesized input |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("26ddd38b22c99269") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 2, 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
from torch import nn
# Create a base Linear layer to pass to LinearND
base_linear = nn.Linear(in_features=4, out_features=3, bias=True)
# INIT_ARGS: arguments for LinearND.__init__
INIT_ARGS = {
'linear': base_linear,
'n': 2
}
# ARGS: arguments for forward method
# Input shape should be (batch_size, n, in_features) or (batch_size, n*in_features)
# With n=2 and in_features=4, we create input of shape (2, 2, 4)
ARGS = {
'input': torch.randn(2, 2, 4)
}
# Construct and call the class
from typing import Callable, List, Dict, Union
from abc import ABC, abstractmethod
class NDModule(ABC):
@property
@abstractmethod
def n(self):
pass
@abstractmethod
def check_compat(self, m: nn.Module) -> bool:
pass
@abstractmethod
def mirror_nth_member(self, idx: int, other):
pass
@abstractmethod
def get_nth_member(self, idx: int) -> nn.Module:
pass
@abstractmethod
def set_nth_member(self, idx: int, member: nn.Module):
pass
def unbatch(self) -> List[nn.Module]:
return [self.get_nth_member(i) for i in range(self.n)]
class LinearND(nn.Module, NDModule):
def __init__(self, linear: nn.Linear, n: int) -> None:
super(LinearND, self).__init__()
device = linear.weight.device
dtype = linear.weight.dtype
self.multiplicity = n
self.in_features = linear.in_features
self.out_features = linear.out_features
self.weight = nn.Parameter(linear.weight.data.unsqueeze(0).repeat(n, 1, 1).to(device).to(dtype))
if linear.bias is not None:
self.bias = nn.Parameter(linear.bias.data.unsqueeze(0).repeat(n, 1).to(device).to(dtype))
return
@property
def n(self):
return self.multiplicity
def check_compat(self, m: nn.Module) -> bool:
if isinstance(m, nn.Linear):
return True
else:
return False
@torch.no_grad()
def get_nth_member(self, idx: int) -> nn.Linear:
retval = nn.Linear(self.in_features, self.out_features, bias=hasattr(self, 'bias'))
retval.weight.data = self.weight.data[idx, :, :]
if hasattr(self, 'bias'):
retval.bias.data = self.bias.data[idx, :]
return retval
@torch.no_grad()
def set_nth_member(self, idx: int, member: nn.Linear):
self.weight.data[idx, :, :] = member.weight.data
if hasattr(self, 'bias'):
self.bias.data[idx, :] = member.bias.data
@torch.no_grad()
def mirror_nth_member(self, idx: int, other):
self.weight.data[idx, :, :] = other.weight.data[idx, :, :]
if hasattr(self, 'bias'):
self.bias.data[idx, :] = other.bias.data[idx, :]
def forward(self, input: torch.Tensor) -> torch.Tensor:
if input.ndim == 2:
input = input.reshape(input.shape[0], self.n, -1).transpose(0, 1)
return torch.matmul(input, self.weight.transpose(1, 2)).add(self.bias.unsqueeze(1)) if hasattr(self, 'bias') else torch.matmul(input, self.weight.transpose(1, 2))
# Instantiate and call
instance = LinearND(**INIT_ARGS)
output = instance(**ARGS)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 3, dtype family float, shape (2, 2, 3) — shape (2, 2, 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)
|
| _forward |
Ran ran; our contract draft was wrong, not the code |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("91857222d88bc678") 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 torch
from torch import nn
torch.manual_seed(0)
# Create a simple model
class SimpleModel(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(4, 3)
def forward(self, x):
return self.linear(x)
# Create a simple loss function
loss_fn = nn.MSELoss()
# Create model and move to CPU (default)
model = SimpleModel()
# Create sample input and target tensors
# x: batch_size=2, feature_dim=4
x = torch.randn(2, 4)
# y: batch_size=2, output_dim=3 (matches model output)
y = torch.randn(2, 3)
ARGS = {
'x': x,
'y': y,
'model': model,
'loss': loss_fn,
'device_movements_async': False
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type 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
|
| _forward_result |
Ran ran; our contract draft was wrong, not the code |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("68960454ca149bef") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 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
from torch import nn
torch.manual_seed(0)
# Create a small model
class SimpleModel(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(4, 3)
def forward(self, x):
return self.linear(x)
# Instantiate the model on CPU
model = SimpleModel()
# Create a small input tensor
x = torch.randn(2, 4)
# Define arguments
ARGS = {
'x': x,
'model': model,
'device_movements_async': False
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 2, dtype family float, shape (2, 3) — shape (2, 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: none by the harness; any seed is in the setup block
|
| batch_output_for_ce_loss_computation |
Ran ran; our contract draft was wrong, not the code |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("27a0f5aa23396728") 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 Tensor, ndim 3, dtype family float, shape (4, 3, 2) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
torch.manual_seed(0)
# The function takes a tensor and permutes its dimensions from (0, 1, 2) to (1, 2, 0)
# For a typical batch output used in CE loss computation:
# - dimension 0 is batch size
# - dimension 1 is number of classes
# - dimension 2 is sequence length (or spatial dimension)
# We'll create a small tensor with distinct sizes for each dimension
output = torch.randn(2, 4, 3) # batch=2, classes=4, sequence_length=3
ARGS = {
"output": output
}
- 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 Tensor, ndim 3, dtype family float, shape (4, 3, 2) — shape (4, 3, 2) as a later run recorded it
- dtype family
- int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
|
| feed_batch_model_image_multiple |
Ran ran; our contract draft was wrong, not the code |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("79b796e77278df4c") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 4, dtype family float, shape (2, 15, 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
torch.manual_seed(0)
# Create a small image tensor
# Shape: (batch_size=2, channels=3, height=4, width=4)
img = torch.randn(2, 3, 4, 4)
# Number of models to repeat for
n_models = 5
ARGS = {
"img": img,
"n_models": n_models,
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type Tensor, ndim 4, dtype family float, shape (2, 15, 4, 4) — shape (2, 15, 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: none by the harness; any seed is in the setup block
|
| feed_batch_model_vector_data |
Ran ran; our contract draft was wrong, not the code |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("375d7ff0eb5b12ce") 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 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
torch.manual_seed(0)
# Create a small vector data tensor
# Shape: (batch_size=2, vector_dim=4)
vd = torch.randn(2, 4)
# Number of models to expand to
n_models = 3
ARGS = {
"vd": vd,
"n_models": n_models,
}
- 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 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: none by the harness; any seed is in the setup block
|
| ModelBatchedCELoss |
Not yet run unverified (harvested, no recorded run) |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("6f835ba0e01b2840") How it ran |
| NDModule |
Not yet run unverified (harvested, no recorded run) |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("b45f2865111fc2a0") How it ran |
| batch_target_for_ce_loss_computation |
Not yet run unverified (harvested, no recorded run) |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("3b8baf6ab55b878c") How it ran |
| batch_that_net |
Not yet run unverified (harvested, no recorded run) |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("a3c6cc2ebe0a4249") How it ran |
| predict_quam |
Not yet run unverified (harvested, no recorded run) |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("149d4c9ec5226399") How it ran |
| set_submodule |
Not yet run unverified (harvested, no recorded run) |
ml-jku/quam/source/methods/quam.py code served (permissive licence) · get_code("eeb07bae5055e8a0") How it ran |