Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
next-version e2e (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
justusschock authored Feb 8, 2023
1 parent 1576683 commit 0066dee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
5 changes: 0 additions & 5 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import logging
import os
import sys
from contextlib import redirect_stdout, redirect_stderr
import io
from typing import Union

import lightning
Expand All @@ -15,13 +12,11 @@
from lit_llms.tensorboard import (
MultiNodeLightningTrainerWithTensorboard,
)
from lightning.app.runners import MultiProcessRuntime

from transformers import T5ForConditionalGeneration, T5TokenizerFast as T5Tokenizer

from lai_tldr import TLDRLightningModule
from tests.test_module import BoringModel
from lightning.app.testing import LightningTestApp

class DummyTLDR(TLDR):
boring_model=True
Expand Down
19 changes: 5 additions & 14 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import string
from collections import namedtuple
from argparse import Namespace
from random import choice
from time import sleep

import lightning as L
import pandas as pd
Expand All @@ -12,8 +11,6 @@
from lai_tldr import TLDRDataModule
from lai_tldr.module import TLDRLightningModule

return_type = namedtuple("return_type", ("loss", "logits"))


class BoringModel(torch.nn.Module):
def __init__(self, target_seq_length: int, vocab_size: int, embed_size: int = 10):
Expand All @@ -23,18 +20,12 @@ def __init__(self, target_seq_length: int, vocab_size: int, embed_size: int = 10
self.seq_length = target_seq_length
self.vocab_size = vocab_size

def forward(self, input_ids, labels=None, **kwargs):
def forward(self, input_ids, **kwargs):
# mimic source_seq_length -> target_seq_length by truncation
logits = self.layer2(self.wte(input_ids))[:, : self.seq_length, :]
if labels is None:
loss = None
else:
loss = torch.nn.functional.cross_entropy(
logits.contiguous().view(-1, logits.size(-1)),
labels.view(-1),
ignore_index=-100,
)
return return_type(loss, logits)

loss = logits.sum()
return Namespace(loss=loss, logits=logits)

def generate(self, input_ids, num_beams: int = 1, **kwargs):
return [self(input_ids).logits.argmax(-1)[0].tolist() for _ in range(num_beams)]
Expand Down

0 comments on commit 0066dee

Please sign in to comment.