# Apex and Random Seed

**URL:** <https://discuss.pytorch.org/t/apex-and-random-seed/148319>\
**Category:** Uncategorized\
**Created:** [April 5, 2022, 9:00am UTC](https://discuss.pytorch.org/t/apex-and-random-seed/148319 "2022-04-05T09:00:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hannibal046](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hannibal046/32/32289_2.png) [@Hannibal046](https://discuss.pytorch.org/u/Hannibal046)\
**Post date:** [April 5, 2022, 9:00am UTC](https://discuss.pytorch.org/t/apex-and-random-seed/148319/1 "2022-04-05T09:00:30Z")

</div>

Hi, I am wondering have you ever encountered such situation when using Apex Fp16, random seed seems to be out of work.  
This is how I set random seed

```python
def setup_seed(seed):
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)
    np.random.seed(seed)
    random.seed(seed)
    torch.backends.cudnn.deterministic = True

```

This is where things get weird. I ran two process simultaneously on GPU0 and GPU1 with same conda environment.

 ![image](https://discuss.pytorch.org/uploads/default/original/3X/e/6/e63eb744ffb21af809ebf9ffb1812a46e4790b0f.png)  
 ![image](https://discuss.pytorch.org/uploads/default/original/3X/5/b/5b1a5a8600b78879786420936e117e7645294e05.png)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [April 5, 2022, 9:20am UTC](https://discuss.pytorch.org/t/apex-and-random-seed/148319/2 "2022-04-05T09:20:46Z")

</div>

`apex.amp` is deprecated so please use the native mixed-precision implementation via `torch.cuda.amp` as described [here](https://pytorch.org/docs/stable/notes/amp_examples.html#amp-examples).
