MCPcopy Create free account
hub / github.com/AnswerDotAI/ModernBERT / test_pad_input

Function test_pad_input

tests/test_padding.py:37–47  ·  view source on GitHub ↗
(sample_data)

Source from the content-addressed store, hash-verified

35
36
37def test_pad_input(sample_data):
38 inputs, attention_mask, _, labels = sample_data
39 unpadded_inputs, indices, _, _, _, unpadded_labels = unpad_input(inputs, attention_mask, labels=labels)
40
41 padded_inputs, padded_labels = pad_input(unpadded_inputs, indices, batch=2, seqlen=4, labels=unpadded_labels)
42
43 assert padded_inputs.shape == (2, 4, 3)
44 assert torch.allclose(padded_inputs[attention_mask.bool()], unpadded_inputs)
45 assert torch.all(padded_inputs[~attention_mask.bool()] == 0)
46 assert torch.all(padded_labels[attention_mask.bool()] == unpadded_labels)
47 assert torch.all(padded_labels[~attention_mask.bool()] == -100)
48
49
50def test_roundtrip(sample_data):

Callers

nothing calls this directly

Calls 2

unpad_inputFunction · 0.90
pad_inputFunction · 0.90

Tested by

no test coverage detected