MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / lengths_to_mask

Function lengths_to_mask

datasets/dataloader.py:183–190  ·  view source on GitHub ↗
(lengths: list[int],
                    device: torch.device,
                    max_len: int = None)

Source from the content-addressed store, hash-verified

181
182
183def lengths_to_mask(lengths: list[int],
184 device: torch.device,
185 max_len: int = None) -> torch.Tensor:
186 lengths = torch.tensor(lengths, device=device)
187 max_len = max_len if max_len else max(lengths)
188 mask = torch.arange(max_len, device=device).expand(
189 len(lengths), max_len) < lengths.unsqueeze(1)
190 return mask

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected