mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-08 04:24:47 +00:00
[misc] update pre-commit and run all files (#4752)
* [misc] update pre-commit * [misc] run pre-commit * [misc] remove useless configuration files * [misc] ignore cuda for clang-format
This commit is contained in:
@@ -3,7 +3,6 @@ from contextlib import contextmanager
|
||||
import torch
|
||||
import torch.distributed as dist
|
||||
from torch.distributed import ProcessGroup
|
||||
from torch.distributed.distributed_c10d import _get_global_rank
|
||||
|
||||
|
||||
class Randomizer:
|
||||
@@ -172,10 +171,9 @@ class Randomizer:
|
||||
Randomizer._INDEX = index_tensor.item()
|
||||
|
||||
|
||||
def create_randomizer_with_offset(seed: int,
|
||||
process_group: ProcessGroup = None,
|
||||
offset_by_rank: bool = True,
|
||||
offset_by_index: bool = True):
|
||||
def create_randomizer_with_offset(
|
||||
seed: int, process_group: ProcessGroup = None, offset_by_rank: bool = True, offset_by_index: bool = True
|
||||
):
|
||||
"""
|
||||
Create a randomizer with an offset. The offset is equal to the rank of the process and the index of the randomizer.
|
||||
|
||||
@@ -197,9 +195,11 @@ def create_randomizer_with_offset(seed: int,
|
||||
if offset_by_index:
|
||||
# check if the randomizer index is synchronized
|
||||
is_synchronized = Randomizer.is_randomizer_index_synchronized(process_group)
|
||||
assert is_synchronized, ("We detect that the randomizer index is not synchronized across processes."
|
||||
"This is not allowed when we want to create a randomizer with offset by index."
|
||||
"Please call Randomizer.synchronize_index() first.")
|
||||
assert is_synchronized, (
|
||||
"We detect that the randomizer index is not synchronized across processes."
|
||||
"This is not allowed when we want to create a randomizer with offset by index."
|
||||
"Please call Randomizer.synchronize_index() first."
|
||||
)
|
||||
|
||||
base_seed += Randomizer.index()
|
||||
Randomizer.increment_index()
|
||||
|
Reference in New Issue
Block a user