项目文件夹

文件
wehub-resource-sync 593b94c120
pytest / Unit Tests (push) Has been cancelled
pytest / Integration (integration_tests_a) (push) Has been cancelled
pytest / Integration (integration_tests_b) (push) Has been cancelled
pytest / Integration (integration_tests_c) (push) Has been cancelled
pytest / Integration (integration_tests_d) (push) Has been cancelled
pytest / Integration (integration_tests_e) (push) Has been cancelled
pytest / Integration (integration_tests_f) (push) Has been cancelled
pytest / Integration (integration_tests_g) (push) Has been cancelled
pytest / Integration (integration_tests_h) (push) Has been cancelled
pytest / Integration (integration_tests_i) (push) Has been cancelled
pytest / Integration (integration_tests_j) (push) Has been cancelled
pytest / Distributed (distributed_a) (push) Has been cancelled
pytest / Distributed (distributed_b) (push) Has been cancelled
pytest / Distributed (distributed_c) (push) Has been cancelled
pytest / Distributed (distributed_d) (push) Has been cancelled
pytest / Distributed (distributed_e) (push) Has been cancelled
pytest / Distributed (distributed_f) (push) Has been cancelled
pytest / Minimal Install (push) Has been cancelled
pytest / Event File (push) Has been cancelled
pytest (slow) / py-slow (push) Has been cancelled
Publish JSON Schema / publish-schema (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:49:20 +08:00

24 行
1.1 KiB
Python

import pytest
import torch
from ludwig.modules import reduction_modules
from ludwig.utils.torch_utils import get_torch_device
DEVICE = get_torch_device()
@pytest.mark.parametrize("reduce_mode", ["last", "sum", "mean", "avg", "max", "concat", "attention", None])
@pytest.mark.parametrize("test_input_shape", [(16, 1, 4), (4, 10, 16)])
def test_sequence_reducer(reduce_mode: str, test_input_shape: tuple[int, ...]):
batch_size, max_sequence_length, encoding_size = test_input_shape
sequence_reducer = reduction_modules.SequenceReducer(
reduce_mode=reduce_mode, max_sequence_length=max_sequence_length, encoding_size=encoding_size
).to(DEVICE)
inputs = torch.zeros(test_input_shape)
# Generates random sequence of random length for each instance in batch.
for batch_index in range(batch_size):
sequence_length = torch.randint(max_sequence_length, (1,))
inputs[batch_index, :sequence_length] = torch.rand((sequence_length, encoding_size))
outputs = sequence_reducer(inputs.to(DEVICE))
assert outputs.shape[1:] == sequence_reducer.output_shape