def deny_moving(): a = nn.Linear(1, 1) b = nn.Linear(1, 1) model = nn.Sequential(a, b) model = Pipe(model, [1, 1], style=Pipe.MultiProcess, worker_map=get_worker_map()) model.cuda() model.cpu() model.to(torch.device("cuda")) model.to(0) model.to("cuda") model.to(device=0) model.to(torch.rand(1)) model.to(tensor=torch.rand(1)) # Casting is allowed. model.half() model.to(torch.double) model.to(dtype=torch.float)
def test_deny_moving(): a = nn.Linear(1, 1) b = nn.Linear(1, 1) model = nn.Sequential(a, b) model = Pipe(model, [1, 1], devices=["cpu", "cpu"]) # Moving is denied. with pytest.raises(TypeError): model.cuda() with pytest.raises(TypeError): model.cpu() with pytest.raises(TypeError): model.to(torch.device("cuda")) with pytest.raises(TypeError): model.to(0) with pytest.raises(TypeError): model.to("cuda") with pytest.raises(TypeError): model.to(device=0) with pytest.raises(TypeError): model.to(torch.rand(1)) with pytest.raises(TypeError): model.to(tensor=torch.rand(1)) # Casting is allowed. model.half() model.to(torch.double) model.to(dtype=torch.float)