| is_scalar |
Ran ran, violated the contract we drafted |
VainF/Torch-Pruning/torch_pruning/_helpers.py code served (permissive licence) · get_code("915b7da0362eb2b4") 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 bool, ndim 0, dtype family float, shape () 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 numbers import Number
torch.manual_seed(0)
# The function is_scalar takes a single parameter 'x' and checks if it's a scalar
# It returns True for:
# - torch.Tensor with shape length 0 (scalar tensor)
# - Number instances
# It returns False for lists, tuples, and other types
ARGS = {
"x": torch.tensor(5.0) # A scalar tensor (0-dimensional)
}
- 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 bool, ndim 0, dtype family float, shape () — shape () 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
|
| load_state_dict |
Ran ran on a synthesized input |
VainF/Torch-Pruning/torch_pruning/serialization.py code served (permissive licence) · get_code("44927cfc49a45803") 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 SimpleModel. 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
torch.manual_seed(0)
# Create a simple model with some custom attributes
class SimpleModel(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(4, 3)
self.custom_attr = 42
self.custom_str = "test"
self.custom_list = [1, 2, 3]
model = SimpleModel()
# Create a state_dict by calling the state_dict function
def state_dict(model: torch.nn.Module):
""" Returns a dictionary containing the state, attributions of a module.
"""
full_state_dict = {}
attributions = {}
for name, module in model.named_modules():
full_state_dict[name] = module.__dict__.copy()
module_attr = {}
for attr_name in dir(module):
attr_value = getattr(module, attr_name)
if attr_name == 'T_destination':
continue
if not callable(attr_value) and (not attr_name.startswith('__')) and (not attr_name.startswith('_')):
if not isinstance(attr_value, torch.nn.Parameter) and (not isinstance(attr_value, torch.Tensor)):
module_attr[attr_name] = attr_value
attributions[name] = module_attr
return {'full_state_dict': full_state_dict, 'attributions': attributions}
# Generate the state dict from the model
captured_state = state_dict(model)
# Create a fresh model to load the state into
fresh_model = SimpleModel()
ARGS = {
'model': fresh_model,
'state_dict': captured_state
}
- 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 SimpleModel — a SimpleModel output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a SimpleModel 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
|
| module2type |
Ran ran on a synthesized input |
VainF/Torch-Pruning/torch_pruning/ops.py code served (permissive licence) · get_code("499a656713eb0e7a") 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 OPTYPE. 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
from enum import IntEnum
torch.manual_seed(0)
class _CustomizedOp(nn.Module):
def __init__(self, op_class):
super().__init__()
self.op_cls = op_class
def __repr__(self):
return 'CustomizedOp({})'.format(str(self.op_cls))
class _ConcatOp(nn.Module):
def __init__(self, id):
super(_ConcatOp, self).__init__()
self.offsets = None
self.concat_sizes = None
self.id = id
def __repr__(self):
return '_ConcatOp_{}({})'.format(self.id, self.offsets)
class _SplitOp(nn.Module):
def __init__(self, id):
super(_SplitOp, self).__init__()
self.offsets = None
self.split_sizes = None
self.id = id
def __repr__(self):
return '_SplitOp_{}({})'.format(self.id, self.offsets)
class _UnbindOp(nn.Module):
def __init__(self, id):
super(_UnbindOp, self).__init__()
self.offsets = None
self.split_sizes = None
self.id = id
def __repr__(self):
return '_UnbindOp_{}({})'.format(self.id, self.offsets)
class _ReshapeOp(nn.Module):
def __init__(self, id):
super(_ReshapeOp, self).__init__()
self.id = id
def __repr__(self):
return '_Reshape_{}()'.format(self.id)
class _ExpandOp(nn.Module):
def __init__(self, id):
super(_ExpandOp, self).__init__()
self.id = id
def __repr__(self):
return '_ExpandOp_{}()'.format(self.id)
class _OutputOp(nn.Module):
def __init__(self, id, shape=None):
super(_OutputOp, self).__init__()
self.id = id
self.shape = list(shape) if shape is not None else None
def __repr__(self):
return '_OutputOp_{}({})'.format(self.id, self.shape if self.shape is not None else 'None')
class FakeGradFn:
def __init__(self):
self._saved_start = 0
self._saved_end = 4
self._saved_step = 1
self._saved_dim = 0
class _SliceOp(nn.Module):
def __init__(self, id, grad_fn):
super(_SliceOp, self).__init__()
self.grad_fn = grad_fn
self.id = id
self.start = grad_fn._saved_start
self.end = grad_fn._saved_end
self.step = grad_fn._saved_step
self.dim = grad_fn._saved_dim
def __repr__(self):
return '_Slice_{}()'.format(self.id)
# Test with a Conv2d module
conv_module = nn.Conv2d(3, 16, kernel_size=3)
linear_module = nn.Linear(10, 5)
bn_module = nn.BatchNorm2d(16)
prelu_module = nn.PReLU()
concat_op = _ConcatOp(0)
split_op = _SplitOp(1)
ln_module = nn.LayerNorm(8)
embed_module = nn.Embedding(100, 16)
customized_op = _CustomizedOp(nn.ReLU)
gn_module = nn.GroupNorm(4, 16)
in_module = nn.InstanceNorm2d(16)
reshape_op = _ReshapeOp(2)
unbind_op = _UnbindOp(3)
expand_op = _ExpandOp(4)
fake_grad_fn = FakeGradFn()
slice_op = _SliceOp(5, fake_grad_fn)
output_op = _OutputOp(6, shape=[2, 4, 8])
elementwise_module = nn.ReLU()
ARGS = {
"module": conv_module
}
- 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 OPTYPE — a OPTYPE output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a OPTYPE output the recorded ndim 0 and dtype family int 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
|
| state_dict |
Ran ran on a synthesized input |
VainF/Torch-Pruning/torch_pruning/serialization.py code served (permissive licence) · get_code("f8d1be76d0300bbf") 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 dict. 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
torch.manual_seed(0)
# Create a simple model with some parameters and attributes
class SimpleModel(nn.Module):
def __init__(self):
super().__init__()
self.linear1 = nn.Linear(4, 3)
self.linear2 = nn.Linear(3, 2)
self.custom_attr = "test_attribute"
self.custom_number = 42
self.custom_list = [1, 2, 3]
def forward(self, x):
x = self.linear1(x)
x = self.linear2(x)
return x
model = SimpleModel()
ARGS = {
'model': model
}
- 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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
|
| to_plain_idxs |
Ran ran on a synthesized input |
VainF/Torch-Pruning/torch_pruning/_helpers.py code served (permissive licence) · get_code("a5f40ecfcfcbe7c1") 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 int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import numpy as np
from collections import namedtuple
class _HybridIndex(namedtuple('_PruingIndex', ['idx', 'root_idx'])):
""" A tuple of (idx, root_idx) where idx is the index of the pruned dimension in the current layer,
and root_idx is the index of the pruned dimension in the root layer.
"""
def __repr__(self):
return str((self.idx, self.root_idx))
# Test case 1: Empty list
empty_idxs = []
# Test case 2: List of _HybridIndex objects
hybrid_idxs = [
_HybridIndex(idx=0, root_idx=5),
_HybridIndex(idx=1, root_idx=6),
_HybridIndex(idx=2, root_idx=7),
]
# Test case 3: List of plain indices (not _HybridIndex)
plain_idxs = [0, 1, 2, 3]
ARGS = {
"idxs": hybrid_idxs
}
- Setup block drafted by
- a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
- Imports
- numpy, torch — 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 int — 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
|
| to_root_idxs |
Ran ran on a synthesized input |
VainF/Torch-Pruning/torch_pruning/_helpers.py code served (permissive licence) · get_code("b4c2def331fc3065") 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 int; 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
from collections import namedtuple
class _HybridIndex(namedtuple('_PruingIndex', ['idx', 'root_idx'])):
""" A tuple of (idx, root_idx) where idx is the index of the pruned dimension in the current layer,
and root_idx is the index of the pruned dimension in the root layer.
"""
def __repr__(self):
return str((self.idx, self.root_idx))
def to_root_idxs(idxs: _HybridIndex):
if len(idxs) == 0 or not isinstance(idxs[0], _HybridIndex):
return idxs
return [i.root_idx for i in idxs]
# Setup code
torch.manual_seed(0)
# Test case 1: non-empty list of _HybridIndex objects
hybrid_indices = [
_HybridIndex(idx=0, root_idx=5),
_HybridIndex(idx=1, root_idx=7),
_HybridIndex(idx=2, root_idx=3),
]
ARGS = {
"idxs": hybrid_indices
}
- 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 list, ndim 2, dtype family int — 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
|
| type2class |
Ran ran on a synthesized input |
VainF/Torch-Pruning/torch_pruning/ops.py code served (permissive licence) · get_code("33b3f48ffee9c0cd") 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 type. 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
from enum import IntEnum
torch.manual_seed(0)
class OPTYPE(IntEnum):
CONV = 0
BN = 1
LINEAR = 2
PRELU = 3
DEPTHWISE_CONV = 4
CONCAT = 5
SPLIT = 6
CUSTOMIZED = 7
ELEMENTWISE = 8
LN = 9
EMBED = 10
PARAMETER = 11
MHA = 12
LSTM = 13
RESHAPE = 14
GN = 15
IN = 16
UNBIND = 17
EXPAND = 18
SLICE = 19
OUTPUT = 20
TORCH_CONV = nn.modules.conv._ConvNd
TORCH_BATCHNORM = nn.modules.batchnorm._BatchNorm
TORCH_LAYERNORM = nn.modules.normalization.LayerNorm
TORCH_GROUPNORM = nn.GroupNorm
TORCH_INSTANCENORM = nn.modules.instancenorm._InstanceNorm
TORCH_PRELU = nn.PReLU
TORCH_LINEAR = nn.Linear
TORCH_EMBED = nn.Embedding
TORCH_PARAMETER = nn.Parameter
TORCH_LSTM = nn.LSTM
class _CustomizedOp(nn.Module):
def __init__(self, op_class):
super().__init__()
self.op_cls = op_class
def __repr__(self):
return 'CustomizedOp({})'.format(str(self.op_cls))
class _ConcatOp(nn.Module):
def __init__(self, id):
super(_ConcatOp, self).__init__()
self.offsets = None
self.concat_sizes = None
self.id = id
def __repr__(self):
return '_ConcatOp_{}({})'.format(self.id, self.offsets)
class _SplitOp(nn.Module):
def __init__(self, id):
super(_SplitOp, self).__init__()
self.offsets = None
self.split_sizes = None
self.id = id
def __repr__(self):
return '_SplitOp_{}({})'.format(self.id, self.offsets)
class _UnbindOp(nn.Module):
def __init__(self, id):
super(_UnbindOp, self).__init__()
self.offsets = None
self.split_sizes = None
self.id = id
def __repr__(self):
return '_UnbindOp_{}({})'.format(self.id, self.offsets)
class _ReshapeOp(nn.Module):
def __init__(self, id):
super(_ReshapeOp, self).__init__()
self.id = id
def __repr__(self):
return '_Reshape_{}()'.format(self.id)
class MockGradFn:
def __init__(self):
self._saved_start = 0
self._saved_end = 2
self._saved_step = 1
self._saved_dim = 0
class _SliceOp(nn.Module):
def __init__(self, id, grad_fn):
super(_SliceOp, self).__init__()
self.grad_fn = grad_fn
self.id = id
self.start = grad_fn._saved_start
self.end = grad_fn._saved_end
self.step = grad_fn._saved_step
self.dim = grad_fn._saved_dim
def __repr__(self):
return '_Slice_{}()'.format(self.id)
class _OutputOp(nn.Module):
def __init__(self, id, shape=None):
super(_OutputOp, self).__init__()
self.id = id
self.shape = list(shape) if shape is not None else None
def __repr__(self):
return '_OutputOp_{}({})'.format(self.id, self.shape if self.shape is not None else 'None')
class _ElementWiseOp(nn.Module):
def __init__(self, id, grad_fn):
super(_ElementWiseOp, self).__init__()
self._grad_fn = grad_fn
self.id = id
def __repr__(self):
return '_ElementWiseOp_{}({})'.format(self.id, self._grad_fn)
class _ExpandOp(nn.Module):
def __init__(self, id):
super(_ExpandOp, self).__init__()
self.id = id
def __repr__(self):
return '_ExpandOp_{}()'.format(self.id)
ARGS = {
"op_type": OPTYPE.CONV
}
- 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 type — a type output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a type 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
|