-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiny_nerf_pytorch_ddp.py
576 lines (476 loc) · 23.3 KB
/
tiny_nerf_pytorch_ddp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# Import all the good stuff
import argparse
import warnings
from typing import Optional
import os
import numpy as np
import torch
import matplotlib.pyplot as plt
from datetime import datetime
import torch.distributed as dist
import torch.multiprocessing as mp
from torch.nn.parallel import DistributedDataParallel as DDP
import requests
url = 'https://people.eecs.berkeley.edu/~bmild/nerf/tiny_nerf_data.npz'
r = requests.get(url, allow_redirects=True)
warnings.filterwarnings("ignore")
open('tiny_nerf_data.npz', 'wb').write(r.content)
# two helper functions
def meshgrid_xy(tensor1: torch.Tensor, tensor2: torch.Tensor) -> (torch.Tensor, torch.Tensor):
"""Mimick np.meshgrid(..., indexing="xy") in pytorch. torch.meshgrid only allows "ij" indexing.
(If you're unsure what this means, safely skip trying to understand this, and run a tiny example!)
Args:
tensor1 (torch.Tensor): Tensor whose elements define the first dimension of the returned meshgrid.
tensor2 (torch.Tensor): Tensor whose elements define the second dimension of the returned meshgrid.
"""
# TESTED
ii, jj = torch.meshgrid(tensor1, tensor2)
return ii.transpose(-1, -2), jj.transpose(-1, -2)
def cumprod_exclusive(tensor: torch.Tensor) -> torch.Tensor:
r"""Mimick functionality of tf.math.cumprod(..., exclusive=True), as it isn't available in PyTorch.
Args:
tensor (torch.Tensor): Tensor whose cumprod (cumulative product, see `torch.cumprod`) along dim=-1
is to be computed.
Returns:
cumprod (torch.Tensor): cumprod of Tensor along dim=-1, mimiciking the functionality of
tf.math.cumprod(..., exclusive=True) (see `tf.math.cumprod` for details).
"""
# TESTED
# Only works for the last dimension (dim=-1)
dim = -1
# Compute regular cumprod first (this is equivalent to `tf.math.cumprod(..., exclusive=False)`).
cumprod = torch.cumprod(tensor, dim)
# "Roll" the elements along dimension 'dim' by 1 element.
cumprod = torch.roll(cumprod, 1, dim)
# Replace the first element by "1" as this is what tf.cumprod(..., exclusive=True) does.
cumprod[..., 0] = 1.
return cumprod
# generate training data
def get_ray_bundle(height: int, width: int, focal_length: float, tform_cam2world: torch.Tensor):
r"""Compute the bundle of rays passing through all pixels of an image (one ray per pixel).
Args:
height (int): Height of an image (number of pixels).
width (int): Width of an image (number of pixels).
focal_length (float or torch.Tensor): Focal length (number of pixels, i.e., calibrated intrinsics).
tform_cam2world (torch.Tensor): A 6-DoF rigid-body transform (shape: :math:`(4, 4)`) that
transforms a 3D point from the camera frame to the "world" frame for the current example.
Returns:
ray_origins (torch.Tensor): A tensor of shape :math:`(width, height, 3)` denoting the centers of
each ray. `ray_origins[i][j]` denotes the origin of the ray passing through pixel at
row index `j` and column index `i`.
(TODO: double check if explanation of row and col indices convention is right).
ray_directions (torch.Tensor): A tensor of shape :math:`(width, height, 3)` denoting the
direction of each ray (a unit vector). `ray_directions[i][j]` denotes the direction of the ray
passing through the pixel at row index `j` and column index `i`.
(TODO: double check if explanation of row and col indices convention is right).
"""
# TESTED
ii, jj = meshgrid_xy(
torch.arange(width).to(tform_cam2world),
torch.arange(height).to(tform_cam2world)
)
directions = torch.stack([(ii - width * .5) / focal_length,
-(jj - height * .5) / focal_length,
-torch.ones_like(ii)
], dim=-1)
ray_directions = torch.sum(directions[..., None, :] * tform_cam2world[:3, :3], dim=-1)
ray_origins = tform_cam2world[:3, -1].expand(ray_directions.shape)
return ray_origins, ray_directions
def compute_query_points_from_rays(
ray_origins: torch.Tensor,
ray_directions: torch.Tensor,
near_thresh: float,
far_thresh: float,
num_samples: int,
randomize: Optional[bool] = True
) -> (torch.Tensor, torch.Tensor):
r"""Compute query 3D points given the "bundle" of rays. The near_thresh and far_thresh
variables indicate the bounds within which 3D points are to be sampled.
Args:
ray_origins (torch.Tensor): Origin of each ray in the "bundle" as returned by the
`get_ray_bundle()` method (shape: :math:`(width, height, 3)`).
ray_directions (torch.Tensor): Direction of each ray in the "bundle" as returned by the
`get_ray_bundle()` method (shape: :math:`(width, height, 3)`).
near_thresh (float): The 'near' extent of the bounding volume (i.e., the nearest depth
coordinate that is of interest/relevance).
far_thresh (float): The 'far' extent of the bounding volume (i.e., the farthest depth
coordinate that is of interest/relevance).
num_samples (int): Number of samples to be drawn along each ray. Samples are drawn
randomly, whilst trying to ensure "some form of" uniform spacing among them.
randomize (optional, bool): Whether or not to randomize the sampling of query points.
By default, this is set to `True`. If disabled (by setting to `False`), we sample
uniformly spaced points along each ray in the "bundle".
Returns:
query_points (torch.Tensor): Query points along each ray
(shape: :math:`(width, height, num_samples, 3)`).
depth_values (torch.Tensor): Sampled depth values along each ray
(shape: :math:`(num_samples)`).
"""
# TESTED
# shape: (num_samples)
depth_values = torch.linspace(near_thresh, far_thresh, num_samples).to(ray_origins)
if randomize is True:
# ray_origins: (width, height, 3)
# noise_shape = (width, height, num_samples)
noise_shape = list(ray_origins.shape[:-1]) + [num_samples]
# depth_values: (num_samples)
depth_values = depth_values \
+ torch.rand(noise_shape).to(ray_origins) * (far_thresh
- near_thresh) / num_samples
# (width, height, num_samples, 3) = (width, height, 1, 3) + (width, height, 1, 3) * (num_samples, 1)
# query_points: (width, height, num_samples, 3)
query_points = ray_origins[..., None, :] + ray_directions[..., None, :] * depth_values[..., :, None]
# TODO: Double-check that `depth_values` returned is of shape `(num_samples)`.
return query_points, depth_values
def compute_query_points_from_rays_ddp(
ray_origins: torch.Tensor,
ray_directions: torch.Tensor,
near_thresh: float,
far_thresh: float,
num_samples: int,
start_heights: list,
rank: int,
randomize: Optional[bool] = True
) -> (torch.Tensor, torch.Tensor):
r"""Compute query 3D points given the "bundle" of rays. The near_thresh and far_thresh
variables indicate the bounds within which 3D points are to be sampled.
Args:
ray_origins (torch.Tensor): Origin of each ray in the "bundle" as returned by the
`get_ray_bundle()` method (shape: :math:`(width, height, 3)`).
ray_directions (torch.Tensor): Direction of each ray in the "bundle" as returned by the
`get_ray_bundle()` method (shape: :math:`(width, height, 3)`).
near_thresh (float): The 'near' extent of the bounding volume (i.e., the nearest depth
coordinate that is of interest/relevance).
far_thresh (float): The 'far' extent of the bounding volume (i.e., the farthest depth
coordinate that is of interest/relevance).
num_samples (int): Number of samples to be drawn along each ray. Samples are drawn
randomly, whilst trying to ensure "some form of" uniform spacing among them.
randomize (optional, bool): Whether or not to randomize the sampling of query points.
By default, this is set to `True`. If disabled (by setting to `False`), we sample
uniformly spaced points along each ray in the "bundle".
Returns:
query_points (torch.Tensor): Query points along each ray
(shape: :math:`(width, height, num_samples, 3)`).
depth_values (torch.Tensor): Sampled depth values along each ray
(shape: :math:`(num_samples)`).
"""
# TESTED
# shape: (num_samples)
depth_values = torch.linspace(near_thresh, far_thresh, num_samples).to(ray_origins)
if randomize is True:
# ray_origins: (width, height, 3)
# noise_shape = (width, height, num_samples)
noise_shape = list(ray_origins.shape[:-1]) + [num_samples]
# depth_values: (num_samples)
depth_values = depth_values \
+ torch.rand(noise_shape).to(ray_origins) * (far_thresh
- near_thresh) / num_samples
# (width, height, num_samples, 3) = (width, height, 1, 3) + (width, height, 1, 3) * (num_samples, 1)
# query_points: (width, height, num_samples, 3)
query_points = ray_origins[..., None, :] + ray_directions[..., None, :] * depth_values[..., :, None]
# TODO: Double-check that `depth_values` returned is of shape `(num_samples)`.
return query_points[start_heights[rank]: start_heights[rank+1]], depth_values[start_heights[rank]: start_heights[rank+1]]
def render_volume_density(
radiance_field: torch.Tensor,
ray_origins: torch.Tensor,
depth_values: torch.Tensor
) -> (torch.Tensor, torch.Tensor, torch.Tensor):
r"""Differentiably renders a radiance field, given the origin of each ray in the
"bundle", and the sampled depth values along them.
Args:
radiance_field (torch.Tensor): A "field" where, at each query location (X, Y, Z),
we have an emitted (RGB) color and a volume density (denoted :math:`\sigma` in
the paper) (shape: :math:`(width, height, num_samples, 4)`).
ray_origins (torch.Tensor): Origin of each ray in the "bundle" as returned by the
`get_ray_bundle()` method (shape: :math:`(width, height, 3)`).
depth_values (torch.Tensor): Sampled depth values along each ray
(shape: :math:`(num_samples)`).
Returns:
rgb_map (torch.Tensor): Rendered RGB image (shape: :math:`(width, height, 3)`).
depth_map (torch.Tensor): Rendered depth image (shape: :math:`(width, height)`).
acc_map (torch.Tensor): # TODO: Double-check (I think this is the accumulated
transmittance map).
"""
# TESTED
sigma_a = torch.nn.functional.relu(radiance_field[..., 3])
rgb = torch.sigmoid(radiance_field[..., :3])
one_e_10 = torch.tensor([1e10], dtype=ray_origins.dtype, device=ray_origins.device)
dists = torch.cat((depth_values[..., 1:] - depth_values[..., :-1],
one_e_10.expand(depth_values[..., :1].shape)), dim=-1)
alpha = 1. - torch.exp(-sigma_a * dists)
weights = alpha * cumprod_exclusive(1. - alpha + 1e-10)
rgb_map = (weights[..., None] * rgb).sum(dim=-2)
depth_map = (weights * depth_values).sum(dim=-1)
acc_map = weights.sum(-1)
return rgb_map, depth_map, acc_map
def positional_encoding(
tensor, num_encoding_functions=6, include_input=True, log_sampling=True
) -> torch.Tensor:
r"""Apply positional encoding to the input.
Args:
tensor (torch.Tensor): Input tensor to be positionally encoded.
num_encoding_functions (optional, int): Number of encoding functions used to
compute a positional encoding (default: 6).
include_input (optional, bool): Whether or not to include the input in the
computed positional encoding (default: True).
log_sampling (optional, bool): Sample logarithmically in frequency space, as
opposed to linearly (default: True).
Returns:
(torch.Tensor): Positional encoding of the input tensor.
"""
# TESTED
# Trivially, the input tensor is added to the positional encoding.
encoding = [tensor] if include_input else []
# Now, encode the input using a set of high-frequency functions and append the
# resulting values to the encoding.
frequency_bands = None
if log_sampling:
frequency_bands = 2.0 ** torch.linspace(
0.0,
num_encoding_functions - 1,
num_encoding_functions,
dtype=tensor.dtype,
device=tensor.device,
)
else:
frequency_bands = torch.linspace(
2.0 ** 0.0,
2.0 ** (num_encoding_functions - 1),
num_encoding_functions,
dtype=tensor.dtype,
device=tensor.device,
)
for freq in frequency_bands:
for func in [torch.sin, torch.cos]:
encoding.append(func(tensor * freq))
# Special case, for no positional encoding
if len(encoding) == 1:
return encoding[0]
else:
return torch.cat(encoding, dim=-1)
class VeryTinyNerfModel(torch.nn.Module):
r"""Define a "very tiny" NeRF model comprising three fully connected layers.
"""
def __init__(self, filter_size=128, num_encoding_functions=6):
super(VeryTinyNerfModel, self).__init__()
# Input layer (default: 39 -> 128)
self.layer1 = torch.nn.Linear(3 + 3 * 2 * num_encoding_functions, filter_size)
# Layer 2 (default: 128 -> 128)
self.layer2 = torch.nn.Linear(filter_size, filter_size)
# Layer 3 (default: 128 -> 4)
self.layer3 = torch.nn.Linear(filter_size, 4)
# Short hand for torch.nn.functional.relu
self.relu = torch.nn.functional.relu
def forward(self, x):
x = self.relu(self.layer1(x))
x = self.relu(self.layer2(x))
x = self.layer3(x)
return x
def get_minibatches(inputs: torch.Tensor):
r"""Takes a huge tensor (ray "bundle") and splits it into a list of minibatches.
Each element of the list (except possibly the last) has dimension `0` of length
`chunksize`.
"""
chunksize = 100 * 32 * 8
return [inputs[i:i + chunksize] for i in range(0, inputs.shape[0], chunksize)]
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load input images, poses, and intrinsics
# data = np.load("tiny_nerf_data.npz")
# One iteration of TinyNeRF (forward pass).
def run_one_iter_of_tinynerf(height, width, focal_length, tform_cam2world,
near_thresh, far_thresh, depth_samples_per_ray,
encoding_function, model, get_minibatches_function):
# Get the "bundle" of rays through all image pixels.
ray_origins, ray_directions = get_ray_bundle(height, width, focal_length,
tform_cam2world)
#print(ray_origins.shape)
# Sample query points along each ray
query_points, depth_values = compute_query_points_from_rays(
ray_origins, ray_directions, near_thresh, far_thresh, depth_samples_per_ray
)
# "Flatten" the query points.
flattened_query_points = query_points.reshape((-1, 3))
#print(flattened_query_points.shape)
# Encode the query points (default: positional encoding).
encoded_points = encoding_function(flattened_query_points)
# Split the encoded points into "chunks", run the model on all chunks, and
# concatenate the results (to avoid out-of-memory issues).
batches = get_minibatches_function(encoded_points)
predictions = []
for batch in batches:
predictions.append(model(batch))
radiance_field_flattened = torch.cat(predictions, dim=0)
# "Unflatten" to obtain the radiance field.
unflattened_shape = list(query_points.shape[:-1]) + [4]
radiance_field = torch.reshape(radiance_field_flattened, unflattened_shape)
# Perform differentiable volume rendering to re-synthesize the RGB image.
rgb_predicted, _, _ = render_volume_density(radiance_field, ray_origins, depth_values)
return rgb_predicted
def run_iter_of_tinynerf_ddp(height, width, start_heights, rank, focal_length, tform_cam2world,
near_thresh, far_thresh, depth_samples_per_ray,
encoding_function, model, get_minibatches_function):
# Get the "bundle" of rays through all image pixels.
ray_origins, ray_directions = get_ray_bundle(height, width, focal_length,
tform_cam2world)
# Sample query points along each ray
query_points, depth_values = compute_query_points_from_rays_ddp(
ray_origins, ray_directions, near_thresh, far_thresh, depth_samples_per_ray, start_heights, rank
)
#print(query_points.shape)
# "Flatten" the query points.
flattened_query_points = query_points.reshape((-1, 3))
# Encode the query points (default: positional encoding).
encoded_points = encoding_function(flattened_query_points)
# Split the encoded points into "chunks", run the model on all chunks, and
# concatenate the results (to avoid out-of-memory issues).
batches = get_minibatches_function(encoded_points)
predictions = []
for batch in batches:
predictions.append(model(batch))
radiance_field_flattened = torch.cat(predictions, dim=0)
# "Unflatten" to obtain the radiance field.
unflattened_shape = list(query_points.shape[:-1]) + [4]
radiance_field = torch.reshape(radiance_field_flattened, unflattened_shape)
#print(radiance_field.shape)
# Perform differentiable volume rendering to re-synthesize the RGB image.
rgb_predicted, _, _ = render_volume_density(radiance_field, ray_origins, depth_values)
return rgb_predicted
def nerf_ddp(gpu, args):
gpu_list = [int(gpu) for gpu in args.gpus.split(',')]
rank = sum(gpu_list[:args.id]) + gpu
# Number of functions used in the positional encoding (Be sure to update the
# model if this number changes).
num_encoding_functions = 6
# Specify encoding function.
encode = lambda x: positional_encoding(x, num_encoding_functions=num_encoding_functions)
# Number of depth samples along each ray.
depth_samples_per_ray = args.depth_samples_per_ray
# Chunksize (Note: this isn't batchsize in the conventional sense. This only
# specifies the number of rays to be queried in one go. Backprop still happens
# only after all rays from the current "bundle" are queried and rendered).
# chunksize = 16384 # Use chunksize of about 4096 to fit in ~1.4 GB of GPU memory.
# Optimizer parameters
lr = 5e-3
num_iters = args.num_iters
# Seed RNG, for repeatability
seed = 9458
torch.manual_seed(seed)
np.random.seed(seed)
# Misc parameters
display_every = 100 # Number of iters after which stats are displayed
dist.init_process_group(backend='gloo', init_method='env://', world_size=args.world_size, rank=rank)
#print("my process rank:{} on gpu {}\n".format(rank, gpu))
"""
Model
"""
model = VeryTinyNerfModel(num_encoding_functions=num_encoding_functions).to(gpu)
#print("rank", rank)
"""
Optimizer
"""
ddp_model = DDP(model, device_ids=[gpu])
optimizer = torch.optim.Adam(ddp_model.parameters(), lr=lr)
"""
Get data
"""
data = np.load("tiny_nerf_data.npz")
# Images
images = data["images"]
# Camera extrinsics (poses)
tform_cam2world = data["poses"]
tform_cam2world = torch.from_numpy(tform_cam2world).to(gpu)
# Focal length (intrinsics)
focal_length = data["focal"]
focal_length = torch.from_numpy(focal_length).to(gpu)
# Height and width of each image
height, width = images.shape[1:3]
# Near and far clipping thresholds for depth values.
near_thresh = 2.
far_thresh = 6.
# Hold one image out (for test).
testimg, testpose = images[101], tform_cam2world[101]
testimg = torch.from_numpy(testimg).to(gpu)
# Map images to device
images = torch.from_numpy(images[:100, ..., :3]).to(gpu)
"""
Train-Eval-Repeat!
"""
# Lists to log metrics etc.
psnrs = []
iternums = []
# used for data partitions, partition by heights
start_heights = list(range(0, height, int(height/(args.world_size - 1))))
start_heights.append(height)
start = datetime.now()
for i in range(num_iters):
# Randomly pick an image as the target.
target_img_idx = np.random.randint(images.shape[0])
target_img = images[target_img_idx].to(gpu)
target_tform_cam2world = tform_cam2world[target_img_idx].to(gpu)
# Run one iteration of TinyNeRF and get the rendered RGB image.
rgb_predicted = run_iter_of_tinynerf_ddp(height, width, start_heights, rank, focal_length,
target_tform_cam2world, near_thresh,
far_thresh, depth_samples_per_ray,
encode, ddp_model, get_minibatches)
# Compute mean-squared error between the predicted and target images. Backprop!
loss = torch.nn.functional.mse_loss(rgb_predicted, target_img[start_heights[rank]:start_heights[rank + 1]])
# if i % display_every == 0:
# print('Rank: {:4d}, GPU: {}, rgb_predicted_shape: {}, Iteration: {:4d}/{}, Loss: {:.4f}, Time: {}'.format(rank, gpu, rgb_predicted.shape, i, num_iters, loss.item(), (datetime.now() - start)))
loss.backward()
optimizer.step()
optimizer.zero_grad()
# Display images/plots/stats
if rank == 0 and i % display_every == 0:
# Render the held-out view
rgb_predicted = run_one_iter_of_tinynerf(height, width, focal_length,
testpose, near_thresh,
far_thresh, depth_samples_per_ray,
encode, ddp_model, get_minibatches)
loss = torch.nn.functional.mse_loss(rgb_predicted, target_img)
psnr = -10. * torch.log10(loss)
psnrs.append(psnr.item())
iternums.append(i)
print('Iteration: {}/{}, Loss: {:.4f}, Time: {}'.format(i, num_iters, loss.item(), (datetime.now() - start)))
im = rgb_predicted.detach().cpu().numpy()
cwd = os.getcwd()
path = '{}/logs'.format(cwd)
if not os.path.exists(path):
os.makedirs(path)
plt.imsave(os.path.join(path , "Iteration_{}.png".format(i)), im)
if gpu == 0:
print("Training complete in: " + str(datetime.now() - start))
cleanup()
def cleanup():
dist.destroy_process_group()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--nodes', default=1, type=int, metavar='N',
help='number of data loading workers (default: 4)')
parser.add_argument('-g', '--gpus', default="", type=str,
help='number of gpus of each node')
parser.add_argument('-i', '--id', default=0, type=int,
help='the id of the node which is determined by the correponding index in the gpu list')
parser.add_argument('-iter', '--num_iters', default=1000, type=int, metavar='N',
help='number of iterations to run')
parser.add_argument('-d', '--depth_samples_per_ray', default=32, type=int, metavar='N',
help='number of samples per ray')
parser.add_argument('-t', '--number_of_tests', default=1, type=int, metavar='N',
help='number of tests that you want to run')
args = parser.parse_args()
gpu_list = [int(gpu) for gpu in args.gpus.split(',')]
args.world_size = sum(gpu_list)
print("This code is running.")
args.world_size = sum(gpu_list)
#change to your own master IP address
os.environ["MASTER_ADDR"] = "10.145.83.59"
os.environ["MASTER_PORT"] = "29515"
for _ in range(args.number_of_tests):
mp.spawn(nerf_ddp,
nprocs=gpu_list[args.id],
args=(args,))
print("Done!")
if __name__=="__main__":
# Environment variables which need to be
# set when using c10d's default "env"
# initialization mode.
main()