Update examples to new API
MODIFY
examples/efficientnet.py
examples/efficientnet.py
@@ -38,7 +38,7 @@ def infer(model, img):
# run the net
if GPU:
- out = model.forward(Tensor(img).cuda()).cpu()
+ out = model.forward(Tensor(img).gpu()).cpu()
else:
out = model.forward(Tensor(img))
@@ -55,7 +55,7 @@ if __name__ == "__main__":
model = EfficientNet(int(os.getenv("NUM", "0")))
model.load_weights_from_torch()
if GPU:
- [x.cuda_() for x in get_parameters(model)]
+ [x.gpu_() for x in get_parameters(model)]
# category labels
import ast

MODIFY
examples/mnist_gan.py
examples/mnist_gan.py
@@ -65,7 +65,7 @@ if __name__ == "__main__":
ds_noise = Tensor(np.random.randn(64,128).astype(np.float32), gpu=GPU, requires_grad=False)
n_steps = int(train_data_size/batch_size)
if GPU:
- [x.cuda_() for x in generator_params+discriminator_params]
+ [x.gpu_() for x in generator_params+discriminator_params]
# optimizers
optim_g = optim.Adam(generator_params,lr=0.0002, b1=0.5) # 0.0002 for equilibrium!
optim_d = optim.Adam(discriminator_params,lr=0.0002, b1=0.5)

MODIFY
examples/serious_mnist.py
examples/serious_mnist.py
@@ -85,7 +85,7 @@ class BigConvNet:
try:
par.cpu().data[:] = np.load(f)
if GPU:
- par.cuda()
+ par.gpu()
except:
print('Could not load parameter')
@@ -126,7 +126,7 @@ if __name__ == "__main__":
if GPU:
params = get_parameters(model)
- [x.cuda_() for x in params]
+ [x.gpu_() for x in params]
for lr, epochs in zip(lrs, epochss):
optimizer = optim.Adam(model.parameters(), lr=lr)

Update examples to new API (#205)