Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# for k in range(size):
# rev_conv_1x1 = layers[size - k - 1][1]
# rev_x, _ = rev_conv_1x1(rev_x)
# error = cf.mean(abs(x - rev_x))
# print("lu_1x1:", error)
# affine coupling layer
params = glow.nn.additive_coupling.Parameters(
channels_x=channels_x // 2, channels_h=128)
params.to_gpu()
params.conv_1(x[:, 0::2])
params.conv_1.W.data = xp.random.uniform(
-1.0, 1.0, size=params.conv_1.W.data.shape).astype("float32")
params.conv_2.W.data = xp.random.uniform(
-1.0, 1.0, size=params.conv_2.W.data.shape).astype("float32")
params.conv_3.W.data = xp.random.uniform(
-1.0, 1.0, size=params.conv_3.W.data.shape).astype("float32")
params.scale.data = xp.random.uniform(
-1.0, 1.0, size=params.scale.data.shape).astype("float32")
nonlinear_mapping = glow.nn.additive_coupling.NonlinearMapping(params)
coupling_layer = glow.nn.additive_coupling.AdditiveCoupling(
nn=nonlinear_mapping)
rev_coupling_layer = coupling_layer.reverse_copy()
y = x
for _ in range(size):
y, _ = coupling_layer(y)
rev_x = y
for _ in range(size):
rev_x, _ = rev_coupling_layer(rev_x)
error = cf.mean(abs(x - rev_x))
print("coupling:", error)
def test_backward1(self):
n, c, h, w = 1, 5, 16, 16
ksize, stride, pad = 2, 2, 0
x = np.random.randn(n, c, h, w).astype('f') * 100
f = lambda x: F.pooling_simple(x, ksize, stride, pad)
self.assertTrue(gradient_check(f, x))
def test_backward1(self):
n, c, h, w = 1, 5, 16, 16
ksize, stride, pad = 2, 2, 0
x = np.random.randn(n, c, h, w).astype('f') * 1000
f = lambda x: F.pooling(x, ksize, stride, pad)
self.assertTrue(gradient_check(f, x))
def test_25(self):
N = 16
Nd = 5
Cs = 3
K = 2
M = 4
D = cp.random.randn(Nd, Nd, M)
s = cp.random.randn(N, N, Cs, K)
lmbda = 1e-1
try:
b = cbpdn.ConvBPDNMaskDcpl(D, s, lmbda)
b.solve()
except Exception as e:
print(e)
assert 0
def test_copy_multigpu(self, dtype, order):
with cuda.Device(0):
src = cupy.random.uniform(-1, 1, (2, 3)).astype(dtype)
with cuda.Device(1):
dst = src.copy(order)
testing.assert_allclose(src, dst, rtol=0, atol=0)
def test_randn_invalid_argument(self):
with self.assertRaises(TypeError):
random.randn(1, 2, 3, unnecessary='unnecessary_argument')
def test_forward2(self):
n, c, h, w = 1, 5, 15, 15
o, k, s, p = 8, (3, 3), (3, 1), (2, 1)
x = np.random.randn(n, c, h, w).astype('f')
W = np.random.randn(o, c, k[0], k[1]).astype('f')
b = None
y = F.conv2d_simple(x, W, b, s, p)
expected = CF.convolution_2d(x, W, b, s, p)
self.assertTrue(array_allclose(expected.data, y.data))
def main():
np.random.seed(0)
try:
import cupy
cupy.random.seed(0)
except Exception:
pass
option2id, all_guesses = load_quizbowl()
train_iter = QuestionIterator(all_guesses[c.BUZZER_TRAIN_FOLD], option2id,
batch_size=128, make_vector=dense_vector0)
dev_iter = QuestionIterator(all_guesses[c.BUZZER_DEV_FOLD], option2id,
batch_size=128, make_vector=dense_vector0)
devtest_iter = QuestionIterator(all_guesses['test'], option2id,
batch_size=128, make_vector=dense_vector0)
expo_iter = QuestionIterator(all_guesses['expo'], option2id,
batch_size=128, make_vector=dense_vector0)
n_hidden = 300
model_name = 'neo_0'
model_dir = 'output/buzzer/neo/{}.npz'.format(model_name)