MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / set_random_seed

Function set_random_seed

SwissArmyTransformer/sat/arguments.py:566–586  ·  view source on GitHub ↗

Set random seed for reproducability.

(seed)

Source from the content-addressed store, hash-verified

564 return True
565
566def set_random_seed(seed):
567 """Set random seed for reproducability."""
568 if seed is not None:
569 global _GLOBAL_RANDOM_SEED
570 _GLOBAL_RANDOM_SEED = seed
571 assert seed > 0
572 random.seed(seed)
573 np.random.seed(seed)
574 torch.manual_seed(seed)
575 torch.cuda.manual_seed(seed)
576 torch.cuda.manual_seed_all(seed) # if you are using multi-GPU.
577 torch.backends.cudnn.benchmark = True
578 torch.backends.cudnn.deterministic = True
579 torch.backends.cudnn.enabled = True # False
580 torch.backends.cuda.matmul.allow_tf32 = False # if set it to True will be much faster but not accurate
581 try:
582 import deepspeed
583 if deepspeed.checkpointing.is_configured():
584 mpu.model_parallel_cuda_manual_seed(seed)
585 except ImportError:
586 pass
587
588def reset_random_seed(scale=1):
589 assert _GLOBAL_RANDOM_SEED is not None, "You have not set random seed. No need to reset it."

Callers 6

mainFunction · 0.90
mainFunction · 0.90
get_argsFunction · 0.90
_simple_initFunction · 0.85
get_argsFunction · 0.85
reset_random_seedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected