-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/heterogeneous x pu training (#355)
Co-authored-by: Wenwen Qu <[email protected]>
- Loading branch information
1 parent
058fb9b
commit d6bfaca
Showing
19 changed files
with
1,170 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from .sampler import LuminaPickleSampler | ||
from .sampler import LuminaPickleBatchSampler | ||
from .dataset import LuminaPickleDataset | ||
|
||
__all__ = [ | ||
"LuminaPickleSampler", | ||
"LuminaPickleBatchSampler", | ||
"LuminaPickleDataset" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import torch | ||
|
||
def lumina_collate_fn(batch): | ||
""" | ||
Collate function for packed input sequences. | ||
Args: | ||
batch (List[Dict]): List of dictionaries representing each sample in batch. | ||
Each dictionary contains "tokens", "labels", "type_ids", "cu_seqlens", and "indexes" keys. | ||
Returns: | ||
Tuple[Dict[str, torch.Tensor], torch.Tensor]: A tuple containing a dictionary of tensors with "input_ids", | ||
"cu_seqlens", "indexes", and "type_ids" keys, and the tensor of padded "labels". | ||
""" | ||
# Initialize lists to store the data from each sample | ||
tokens, labels, type_ids, indexes = [], [], [], [] | ||
cumulative_seqlens = [0] | ||
|
||
# Accumulate all samples into respective lists | ||
for sample in batch: | ||
tokens.extend([abs(w) for w in sample["tokens"]]) | ||
labels.extend([w if w > 0 else -100 for w in sample["labels"]]) | ||
type_ids.extend(sample["type_ids"]) | ||
indexes.extend(sample["indexes"]) | ||
cumulative_seqlens.append(cumulative_seqlens[-1] + sample["cu_seqlens"][-1]) | ||
|
||
# Convert lists to tensors and unsqueeze to add batch dimension | ||
xs = torch.tensor(tokens, dtype=torch.long).unsqueeze(0) | ||
ys = torch.tensor(labels, dtype=torch.long).unsqueeze(0) | ||
ts = torch.tensor(type_ids, dtype=torch.long).unsqueeze(0) | ||
indexes = torch.tensor(indexes, dtype=torch.long).unsqueeze(0) | ||
cu_seqlens = torch.tensor(cumulative_seqlens, dtype=torch.int).unsqueeze(0) | ||
|
||
return {"input_ids": xs, "cu_seqlens": cu_seqlens, "indexes": indexes, "type_ids": ts}, ys |
Oops, something went wrong.