Skip to content

Commit

Permalink
modify code for suporting older versions of pytorch
Browse files Browse the repository at this point in the history
  • Loading branch information
brandontrabucco committed Aug 26, 2021
1 parent b95b554 commit 449f918
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ The goal of model-based optimization is to find an input **x** that maximizes an
Design-Bench can be installed with the complete set of benchmarks via our pip package.

```bash
pip install design-bench[all]==2.0.12
pip install design-bench[all]==2.0.13
pip install morphing-agents==1.5.1
```

Alternatively, if you do not have MuJoCo, you may opt for a minimal install.

```bash
pip install design-bench==2.0.12
pip install design-bench==2.0.13
```

## Available Tasks
Expand Down
25 changes: 21 additions & 4 deletions design_bench/oracles/exact/cifar_nas_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
Design-Bench Maintainer: Brandon Trabucco
"""

import functools
import operator

import torch
import torch.nn as nn
import torch.optim as optim
Expand Down Expand Up @@ -42,10 +45,24 @@ def __init__(self, config):
kernel_size2 = kernel_sizes[config[2]]
activation2 = activations[config[3]]

# the next lines are to compensate for how older versions of
# pytorch do not natively support padding=same
padding1 = (kernel_size1 // 2 + (kernel_size1 - 2 * (
kernel_size1 // 2)) - 1, kernel_size1 // 2,
kernel_size1 // 2 + (kernel_size1 - 2 * (
kernel_size1 // 2)) - 1, kernel_size1 // 2)

padding2 = (kernel_size2 // 2 + (kernel_size2 - 2 * (
kernel_size2 // 2)) - 1, kernel_size2 // 2,
kernel_size2 // 2 + (kernel_size2 - 2 * (
kernel_size2 // 2)) - 1, kernel_size2 // 2)

self.network = nn.Sequential(
nn.Conv2d(32, 32, kernel_size1, padding='same'),
nn.ZeroPad2d(padding1),
nn.Conv2d(32, 32, kernel_size1),
activation1(),
nn.Conv2d(32, 32, kernel_size2, padding='same'),
nn.ZeroPad2d(padding2),
nn.Conv2d(32, 32, kernel_size2),
activation2(),
nn.MaxPool2d(3, stride=1, padding=1)
)
Expand All @@ -65,8 +82,8 @@ def __init__(self, config):
for i in range(0, len(config), n_params):
configs.append(config[i:i + n_params])

layers = []
layers.append(nn.Conv2d(3, 32, 3, padding='same'))
layers = [nn.ZeroPad2d((1, 1, 1, 1)),
nn.Conv2d(3, 32, 3)]

for config in configs:
layers.append(Block(config))
Expand Down

0 comments on commit 449f918

Please sign in to comment.