dllllb / pytorch-lifestream

A library built upon PyTorch for building embeddings on discrete event sequences using self-supervision
Apache License 2.0
215 stars 46 forks source link

Modern torch #156

Closed ivan-chai closed 4 months ago

ivan-chai commented 4 months ago
  1. Relax dependencies.
  2. Add support for the modern PyTorch and PyTorch-Lightning packages.
  3. Update tests.
  4. Add Dockerfile with the default environment.
ivkireev86 commented 4 months ago

И еще тесты ппадают с такой ошибкой:

================================================================================== FAILURES ===================================================================================
_____________________________________________________________________________ test_padded_collate _____________________________________________________________________________

    def test_padded_collate():
        data = [
            ({'a': torch.LongTensor([1, 2, 3, 4])}, torch.LongTensor([0])),
            ({'a': torch.LongTensor([1, 2])},  torch.LongTensor([0])),
            ({'a': torch.LongTensor([1])},  torch.LongTensor([1])),
        ]

        tt = torch.LongTensor([
            [1, 2, 3, 4],
            [1, 2, 0, 0],
            [1, 0, 0, 0]])

>       x, y = padded_collate(data)

ptls_tests/test_data_load/test__init__.py:21: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

batch = [({'a': tensor([1, 2, 3, 4])}, tensor([0])), ({'a': tensor([1, 2])}, tensor([0])), ({'a': tensor([1])}, tensor([1]))]

    def padded_collate(batch):
        new_x_ = defaultdict(list)
        for x, _ in batch:
            for k, v in x.items():
                new_x_[k].append(v)

        lengths = torch.IntTensor([len(e) for e in next(iter(new_x_.values()))])

        new_x = {k: torch.nn.utils.rnn.pad_sequence(v, batch_first=True) for k, v in new_x_.items()}
>       new_y = np.array([y for _, y in batch])
E       ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part.

ptls/data_load/__init__.py:347: ValueError
============================================================================== warnings summary ===============================================================================
ivan-chai commented 4 months ago

Тест вроде бы должен работать теперь.