Set `torch.cuda.manual_seed_all()` for DDP (#8688)
Browse files* Set `torch.cuda.manual_seed_all()` for DDP
* Update general.py
* Update general.py
- utils/general.py +3 -3
utils/general.py
CHANGED
@@ -203,14 +203,14 @@ def init_seeds(seed=0, deterministic=False):
|
|
203 |
if deterministic and check_version(torch.__version__, '1.12.0'): # https://github.com/ultralytics/yolov5/pull/8213
|
204 |
torch.use_deterministic_algorithms(True)
|
205 |
os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8'
|
206 |
-
|
207 |
|
208 |
random.seed(seed)
|
209 |
np.random.seed(seed)
|
210 |
torch.manual_seed(seed)
|
211 |
cudnn.benchmark, cudnn.deterministic = (False, True) if seed == 0 else (True, False)
|
212 |
-
|
213 |
-
|
214 |
|
215 |
|
216 |
def intersect_dicts(da, db, exclude=()):
|
|
|
203 |
if deterministic and check_version(torch.__version__, '1.12.0'): # https://github.com/ultralytics/yolov5/pull/8213
|
204 |
torch.use_deterministic_algorithms(True)
|
205 |
os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8'
|
206 |
+
os.environ['PYTHONHASHSEED'] = str(seed)
|
207 |
|
208 |
random.seed(seed)
|
209 |
np.random.seed(seed)
|
210 |
torch.manual_seed(seed)
|
211 |
cudnn.benchmark, cudnn.deterministic = (False, True) if seed == 0 else (True, False)
|
212 |
+
torch.cuda.manual_seed(seed)
|
213 |
+
torch.cuda.manual_seed_all(seed) # for Multi-GPU, exception safe
|
214 |
|
215 |
|
216 |
def intersect_dicts(da, db, exclude=()):
|