Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/data/unlearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ def __len__(self):

def __getitem__(self, idx):
item = {}
g = torch.Generator()
rank = torch.distributed.get_rank() if torch.distributed.is_initialized() else 0
seed = int(torch.empty((), dtype=torch.int64).random_().item() + rank)
g.manual_seed(seed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be better to use the seed from the experiment config here, rather than
int(torch.empty((), dtype=torch.int64).random_().item() to avoid introducing randomness uncontrolled by the seed.

can you try to see if you can make the experiment's cfg.seed available to this dataset class and then use seed = exp_seed + rank here?

if self.anchor == "forget":
item["forget"] = self.forget[idx]
if self.retain:
retain_idx = torch.randint(0, len(self.retain), (1,)).item()
retain_idx = torch.randint(0, len(self.retain), (1,), generator=g).item()
item["retain"] = self.retain[retain_idx]
elif self.anchor == "retain":
item["retain"] = self.retain[idx]
if self.forget:
forget_idx = torch.randint(0, len(self.forget), (1,)).item()
forget_idx = torch.randint(0, len(self.forget), (1,), generator=g).item()
item["forget"] = self.forget[forget_idx]
return item