MCPcopy Create free account
hub / github.com/pytorch/examples / __init__

Method __init__

distributed/rpc/parameter_server/rpc_parameter_server.py:19–41  ·  view source on GitHub ↗
(self, num_gpus=0)

Source from the content-addressed store, hash-verified

17
18class Net(nn.Module):
19 def __init__(self, num_gpus=0):
20 super(Net, self).__init__()
21 print(f"Using {num_gpus} GPUs to train")
22 self.num_gpus = num_gpus
23 if torch.accelerator.is_available() and self.num_gpus > 0:
24 acc = torch.accelerator.current_accelerator()
25 device = torch.device(f'{acc}:0')
26 else:
27 device = torch.device("cpu")
28 print(f"Putting first 2 convs on {str(device)}")
29 # Put conv layers on the first accelerator device
30 self.conv1 = nn.Conv2d(1, 32, 3, 1).to(device)
31 self.conv2 = nn.Conv2d(32, 64, 3, 1).to(device)
32 # Put rest of the network on the 2nd accelerator device, if there is one
33 if torch.accelerator.is_available() and self.num_gpus > 0:
34 acc = torch.accelerator.current_accelerator()
35 device = torch.device(f'{acc}:1')
36
37 print(f"Putting rest of layers on {str(device)}")
38 self.dropout1 = nn.Dropout2d(0.25).to(device)
39 self.dropout2 = nn.Dropout2d(0.5).to(device)
40 self.fc1 = nn.Linear(9216, 128).to(device)
41 self.fc2 = nn.Linear(128, 10).to(device)
42
43 def forward(self, x):
44 x = self.conv1(x)

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected