Skip to content
Open
Changes from all commits
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
14 changes: 8 additions & 6 deletions openicl/utils/collators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class ListWrapper:
def __init__(self, data: List[Any]):
self.data = data

def to(self, device):
def to(self, device, non_blocking=False):
return self.data


def ignore_pad_dict(features):
res_dict = {}
if "metadata" in features[0]:
res_dict['metadata'] = ListWrapper([x.pop("metadata") for x in features])
res_dict["metadata"] = ListWrapper([x.pop("metadata") for x in features])
return res_dict


Expand All @@ -30,7 +30,9 @@ class DataCollatorWithPaddingAndCuda:
max_length: Optional[int] = 3000
pad_to_multiple_of: Optional[int] = None

def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> BatchEncoding:
def __call__(
self, features: List[Dict[str, Union[List[int], torch.Tensor]]]
) -> BatchEncoding:
res_dict = ignore_pad_dict(features)

has_labels = "labels" in features[0]
Expand All @@ -43,7 +45,7 @@ def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) ->
pad_to_multiple_of=self.pad_to_multiple_of,
return_attention_mask=True,
return_tensors="pt",
verbose=False
verbose=False,
)

# print(features)
Expand All @@ -54,11 +56,11 @@ def __call__(self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) ->
pad_to_multiple_of=self.pad_to_multiple_of,
return_attention_mask=True,
return_tensors="pt",
verbose=False
verbose=False,
)

if has_labels:
batch['labels'] = labels.input_ids
batch["labels"] = labels.input_ids
batch.update(res_dict)

if self.device:
Expand Down