MCPcopy Create free account
hub / github.com/InternLM/InternLM-XComposer / set_random_seed

Function set_random_seed

example_code/utils.py:63–76  ·  view source on GitHub ↗

Set the random seed for reproducibility. Parameters: seed (int): The seed to use for generating random numbers.

(seed, set_cudnn=False)

Source from the content-addressed store, hash-verified

61
62
63def set_random_seed(seed, set_cudnn=False):
64 """Set the random seed for reproducibility.
65
66 Parameters:
67 seed (int): The seed to use for generating random numbers.
68 """
69 torch.manual_seed(seed)
70 if torch.cuda.is_available():
71 torch.cuda.manual_seed_all(seed) # For multi-GPU.
72 np.random.seed(seed)
73 random.seed(seed)
74 if set_cudnn and torch.backends.cudnn.is_available():
75 torch.backends.cudnn.deterministic = True
76 torch.backends.cudnn.benchmark = False

Callers 2

__init__Method · 0.90
generate_articleMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected