While trying to execute sample in distr app tutorial, coding error occurs, can not fix

GGPYTORCH000: <p>In this tutorial, I tried executing but random() call returns error:<br>
<a href="https://pytorch.org/tutorials/intermediate/dist_tuto.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/tutorials/intermediate/dist_tuto.html</a></p>
<p>(search for random() in that page above and try executing it).</p>
<p>I tried many ways to replace with equivalent but can not find substitiute such that code runs error-free. It is poorly written such that does not tell whcih library it should come from.</p>

H-Huang: <p>I’m guessing it should be this? <a href="https://docs.python.org/3/library/random.html#random.Random" class="inline-onebox" rel="noopener nofollow ugc">random — Generate pseudo-random numbers — Python 3.12.3 documentation</a></p>
<p>Updated the tutorials here: <a href="https://github.com/pytorch/tutorials/pull/2880" class="inline-onebox" rel="noopener nofollow ugc">Include import for dist_tuto by H-Huang · Pull Request #2880 · pytorch/tutorials · GitHub</a>. Feel free to send in PRs for other issues you find.</p>

GGPYTORCH000: <p>Do you own this tutorial or just suggesting by sidelines. if former, you should test your code before publishing</p>

GGPYTORCH000: <p>so how should i change the code? random() causes error.</p>

H-Huang: <p><code>from random import Random</code></p>

GGPYTORCH000: <p>that might have worked but errors continue to occur with this sample code, fixed number of it and now seeing:</p>
<p>init_process: rank, size:  0 ,  2<br>
init_process: rank, size:  1 ,  2<br>
run: rank/size:  1 / 2<br>
run: rank/size:  0 / 2<br>
GG: size/bsz:  2 / 64<br>
GG: size/bsz:  2 / 64<br>
Process Process-1:<br>
Traceback (most recent call last):<br>
File “/home/miniconda3/envs/root-test/lib/python3.9/multiprocessing/process.py”, line 315, in _bootstrap<br>
self.run()<br>
File “/home/miniconda3/envs/root-test/lib/python3.9/multiprocessing/process.py”, line 108, in run<br>
self._target(*self._args, **self._kwargs)<br>
File “/root/extdir/gg/git/codelab/gpu/ml/pytorch/distributed/tutorials/2-distributed-data-parallelism/dist-app-training.py”, line 160, in init_process<br>
fn(rank, size)<br>
File “/root/extdir/gg/git/codelab/gpu/ml/pytorch/distributed/tutorials/2-distributed-data-parallelism/dist-app-training.py”, line 139, in run<br>
num_batches = ceil(len(train_set.dataset) / float(bsz))<br>
NameError: name ‘ceil’ is not defined<br>
Process Process-2:<br>
Traceback (most recent call last):<br>
File “/home/miniconda3/envs/root-test/lib/python3.9/multiprocessing/process.py”, line 315, in _bootstrap<br>
self.run()<br>
File “/home/miniconda3/envs/root-test/lib/python3.9/multiprocessing/process.py”, line 108, in run<br>
self._target(*self._args, **self._kwargs)<br>
File “/root/extdir/gg/git/codelab/gpu/ml/pytorch/distributed/tutorials/2-distributed-data-parallelism/dist-app-training.py”, line 160, in init_process<br>
fn(rank, size)<br>
File “/root/extdir/gg/git/codelab/gpu/ml/pytorch/distributed/tutorials/2-distributed-data-parallelism/dist-app-training.py”, line 139, in run<br>
num_batches = ceil(len(train_set.dataset) / float(bsz))<br>
NameError: name ‘ceil’ is not defined</p>

GGPYTORCH000: <p>ok fixed everything appears working but not before fixing obvious and some less obvious errors.</p>