Skip to content

Commit a277512

Browse files
authored
loosen input ranges (#46)
* principled tol * switch dtype stuff
1 parent 87cfbe8 commit a277512

73 files changed

Lines changed: 240 additions & 97 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

problems/all-pairs-shortest-path/def.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class all_pairs_shortest_path(Problem):
99
"""All-pairs shortest path problem using Floyd-Warshall algorithm."""
1010

11+
is_exact = True
12+
1113
def __init__(self):
1214
super().__init__(
1315
name="all-pairs-shortest-path"
@@ -23,7 +25,7 @@ def reference_solution(self, adj_matrix: torch.Tensor) -> torch.Tensor:
2325
Returns:
2426
Distance matrix with shortest paths between all pairs of nodes
2527
"""
26-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
28+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=adj_matrix.dtype):
2729
N = adj_matrix.size(0)
2830
device = adj_matrix.device
2931

problems/argmax/def.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class argmax(Problem):
88
"""Argmax over dimension problem."""
99

10+
is_exact = True
11+
1012
def __init__(self):
1113
super().__init__(
1214
name="argmax"
@@ -23,7 +25,7 @@ def reference_solution(self, input_tensor: torch.Tensor, dim: int) -> torch.Tens
2325
Returns:
2426
Result of argmax operation
2527
"""
26-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
28+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_tensor.dtype):
2729
return torch.argmax(input_tensor, dim=dim).to(torch.int32)
2830

2931
def generate_test_cases(self, dtype: torch.dtype) -> List[Dict[str, Any]]:

problems/argmin/def.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class argmin(Problem):
88
"""Argmin over dimension problem."""
99

10+
is_exact = True
11+
1012
def __init__(self):
1113
super().__init__(
1214
name="argmin"
@@ -23,7 +25,7 @@ def reference_solution(self, input_tensor: torch.Tensor, dim: int) -> torch.Tens
2325
Returns:
2426
Result of argmin operation
2527
"""
26-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
28+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_tensor.dtype):
2729
return torch.argmin(input_tensor, dim=dim).to(torch.int32)
2830

2931
def generate_test_cases(self, dtype: torch.dtype) -> List[Dict[str, Any]]:

problems/array-sort/def.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
class array_sort(Problem):
1010
"""General array sorting problem (integer arrays)."""
1111

12+
is_exact = True
13+
1214
def __init__(self):
1315
super().__init__(name="array-sort")
1416

problems/avg-pool-1d/def.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class avg_pool_1d(Problem):
88
"""1D average pooling problem."""
99

10+
is_exact = False
11+
1012
def __init__(self):
1113
super().__init__(
1214
name="avg-pool-1d"
@@ -26,7 +28,7 @@ def reference_solution(self, input_tensor: torch.Tensor, kernel_size: int,
2628
Returns:
2729
Result of average pooling
2830
"""
29-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
31+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_tensor.dtype):
3032
input_reshaped = input_tensor.view(1, 1, input_tensor.size(0))
3133

3234
result = torch.nn.functional.avg_pool1d(
@@ -65,7 +67,7 @@ def generate_test_cases(self, dtype: torch.dtype) -> List[Dict[str, Any]]:
6567
"padding": p,
6668
"create_inputs": lambda size=h, kernel_size=k, stride=s, padding=p, seed=seed, dtype=dtype: (
6769
*(lambda g: (
68-
torch.rand((size), device="cuda", dtype=dtype, generator=g) * 10.0 - 5.0, # uniform [-5, 5]
70+
torch.rand((size), device="cuda", dtype=dtype, generator=g) * 2.0 - 1.0, # uniform [-1, 1]
6971
))(torch.Generator(device="cuda").manual_seed(seed)),
7072
kernel_size,
7173
stride,

problems/avg-pool-2d/def.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class avg_pool_2d(Problem):
88
"""2D average pooling problem."""
99

10+
is_exact = False
11+
1012
def __init__(self):
1113
super().__init__(
1214
name="avg-pool-2d"
@@ -26,7 +28,7 @@ def reference_solution(self, input_tensor: torch.Tensor, kernel_size: int,
2628
Returns:
2729
Result of average pooling
2830
"""
29-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
31+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_tensor.dtype):
3032
input_reshaped = input_tensor.view(1, 1, input_tensor.size(0), input_tensor.size(1))
3133

3234
result = torch.nn.functional.avg_pool2d(
@@ -66,7 +68,7 @@ def generate_test_cases(self, dtype: torch.dtype) -> List[Dict[str, Any]]:
6668
"padding": p,
6769
"create_inputs": lambda h=h, w=w, k=k, s=s, p=p, seed=seed, dtype=dtype: (
6870
*(lambda g: (
69-
torch.rand((h, w), device="cuda", dtype=dtype, generator=g) * 10.0 - 5.0, # uniform [-5, 5]
71+
torch.rand((h, w), device="cuda", dtype=dtype, generator=g) * 2.0 - 1.0, # uniform [-1, 1]
7072
))(torch.Generator(device="cuda").manual_seed(seed)),
7173
k, s, p
7274
)

problems/avg-pool-3d/def.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class avg_pool_3d(Problem):
88
"""3D average pooling problem."""
99

10+
is_exact = False
11+
1012
def __init__(self):
1113
super().__init__(
1214
name="avg-pool-3d"
@@ -26,7 +28,7 @@ def reference_solution(self, input_tensor: torch.Tensor, kernel_size: int,
2628
Returns:
2729
Result of average pooling
2830
"""
29-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
31+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_tensor.dtype):
3032
input_reshaped = input_tensor.view(1, 1, input_tensor.size(0), input_tensor.size(1), input_tensor.size(2))
3133

3234
result = torch.nn.functional.avg_pool3d(
@@ -66,7 +68,7 @@ def generate_test_cases(self, dtype: torch.dtype) -> List[Dict[str, Any]]:
6668
"padding": p,
6769
"create_inputs": lambda h=h, w=w, d=d, k=k, s=s, p=p, seed=seed, dtype=dtype: (
6870
*(lambda g: (
69-
torch.rand((h, w, d), device="cuda", dtype=dtype, generator=g) * 10.0 - 5.0, # uniform [-5, 5]
71+
torch.rand((h, w, d), device="cuda", dtype=dtype, generator=g) * 2.0 - 1.0, # uniform [-1, 1]
7072
))(torch.Generator(device="cuda").manual_seed(seed)),
7173
k, s, p
7274
)

problems/batch-norm/def.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class batch_norm(Problem):
99
"""Batch Normalization problem."""
1010

11+
is_exact = False
12+
1113
def __init__(self):
1214
super().__init__(
1315
name="batch-norm"
@@ -24,7 +26,7 @@ def reference_solution(self, x: torch.Tensor) -> torch.Tensor:
2426
Returns:
2527
torch.Tensor: Output tensor with Batch Normalization applied, same shape as input.
2628
"""
27-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
29+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=x.dtype):
2830
# Create BatchNorm2d layer with no affine parameters and no running stats
2931
bn = nn.BatchNorm2d(
3032
num_features=x.size(1), # F dimension

problems/box-blur/def.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class box_blur(Problem):
99
"""Box blur problem."""
1010

11+
is_exact = False
12+
1113
def __init__(self):
1214
super().__init__(
1315
name="box-blur"
@@ -24,7 +26,7 @@ def reference_solution(self, input_image: torch.Tensor, kernel_size: int) -> tor
2426
Returns:
2527
Blurred image of shape (height, width)
2628
"""
27-
with torch.no_grad():
29+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_image.dtype):
2830
h, w = input_image.shape
2931
pad = kernel_size // 2
3032

problems/conv-1d/def.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class conv_1d(Problem):
88
"""1D convolution problem."""
99

10+
is_exact = False
11+
1012
def __init__(self):
1113
super().__init__(
1214
name="conv-1d"
@@ -23,7 +25,7 @@ def reference_solution(self, input_signal: torch.Tensor, kernel: torch.Tensor) -
2325
Returns:
2426
Result of convolution with zero padding
2527
"""
26-
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=torch.float32):
28+
with torch.no_grad(), torch.autocast("cuda", enabled=False, dtype=input_signal.dtype):
2729
# Ensure kernel size is odd
2830
assert kernel.size(0) % 2 == 1, "Kernel size must be odd"
2931

@@ -69,7 +71,7 @@ def generate_test_cases(self, dtype: torch.dtype) -> List[Dict[str, Any]]:
6971
"kernel_size": kernel_size,
7072
"create_inputs": lambda s=signal_size, k=kernel_size, seed=seed, dtype=dtype: (
7173
*(lambda g: (
72-
torch.rand(s, device="cuda", dtype=dtype, generator=g) * 10.0 - 5.0,
74+
torch.rand(s, device="cuda", dtype=dtype, generator=g) * 2.0 - 1.0,
7375
torch.rand(k, device="cuda", dtype=dtype, generator=g) * 2.0 - 1.0,
7476
))(torch.Generator(device="cuda").manual_seed(seed)),
7577
)

0 commit comments

Comments
 (0)